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.
精彩评论