help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to raise an error


From: Luca
Subject: Re: How to raise an error
Date: Fri, 09 Oct 2009 20:12:54 +0200
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

CreateIdentifierNode function can return a pointer to a struct (typically a 
pointer to a node).
You can set the error in a field inside the node; you have also to increase an error counter (increase the same variable inside yyerror).

Then you can parse the remaining input, for example:

exp:    
         INTEGER                        {$$ =AddIntNode($1);}
        |identifier                     {$$ = $1; }
        |exp '+' exp                    {$$ = AddNode('+',$1,$3); /*check the 
two children and returns a pNode */}      

so AddIntNode and AddNode can recognize the error and perform the right action 
(so they can propagate the error up to the root of the syntax tree).


I suggest to read the follwing pdf:
http://epaperpress.com/lexandyacc/download/lexyacc.pdf
there is an example for a calculator using node.

Bye,
Luca


BradDaBug ha scritto:
My parser basically works by calling various functions that build a big parse
tree. Something like this:

identifier:
   LOCALIDENTIFIER { $$ = CreateIdentifierNode(yytext); }

The problem is that I need to be able to detect errors within those
functions (for example, is the identifier name too long) and propagate them
back to Bison. But I don't know how. I don't have access to the YYERROR
macro in those functions, and I can't manually "goto yyerrorlab;" since I'm
in a different function.

How can I do it?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]