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 lo
Why not something like :
identifier:
LOCALIDENTIFIER {
$$ = CreateIdentifierNode(yytext);
if ($$== NULL) {
YYERROR;
}
}
Then just get your CreateIdentifierNode to return NULL if its invalid..
(You can play with setting an e
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: