tags:

views:

76

answers:

1
+2  A: 

I would suggest to have a look at the example grammers on the antlr site. The java grammar does what you want.

Basicly you can do something like this:

expr : andexp;
andexpr : orexpr (AND andexpr)*;
orexpr : notexpr (OR orexpr)*;
notexpr : atom | NOT expr;

The key is, that every expression can end to be an atom.

Arne
Thanks for your answer. My issue with this solution is that the parse tree looks odd: every atom has a notexpr as parent, even if that's not really a notexpr. Maybe LL(*) parsers are not the best solution for this kind of parsing?
WardB
Theres nothing wrong with LL parsers for this kind of grammer (is very common to use this kind of expression). If you generate an AST you can use rewrite rules to create an AST that does not include the "superflues" parents.
Arne