[antlr-interest] tiny filter grammar

Cameron Taggart cameron.taggart at gmail.com
Wed Sep 20 23:42:57 PDT 2006


Hi I'm trying to build a grammar so that I can parse an existing
filter text.  Here is an example filter text:

( IsNull( {a}) or {b} =1 ) // comment
  AND ( IsNull ({c}) or  {d} = 1 )
 AND {e} = "Please Help!"

Being an antlr newbie, I'm having a hard time figuring out the secret
sauce for dealing with the various expression types.  I'm not really
sure how to deal with groups.  Here is my antlr v3 grammar in its
entirety:

grammar FilterParser;

group : '(' (expression|logical) ')';
expression : relational|isNull; // |logical; recursion overflow to
logical from expression
logical : (expression|group) (logicalOp (expression|group))+;
relational : Variable relationalOp (Number|String);
isNull : 'IsNull' '(' Variable ')';
relationalOp : '='|'!='|'>'|'<'|'>='|'<=';
logicalOp : 'AND'|'or'; // TODO case insensitive

LineComment : '//' ~('\n'|'r')+ {channel=99;};	
Variable : '{' ~('}')* '}';
Number : ('-'|'+')?('0'..'9')+('.'('0'..'9')+)?;
String	: '"' ~('"')* '"';

cheers,
Cameron


More information about the antlr-interest mailing list