home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / compiler / 1884 < prev    next >
Encoding:
Internet Message Format  |  1992-11-15  |  2.1 KB

  1. Path: sparky!uunet!ogicse!das-news.harvard.edu!spdcc!iecc!compilers-sender
  2. From: danfuzz@wastelands.kaleida.com (Dan Bornstein)
  3. Newsgroups: comp.compilers
  4. Subject: Re: error recovery with yacc
  5. Keywords: yacc, errors
  6. Message-ID: <92-11-075@comp.compilers>
  7. Date: 14 Nov 92 03:55:47 GMT
  8. Article-I.D.: comp.92-11-075
  9. References: <92-11-038@comp.compilers>
  10. Sender: compilers-sender@iecc.cambridge.ma.us
  11. Reply-To: danfuzz@wastelands.kaleida.com (Dan Bornstein)
  12. Organization: Kaleida Labs, Inc.
  13. Lines: 42
  14. Approved: compilers@iecc.cambridge.ma.us
  15.  
  16. >I have a problem understanding/using the error recovery mechanisme
  17. >with yacc. Part of my syntax is:
  18. >
  19. >[...]
  20. >     statement_list
  21. >             : /* empty */
  22. >             | statement
  23. >             | statement_list separator
  24. >             | statement_list separator statement
  25. >             ;
  26. >[...]
  27. >
  28. >If some statement is in error then I just want to skip over the 
  29. >next separator (which is a ';' or NEWLINE) and continue the
  30. >parsing of the proc_body with the rest of the statements.
  31. >I added the following rule to the statement_list definition:
  32. >             | error separator statement_list
  33. >( no yyerrok here!) 
  34. >This seems ok, but causes the error to be reduce only just before
  35. >the ENDPROC.
  36. >Somehow it just doesn't feel right to me. Is there a better way?
  37.  
  38. The way I do it (and usually see it done) would be to reverse
  39. it around:
  40.  
  41.               | statement_list error separator
  42.  
  43. meaning, more or less, "A statement list followed by an error and a
  44. separator is still a statement list." The way you originally put it, "A
  45. statement list can start with an error and then a separator, but you still
  46. have to find another statement list after that." So, what yacc was doing
  47. was dutifully finding the longest statement_list following the error and
  48. separator before reporting the error.
  49.  
  50. Since a statement_list might be empty, you can still get the rule to
  51. reduce given an error at the beginning of the input text.
  52.  
  53. -Dan Bornstein
  54. danfuzz@kaleida.com
  55. -- 
  56. Send compilers articles to compilers@iecc.cambridge.ma.us or
  57. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  58.