我使用yy_scan_string
andyyparse()
来解析一些文本。当出现语法错误时,我想继续解析下一个字符串,但它不起作用。
yacc 文件片段:
set:SET PARENTHESIS reference EQUAL expression CLOSE_PARENTHESIS {$$ = set_directive($3,$5); }
|error { printf("set error abourt!");YYACCEPT;}//when appears error,I want to continue parsing the next string.I hava used YYABORT,but it not work as I want
;
...
int main(){
yy_scan_string("#set($b ==9)"); //this string has syntax error.
yyparse();
yylex_destroy();
printf("=====================11111========================\n");
traverse(snode); //print the ast
free_tree(snode); // release the memory
yy_scan_string("#if($r==5) wewqewqe #end"); //this string is right,I want to continue to parse this after paser the string on it: "#set($b ==9)"
yyparse();
yylex_destroy();
printf("=====================222222========================\n");
traverse(snode);
free_tree(snode);
return 1;
}
int yywrap(){
return 1;
}
int yyerror(char* s){
printf("=====================error %s========================\n",s);
//reset_input();
//yyclearin;
return 0;
}
我该怎么办,请帮帮我!