home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!das-news.harvard.edu!spdcc!iecc!compilers-sender
- From: danfuzz@wastelands.kaleida.com (Dan Bornstein)
- Newsgroups: comp.compilers
- Subject: Re: error recovery with yacc
- Keywords: yacc, errors
- Message-ID: <92-11-075@comp.compilers>
- Date: 14 Nov 92 03:55:47 GMT
- Article-I.D.: comp.92-11-075
- References: <92-11-038@comp.compilers>
- Sender: compilers-sender@iecc.cambridge.ma.us
- Reply-To: danfuzz@wastelands.kaleida.com (Dan Bornstein)
- Organization: Kaleida Labs, Inc.
- Lines: 42
- Approved: compilers@iecc.cambridge.ma.us
-
- >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
- --
- Send compilers articles to compilers@iecc.cambridge.ma.us or
- {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.
-