I try to make a grammer with ANTLR with the following specifics.
It can parse an identifier like:
foo > bar > 67
where foo > bar is the identifier, because if > followed by a letter it contains to the identifier and else its a greater than operator.
And I it should parse things like
((a = 1) AND (b = 2)) OR (c = 3)
where the ( ) are necessary.
I'm really new to this topic and ANTLR and hope someone can help.
I'm currently have this grammer
grammar testgrammer;
start : statement EOF;
statement
: operation (AND operation)*;
operation
: '(' ID OPERATOR INT ')';
AND : 'AND';
OPERATOR: '=' | '>';
ID
: ('a'..'z'| 'A'..'Z')+ (WS '>' WS ('a'..'z' | 'A'..'Z')+)?
;
WS
: ' '+ {skip();}
;
INT : '0'..'9'+
;
but I can't figure out howto switch between the > in an id and the > as an operator.