home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / compiler / 1847 < prev    next >
Encoding:
Internet Message Format  |  1992-11-11  |  1.9 KB

  1. 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
  2. From: scheek@RUGRCX.RUG.NL (Frans van hoesel)
  3. Newsgroups: comp.compilers
  4. Subject: error recovery with yacc
  5. Keywords: yacc, errors
  6. Message-ID: <92-11-038@comp.compilers>
  7. Date: 10 Nov 92 16:14:41 GMT
  8. Article-I.D.: comp.92-11-038
  9. Sender: compilers-sender@iecc.cambridge.ma.us
  10. Reply-To: scheek@RUGRCX.RUG.NL (Frans van hoesel)
  11. Organization: Compilers Central
  12. Lines: 59
  13. Approved: compilers@iecc.cambridge.ma.us
  14.  
  15. Hi
  16.   
  17.    I have a problem understanding/using the error recovery mechanisme
  18.    with yacc. Part of my syntax is:
  19.  
  20.       %start compilation_chunk
  21.     %%
  22.  
  23.     procedure:
  24.         : PROC proc_header proc_body ENDPROC
  25.         ;
  26.     proc_body
  27.         : statement_list
  28.         ;
  29.     statement_list
  30.         : /* empty */
  31.         | statement
  32.         | statement_list separator
  33.         | statement_list separator statement
  34.         ;
  35.     seperator
  36.         : ';'
  37.         | NEWLINE
  38.         ;
  39.     one_liner
  40.         : /* empty */
  41.         | statement
  42.         | one_liner ';'
  43.         | one_liner ';' statement
  44.         ;
  45.     compilation_chunk
  46.         : one_liner NEWLINE
  47.             { YYACCEPT ; }
  48.         | procedure
  49.             { YYACCEPT ; }
  50.         ;
  51.        %%
  52.     
  53.    If some statement is in error then I just want to skip over the 
  54.    next separator (which is a ';' or NEWLINE) and continue the
  55.    parsing of the proc_body with the rest of the statements.
  56.    I added the following rule to the statement_list definition:
  57.         | error separator statement_list
  58.    ( no yyerrok here!) 
  59.    This seems ok, but causes the error to be reduce only just before
  60.    the ENDPROC.
  61.    Somehow it just doesn't feel right to me. Is there a better way?
  62.    
  63.    It sounds to me I'm reinventing the wheel, so maybe there is a
  64.    kind person who wants to explain to me how a wheel should look like?
  65.  
  66. -- frans van hoesel
  67.  
  68. scheek@rugrcx.rug.nl or
  69. hoesel@igc.ethz.ch
  70. (both are me)
  71. -- 
  72. Send compilers articles to compilers@iecc.cambridge.ma.us or
  73. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  74.