[antlr-interest] (newbie) Grammar question
Diehl, Matthew J
matthew.j.diehl at intel.com
Mon Aug 13 13:28:08 PDT 2007
> Now I'd like to add support for null and numerical tests like:
>
> bean1.enabled = bean2.value != null && bean3.value > 0
>
> My main issue is how to allow statements like !bean.enabled
> while preventing statements like bean.value < !5.
>
It sounds like you need split it into two rules: One for boolean
relationships, and the other for expressions. The '!' can only come
before relationships and cannot come in the middle of an expression.
relationship
: NEQ? expr //this does not allow nested like: !(this && that), so
you'd have to change.
| expr relationship_sign expr
;
relationship_sign : LessThan | GreaterThan | LEqual | GEqual ;
stat : PROPERTY '='! (expr | relationship); //allows both values or
booleans
expr : natom (oper^ natom)*;
natom : NOT^? atom;
atom : PROPERTY | '(' expr ')' -> expr
;
oper : AND | OR | EQ | NEQ;
More information about the antlr-interest
mailing list