Re: Yacc/Bison - what semantic actions to take on a parse error

James Harris <james.harris.1@gmail.com>
Thu, 24 May 2012 22:49:50 -0700 (PDT)

          From comp.compilers

Related articles
Yacc/Bison - what semantic actions to take on a parse error james.harris.1@gmail.com (James Harris) (2012-05-23)
Re: Yacc/Bison - what semantic actions to take on a parse error james.harris.1@gmail.com (James Harris) (2012-05-24)
Re: Yacc/Bison - what semantic actions to take on a parse error james.harris.1@gmail.com (James Harris) (2012-05-24)
Re: Yacc/Bison - what semantic actions to take on a parse error cfc@shell01.TheWorld.com (Chris F Clark) (2012-05-30)
| List of all articles for this month |

From: James Harris <james.harris.1@gmail.com>
Newsgroups: comp.compilers
Date: Thu, 24 May 2012 22:49:50 -0700 (PDT)
Organization: Compilers Central
References: 12-05-014 12-05-021
Keywords: yacc, errors, comment
Posted-Date: 25 May 2012 08:52:49 EDT

On May 24, 8:05 pm, James Harris <james.harri...@gmail.com> 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 $<err_msg>$ = "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]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.