[antlr-interest] (newbie) Grammar question

Andrew Pietsch andrew at pietschy.com
Sun Aug 12 17:59:53 PDT 2007


Hi all,

I've created a simple grammar for a value model binding framework I've been
playing with.  It's working well and currently lets me evaluated simple
statements for Javabean properties like:

bean1.enabled = bean2.value && !bean2.value

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.

Any advise on standard approaches to this kind of thing is greatly
appreciated.  My current grammar file is as follows:

stat    : PROPERTY '='! expr;
expr    : natom (oper^ natom)*;
natom    :    NOT^? atom;
atom    : PROPERTY | '(' expr ')' -> expr
    ;
oper    :  AND | OR | EQ | NEQ;

PROPERTY : ID ('.' ID)?;
WS      : ( ' ' | '\t' | '\n' | '\r' )  { $channel = HIDDEN; };

LPAREN  :     '(' ;
RPAREN  :     ')' ;
AND    :     '&&';
OR    :     '||';
EQ    :    '==';
NEQ     :    '!=';
LT    :    '<';
LTE    :    '<=';
GT    :    '>';
GTE    :    '>=';
NOT    :    '!';

fragment ID   : ALPHA (ALPHA | NON_ALPHA)*;

fragment ALPHA  :   ('a'..'z'|'A'..'Z')+ ;

fragment NON_ALPHA
    :    INT
    |     '-'
    |     '_'
    ;

fragment INT :   '0'..'9'+;

Thanks in advance
Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070813/94b653d0/attachment.html 


More information about the antlr-interest mailing list