Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!news.misty.com!news.iecc.com!nerds-end From: James Harris Newsgroups: comp.compilers Subject: Re: Yacc/Bison - what semantic actions to take on a parse error Date: Thu, 24 May 2012 22:49:50 -0700 (PDT) Organization: Compilers Central Lines: 43 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <12-05-022@comp.compilers> References: <12-05-014@comp.compilers> <12-05-021@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: leila.iecc.com 1337950369 62277 64.57.183.58 (25 May 2012 12:52:49 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Fri, 25 May 2012 12:52:49 +0000 (UTC) Keywords: yacc, errors, comment Posted-Date: 25 May 2012 08:52:49 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:651 On May 24, 8:05 pm, James Harris wrote: ... > 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 $$ = "invalid X node" > * Braces but no action, i.e. {} > * No action clause so default to $$ = $1; > * Some combination of YYERROR; and yyerror(); ... > 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? > [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] It sounds like you might be referring to type checking in the compiler's later semantic analysis phase. I was asking about the checking for a type match that the Yacc/Bison build process carries out. For example, if we leave the default action $$ = $1 in an error production the parser creation process might report something like $1 of 'X' has no declared type or, if we set $$ to a dummy error: cannot convert dummy_class* to X_class* in assignment James [Ah, that, right. If it were going to try to use the parse tree, I'd create a dummy node, otherwise { $$ = NULL; } -John]