Re: error recovery with yacc

danfuzz@wastelands.kaleida.com (Dan Bornstein)
Sat, 14 Nov 1992 03:55:47 GMT

          From comp.compilers

Related articles
error recovery with yacc scheek@RUGRCX.RUG.NL (1992-11-10)
Re: error recovery with yacc danfuzz@wastelands.kaleida.com (1992-11-14)
| List of all articles for this month |

Newsgroups: comp.compilers
From: danfuzz@wastelands.kaleida.com (Dan Bornstein)
Organization: Kaleida Labs, Inc.
Date: Sat, 14 Nov 1992 03:55:47 GMT
Keywords: yacc, errors
References: 92-11-038

>I have a problem understanding/using the error recovery mechanisme
>with yacc. Part of my syntax is:
>
>[...]
> statement_list
> : /* 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
>the ENDPROC.
>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
it around:


                            | 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.


-Dan Bornstein
danfuzz@kaleida.com
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.