1 * Notes on improving error handling in MCS
2 (from Axel Schreiner <ats@cs.rit.edu>)
5 I included the 'recover' example with C# as well. Currently the package
6 is at <http://www.cs.rit.edu/~ats/projects/jay/>. I did change some
7 names and the embedding that the user does somewhat, i.e., it is not
8 directly compatible with what you did.
10 Here is the important part about error recovery. To make the typical
11 iterations bullet-proof, code them as follows:
14 | opt WORD { yyErrorFlag = 0; }
18 | seq WORD { yyErrorFlag = 0; }
23 | list ',' WORD { yyErrorFlag = 0; }
26 | list error WORD { yyErrorFlag = 0; }
29 i.e., throw in 'error' wherever a token can be. 'yyErrorFlag' need not
30 be set to zero, but if it is done this way, second errors are caught
31 earlier. This may introduce s/r conflicts, but they tend to be harmless.
33 In your case -- the comment concerning error recovery at the beginning
34 of your compiler jay file -- just adding 'error' to the different
35 global things won't work. Your example will already have started to
36 advance in one of the rules and 'error' is then not in the lookahead of
37 wherever the parse then is. You need to put 'error' into the iteration
38 above those global things.