1

我正在尝试创建 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)!='/'}? '*'
    | ~('*')
    )+;
4

0 回答 0