[antlr-interest] [begginer question] could somebody help me to see this simple grammar?

devdoer bird devdoer2 at gmail.com
Wed Feb 16 00:18:42 PST 2011


HI,all:

the grammar is list below:
----------------------------------------------
logicExp
 :  FIELDNAME ( '>' | '<' ) (CONST_INT | CONST_STRING)
 | '(' logicExp')'

 ;

fragment DIGIT : '0'..'9';
fragment LOWER  : 'a'..'z';
fragment UPPER  : 'A'..'Z';
FIELDNAME : LOWER (LOWER|DIGIT)*  ;
CONST_INT : DIGIT+;
CONST_STRING : '"' (LOWER|UPPER|DIGIT)* '"';

----------------------------------------

When I use the antlrworks to test the grammar,I use the input "( a>3 )",but
the interepter failed to recoginze the last ")", output as follows:
 logicExp
   / \
 /    \
(    logicExp
      /\  \
     /  \  \
    a   >  3

As you see, the last ')'  is missed.
So what's wrong with my grammar?


More information about the antlr-interest mailing list