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?
_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison