|error recovery with yacc scheek@RUGRCX.RUG.NL (1992-11-10)|
|Re: error recovery with yacc firstname.lastname@example.org (1992-11-14)|
|From:||email@example.com (Dan Bornstein)|
|Organization:||Kaleida Labs, Inc.|
|Date:||Sat, 14 Nov 1992 03:55:47 GMT|
>I have a problem understanding/using the error recovery mechanisme
>with yacc. Part of my syntax is:
> : /* empty */
> | statement
> | statement_list separator
> | statement_list separator statement
>If some statement is in error then I just want to skip over the
>next separator (which is a ';' or NEWLINE) and continue the
>parsing of the proc_body with the rest of the statements.
>I added the following rule to the statement_list definition:
> | error separator statement_list
>( no yyerrok here!)
>This seems ok, but causes the error to be reduce only just before
>Somehow it just doesn't feel right to me. Is there a better way?
The way I do it (and usually see it done) would be to reverse
| statement_list error separator
meaning, more or less, "A statement list followed by an error and a
separator is still a statement list." The way you originally put it, "A
statement list can start with an error and then a separator, but you still
have to find another statement list after that." So, what yacc was doing
was dutifully finding the longest statement_list following the error and
separator before reporting the error.
Since a statement_list might be empty, you can still get the rule to
reduce given an error at the beginning of the input text.
Return to the
Search the comp.compilers archives again.