我试图创建antlr语法来解析javadoc注释。我使用ANTLR v2。
为什么第一语法产生非确定性警告而第二语法不产生? 我认为它们很相似。
第一语法:
class TestParser extends Parser;
options {
buildAST = true;
k = 2;
}
startRule: START TEXT END;
class TestLexer extends Lexer;
options {
k = 2;
}
START: "/**";
END: "*/";
TEXT: (
{LA(2)!='/'}? '*'
| ~('*')
)+;
警告:
warning:lexical nondeterminism between rules START and TEXT upon k==1:'/' k==2:'*' warning:lexical nondeterminism between rules END and TEXT upon k==1:'*' k==2:'/'
第二语法:
class TestParser extends Parser;
options {
buildAST = true;
k = 2;
}
startRule: "/**" TEXT "*/";
class TestLexer extends Lexer;
options {
k = 2;
}
TEXT: (
{LA(2)!='/'}? '*'
| ~('*')
)+;