error handling - When using yacc, how do you tell yyparse() that you want to stop parsing? -
still learning yacc , flex, , ran across scenario how-to's , tutorials have not cover. trying parse file, , i'm going along, i'm doing secondary error checking in code i've placed in parser.y
file. when come across lexicographically correct (that is, parse matches properly) logically incorrect (unexpected value or inappropriate value), how yyparse
exit? also, can have return error code me can check in calling code?
/* sample */ my_file_format: header body_lines footer ; header: obrace int cbrace | obrace string cbrace { if ( strcmp ( $1, "contrived_example" ) != 0 ) { /* want exit here */ } } ; /* etc ... */
i realize in example can "contrived_example" using rule, point in if
-block -- can tell yyparse
want stop parsing here?
you can use macros yyerror
or yyabort
depending on want. yyabort
causes yyparse return failure, while yyerror
causes act if there's been error , try recover (which return failure if can't recover).
you can use yyaccept
cause yyparse return success.
Comments
Post a Comment