Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!novia!news-out.readnews.com!news-xxxfer.readnews.com!news.misty.com!news.iecc.com!nerds-end From: James Harris Newsgroups: comp.compilers Subject: Yacc/Bison - what semantic actions to take on a parse error Date: Wed, 23 May 2012 04:19:36 -0700 (PDT) Organization: Compilers Central Lines: 21 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <12-05-014@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: leila.iecc.com 1337832988 38766 64.57.183.58 (24 May 2012 04:16:28 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Thu, 24 May 2012 04:16:28 +0000 (UTC) Keywords: yacc, errors, comment Posted-Date: 24 May 2012 00:16:28 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com X-Received-Bytes: 1989 Xref: csiph.com comp.compilers:643 Yacc etc allow the special "error" keyword to be used in rules to aid error recovery. Where those rules are there to generate a node of a tree and there has been a parse error what should one tell Yacc to do? Sometimes there's nothing valid one can build a node from and I can't find a good way to communicate the situation to Yacc. I've looked at various options. Some are OK in certain cases but none seem right in the general case. I'll post more details if interested but there may be a simple answer. Anyone know of an easy or a standard answer or can provide some recommendations? James [My standard answer is that the error token is mostly useful for resynchronizing to try to find some more syntax errors, but that it's a losing battle to try to do much what you've parsed. Since the recovery process pops stuff on the stack and throws it away, you're going to lose some partially parsed subtrees and get a storage leak unless you hack on the parser skeleton to do something with the stuff that's popped off. Bison added %destructor to let you do that. -John]