Hi,
I'm using Antlr 4.1 to write a tool for parsing and translating a programming language. I just ran into a strange problem.
I have logical expression parsing written as:
expression
:(...)
| lhs=expression operator=(
AMPERSANDAMPERSAND
| PIPEPIPE
) rhs=expression # LogicalOperationExpression
which basically works quite well. Only I just parsed a bit of code where there were many, many OR's:
if(a || (b || c || d || e || ... || zz))
Antlr (both embed in my app and the Antlrworks one) basically froze. It was eating cpu cycles but with no result. I stated cutting back those ORs. At (a || (b || c)) it works fast. With 5 ORs it's a bit slower. With about 8 it starts to take loong time to parse it and with full load (14 I think) it just doesn't end in reasonable time.
Is that a known behaviour or a bug? And in both cases, what can I do to be able to parse such expressions?
I tried rewriting the rule to
| expression logicalRest+ #...
logicalRest
: operator=(
AMPERSANDAMPERSAND
| PIPEPIPE
) rhs=expression
;
but it still prefers to go recursive way instead of flattening it as expression -> expression, logicalRest, logicalRest, ..., logicalRest