[antlr-interest] parsing boolean expressions: not not or abc
lord.of.board at gmx.de
lord.of.board at gmx.de
Thu Jan 14 01:10:24 PST 2010
Hello,
I am trying to build a grammar which accepts boolean expressions for filtering. I found some interesting articles on the web, but now I got stuck.
I try to parse something like this:
not not or abc
The first "not" is the boolean operator and the second is a text.
Or even worse
not not and not or and not and
My grammar look like this:
grammar TextFilterGrammar;
options {
output=AST;
}
content : orexpression
;
orexpression
: andexpression (OR^ andexpression)*
;
andexpression
: expression (AND^ expression)*
;
expression
: (NOT^)? term
;
term : WORD
;
NOT : 'not'
;
AND : 'and'
;
OR : 'or'
;
WORD : ('a'..'z' | '0'..'9' | '%' | '_')+
;
WS : (' ' | '\r' | '\n' | '\t') { skip(); }
;
In ANTLRWorks I always get a MismatchedTokenException when trying to parse "not not or ljsdf". Parsing e.g. "not noti or ljsdf" works fine.
I managed to get it working with quotation marks, but I would prefer to have a solution without.
Best regards,
Lordi
--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
More information about the antlr-interest
mailing list