Suppose you want to parse input:
:3*4*:5*6
The parser generated by your grammar can match this entry in the following parsing trees:

and

(I skipped the colons to make the trees clearer)
Please note that you only see a warning. Specially instructing ANTLR that (('*' | '/') atom)* needs to be greedily matched as follows:
factor : atom (options{greedy=true;}: ('*'^ | '/'^) atom)* ;
the parser “knows” which alternative to take and no warning is issued.
EDIT
I tested the grammar with ANTLR 3.3 as follows:
grammar T; options { output=AST; } parse : expr EOF! ; expr : factor ; factor : atom (options{greedy=true;}: ('*'^ | '/'^) atom)* ; atom : INT | ':'^ expr ; INT : ('0'..'9')+;
And then from the command line:
java -cp antlr-3.3.jar org.antlr.Tool Tg
which does not cause any warnings (or errors).
Bart kiers
source share