Aftershock
Aftershock

Reputation: 5351

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
DIGIT:      '0'..'9';
INT:        (DIGIT)+;

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

Upvotes: 0

Views: 311

Answers (1)

WayneH
WayneH

Reputation: 340

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

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

it will work.

Hope this helps you.

Upvotes: 1

Related Questions