Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #650
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!news.iecc.com!nerds-end |
|---|---|
| From | James Harris <james.harris.1@gmail.com> |
| Newsgroups | comp.compilers |
| Subject | Re: Yacc/Bison - what semantic actions to take on a parse error |
| Date | Thu, 24 May 2012 12:05:03 -0700 (PDT) |
| Organization | Compilers Central |
| Lines | 52 |
| Sender | news@iecc.com |
| Approved | comp.compilers@iecc.com |
| Message-ID | <12-05-021@comp.compilers> (permalink) |
| References | <12-05-014@comp.compilers> |
| NNTP-Posting-Host | news.iecc.com |
| X-Trace | leila.iecc.com 1337922148 85019 64.57.183.58 (25 May 2012 05:02:28 GMT) |
| X-Complaints-To | abuse@iecc.com |
| NNTP-Posting-Date | Fri, 25 May 2012 05:02:28 +0000 (UTC) |
| Keywords | yacc, errors, comment |
| Posted-Date | 25 May 2012 01:02:28 EDT |
| X-submission-address | compilers@iecc.com |
| X-moderator-address | compilers-request@iecc.com |
| X-FAQ-and-archives | http://compilers.iecc.com |
| Xref | csiph.com comp.compilers:650 |
Show key headers only | View raw
On May 23, 12:19 pm, James Harris <james.harri...@gmail.com> wrote:
> 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?
...
> [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.
I wasn't thinking about using the parse tree after the parse phase so
much as just completing the parse.
An example may help illustrate. Say were defining a node type X where
there is nothing special about that node type. We might have a grammar
construct something like the following. I'll use quotes "..." to
indicate descriptive text.
%type <X_type> X
X
: "a normal X" ';' { $$ = Xnode("specific data"); }
| error ';' { ACTION; }
;
The Xnode call constructs a node. The X production expects $$ to be
set to a node of the given type.
The issue is that the error production cannot create a meaningful node
so what actions to replace ACTION are appropriate? Here are some
options.
* Create an X node with dummy values. That would satisfy the type
checking.
* Set $<err_msg>$ = "invalid X node"
* Braces but no action, i.e. {}
* No action clause so default to $$ = $1;
* Some combination of YYERROR; and yyerror();
John, you'll know but for anyone who isn't aware of these options
those for Bison are shown at
http://www.gnu.org/software/bison/manual/html_node/Action-Features.html
So, which option is 'best'? Or should we just ignore a type mismatch
error?
James
[You already know you ran into a syntax error, so I'd think that type
checking is more likely to produce an error cascade than something
useful. -John]
Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar
Yacc/Bison - what semantic actions to take on a parse error James Harris <james.harris.1@gmail.com> - 2012-05-23 04:19 -0700
Re: Yacc/Bison - what semantic actions to take on a parse error James Harris <james.harris.1@gmail.com> - 2012-05-24 12:05 -0700
Re: Yacc/Bison - what semantic actions to take on a parse error James Harris <james.harris.1@gmail.com> - 2012-05-24 22:49 -0700
Re: Yacc/Bison - what semantic actions to take on a parse error Chris F Clark <cfc@shell01.TheWorld.com> - 2012-05-30 14:41 -0400
csiph-web