ANTLR4中的EOF行为

时间:2016-10-01 09:10:24

标签: compiler-construction antlr4

对于给定的输入:

hello hello

语法:

grammar test;

foo: bar ;
bar   : 'hello' bar | EOF;

WS  : [ \t\r\n]+ -> skip ;

我为规则栏获得了一个有效的解析树。

但是当我删除foo规则时:

grammar test;

bar   : 'hello' bar | EOF;

WS  : [ \t\r\n]+ -> skip ;

我收到错误“第1行第11行在输入时没有可行的选择'< EOF>”。这里发生了什么?我正在使用ANTLR4的intellij插件进行规则测试。

1 个答案:

答案 0 :(得分:0)

由ANTLR4的合著者Sam Harwell确认,这是ANTLR4中的错误。可以在这里跟踪:https://github.com/antlr/antlr4/issues/118

解决方法如问题所建议(使用额外的根规则foo)。