开发者

This antlr example is not working properly

This ANTLR example does not parse input "1;" . Can you explain why? It parses "11;".

grammar TestGrammar;

options {
    output=AST;
}

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

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

protected
DIGI开发者_如何学PythonT:      '0'..'9';
INT:        (DIGIT)+;

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


For the java target, if you change: protected DIGIT : '0'..'9' ;

to fragment DIGIT : '0'..'9' ;

it will work.

Hope this helps you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜