[antlr-interest] Priority in interpreting input
peter.goetz at gutefrage.net
Tue Oct 23 04:10:34 PDT 2012
I am using ANTLR to parse an arithmetic expression and create an abstract syntax tree from it with node objects for every node type. A typical expression looks like this:
2 * sqrt(a1 + b2)
As you can see, those expressions can contain literal number values, functions and variables. In the crucial part of my grammar I have the following:
factor: LITERAL | funct | METRIC;
And as the definition of LITERAL and METRIC this:
METRIC : (Letter|Digit|Separator)+;
LITERAL : '0'..'9';
This is a very much simplified version of my real definitions just to make my point. If now I want to parse an expression it seems that ANTLR is not able to recognize the LITERAL, since this is matching as a METRIC, too.
How do I tell ANTLR that a literal-recognition has precedence over a recognized metric?
Thanks a lot for your help!
More information about the antlr-interest