Below are some examples of C-- code that can be used to test the error handling of your parser. In some cases, your parser should be able to recover from the error and continue parsing. In other more problematic cases, the parser can immediately quit.
int main() { int x; int y; x = 0 y = 5; while (x < y) { write x writeln; x = x + * 1; } }
Error on line 6: expected semi, but found id y = 5; Error on line 10: expected semi, but found writeln writeln; Error on line 11: invalid expression x = x + * 1; Parser found 3 errors.
int x; int double(int y) { return 2*y; } int main() { read x; write double(x); return 1
Error on line 12: expected semi, but found done Error on line 12: unexpected end of file, missing closing brace Parser found 2 errors.
int x; int double(int y) { return 2*y; int main() { read x; write double(x); return 1; }
Error on line 7: invalid expression int main() { Error on line 7: unexpected end of function, missing closing brace Parser found 2 errors.
int x; char ; int main() { x = 10; y = 'a'; write x; write y; }
Error on line 2: missing identifier in declaration char ; Parser found 1 error.
int x; char y int main() { x = 10; y = 'a'; write x; write y; }
Error on line 4: expected lparen, but found int int main() { Parser found 1 error.