c++ - Handle exception as a parse error in bison -
how catch en exception thrown upon executing rule in bison like
foo : bar { $$ = new bar($1); }
the bar constructor throws std::invalid_argument
exception if it's argument inappropriate. catch exception , raise compilation error, native error message like
input:42.10: bad value `baz' bar
also there lot of kind of rules, great handle not within rule itself, somewhere in parser.
if using lalr1.cc
, c++ skeleton of bison, there limited support exceptions: if throw yy::parser::syntax_error
, exception caught syntax error, duly reported, , parser enters error recovery mode. that's using yyerror
.
if throw else, whole parsing aborted, stack cleaned, , exception rethrown. that's yyabort
.
so if you'd errors caught rule-reduction should throw specific exception, see c++ parser interface documentation of bison.
Comments
Post a Comment