0

I have the following in a JavaCC file:

void condition() : {}
{
    expression() comp_op() expression()
    | condition() (<AND> | <OR>) condition()
}

where <AND> is "&&" and <OR> is "||". This is causing problems due to the fact that it is direct left-recursion. How can I fix this?

sepp2k
  • 363,768
  • 54
  • 674
  • 675
Aine
  • 195
  • 1
  • 2
  • 10

1 Answers1

2

A condition is essentially 1 or more of expression comp_op expression separated by an AND or an OR. You could do the following

condition --> simpleCondition ( (<AND> | <OR>) simpleCondition )*
simpleCondition --> expression comp_op expression
Isaac Kwan
  • 99
  • 2
  • 10
Theodore Norvell
  • 15,366
  • 6
  • 31
  • 45