ANTLR输入不匹配'< EOF>' [英] ANTLR mismatched input '<EOF>'
问题描述
给出以下ANTLR 4.1语法,其中一行故意注释掉了...
Given the following ANTLR 4.1 grammar, with one line intentionally commented out ...
grammar Foobar;
//whyDoesThisRuleHelp : expression ;
expression : operand | binaryOperation ;
binaryOperation : operand WS BINARY_OPERATOR WS expression ;
operand : LETTER ;
BINARY_OPERATOR : 'EQ' ;
LETTER : [a-z] ;
WS : [ \n]+ ;
..为什么echo -n "a EQ b" | grun Foobar expression
产生
line 1:6 mismatched input '<EOF>' expecting WS
.. 但是如果我们取消注释,在上方的block : expression ;
行中,grun
不会产生任何错误?
.. but if we uncomment the block : expression ;
line above then grun
produces no errors?
推荐答案
您正在看到一个罕见但已知的错误的影响:
在没有明确的EOF的情况下,没有可行的替代方法可以错误地引发启动规则
You are seeing the effects of a rare but known bug:
No viable alternative can be incorrectly thrown for start rules without explicit EOF
正确解决此问题对性能的影响目前令人吃惊,因此我们无意在可预见的将来应用此补丁.解决方法是创建一个以显式EOF
结尾的规则,然后在此处开始解析.
The performance implications of properly fixing this are currently staggering, so we have no intention of applying the patch for the foreseeable future. The workaround is to create a rule that ends with an explicit EOF
, and start parsing there.
这篇关于ANTLR输入不匹配'< EOF>'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!