0

此 ANTLR 示例不解析输入“1;” . 你能解释一下为什么吗?它解析“11;”。

grammar TestGrammar;

options {
    output=AST;
}

expr:       mexpr (PLUS^ mexpr)* SEMI!;
mexpr:      atom (STAR^ atom)*; 
atom:       INT; 

LPAREN:     '('; 
RPAREN:     ')'; 
STAR:       '*'; 
PLUS:       '+'; 
SEMI:       ';';

protected
DIGIT:      '0'..'9';
INT:        (DIGIT)+;

WS:         (' ' | '\t' | '\n' | '\r') {
                $channel = HIDDEN;
            };
4

1 回答 1

1

对于 java 目标,如果您更改: protected DIGIT : '0'..'9' ;

对 DIGIT 进行分段:'0'..'9';

它会起作用的。

希望这对您有所帮助。

于 2010-05-03T13:06:15.357 回答