home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!darwin.sura.net!spool.mu.edu!sol.ctr.columbia.edu!emory!ogicse!das-news.harvard.edu!spdcc!iecc!compilers-sender
- From: scheek@RUGRCX.RUG.NL (Frans van hoesel)
- Newsgroups: comp.compilers
- Subject: error recovery with yacc
- Keywords: yacc, errors
- Message-ID: <92-11-038@comp.compilers>
- Date: 10 Nov 92 16:14:41 GMT
- Article-I.D.: comp.92-11-038
- Sender: compilers-sender@iecc.cambridge.ma.us
- Reply-To: scheek@RUGRCX.RUG.NL (Frans van hoesel)
- Organization: Compilers Central
- Lines: 59
- Approved: compilers@iecc.cambridge.ma.us
-
- Hi
-
- I have a problem understanding/using the error recovery mechanisme
- with yacc. Part of my syntax is:
-
- %start compilation_chunk
- %%
-
- procedure:
- : PROC proc_header proc_body ENDPROC
- ;
- proc_body
- : statement_list
- ;
- statement_list
- : /* empty */
- | statement
- | statement_list separator
- | statement_list separator statement
- ;
- seperator
- : ';'
- | NEWLINE
- ;
- one_liner
- : /* empty */
- | statement
- | one_liner ';'
- | one_liner ';' statement
- ;
- compilation_chunk
- : one_liner NEWLINE
- { YYACCEPT ; }
- | procedure
- { YYACCEPT ; }
- ;
- %%
-
- 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?
-
- It sounds to me I'm reinventing the wheel, so maybe there is a
- kind person who wants to explain to me how a wheel should look like?
-
- -- frans van hoesel
-
- scheek@rugrcx.rug.nl or
- hoesel@igc.ethz.ch
- (both are me)
- --
- Send compilers articles to compilers@iecc.cambridge.ma.us or
- {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.
-