[英]error recovery in byacc/j and jflex using error token like in yacc
i am writing a compiler for a small language using byacc/j and jflex.我正在使用 byacc/j 和 jflex 为一种小型语言编写编译器。 i have no problem in finding first error in a given input file.
我在给定的输入文件中找到第一个错误没有问题。 the problem is i cant find more errors.
问题是我找不到更多错误。 first i used to use yacc and lex and i used special symbol 'error' token at the end of some grammar rules which was built in yacc and i could use 'yyerrok' to simply continue parsing and finding more errors but, in byacc/ji cant find something like that and yyerrok does not work and byacc/j does not recognize that.
首先,我曾经使用 yacc 和 lex,我在一些内置于 yacc 的语法规则的末尾使用了特殊符号“错误”标记,我可以使用“yyerrok”来简单地继续解析并找到更多错误,但是在 byacc/ji找不到类似的东西,yyerrok 不起作用,byacc/j 不承认这一点。 any suggestions to find more than one error in byacc/j?
有什么建议可以在 byacc/j 中找到多个错误? or is there ' error ' and 'yyerrok' in byacc/j?
或者 byacc/j 中是否有“错误”和“yyerrok”?
The only thing that yyerrok
does is reset the count of tokens since the last error notification. yyerrok
唯一做的就是重置自上次错误通知以来的令牌计数。 Yacc parsers suppress error messages in the first three tokens after an error recovery, to prevent cascading error messages. Yacc 解析器在错误恢复后抑制前三个标记中的错误消息,以防止级联错误消息。
Using yyerrok
-- or setting yyerrflag
to 0 -- indicates that error recovery was successful and that error messages should now be produced.使用
yyerrok
-- 或将yyerrflag
设置为 0 -- 表示错误恢复成功并且现在应该生成错误消息。 It does not have any other effect: with or without yyerrok
, parsing will continue.它没有任何其他效果:无论有没有
yyerrok
,解析都将继续。
yyerrok
is a C macro, and Java doesn't have macros. yyerrok
是一个 C 宏,而 Java 没有宏。 So apparently it was dropped from the Java interface.所以显然它是从 Java 接口中删除的。 But
yyerrflag
exists as a parser class member and you should be able to just set it to zero in a parser action.但是
yyerrflag
作为解析器 class 成员存在,您应该能够在解析器操作中将其设置为零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.