Hi,
Please bear with this possibly complicated problem.
I can perfectly form an LL1 grammar for javacc to parse logical
expressions, e.g 4+a>-3. This grammar does logical expressions
without precedence (to be brief):
Logical -> UnaryLogical ( (AND | OR) UnaryLogical ) *
UnaryLogical -> "(" Logical ")" | NOT UnaryLogical | ArithmExpr
LOGOP ArithmExpr
ArithmExpr -> UnaryArithExpr ( (+|-|*|/) UnaryArithExpr )*
UnaryArithExpr -> "(" ArithmExpr ")" | (+| -) UnaryArithExpr |
IDENTIFIER | NUMBER
LOGOP -> ">" | "<" | "==" | "<=" | ">="
The problem is, I am not sure how to recognise the possibility of a
function declaration instead of an expression, e.g: f (SomeArith)
without breaking LL1 compatibility, and hence resorting to lookaheads
and what not. These functions cannot be nested (i.e AND'es or OR'ed).
Consider for example, these statements that should all be recorgnised
by the new grammar:
4+5 > 6
(4+5) > 5
a(3)
a
(a)
(a(3))
!(a(3))
The third example is a function name without an argument, and should
be recognised. The functions return boolean and hence can replace the
logical expressions. I just can't come up with an LL1 parser for this.
Any help is greatly appreciated.
John


|