Here's an example.

E <- E '+' V
  / V
V <- 'a'

E is left recursive so we break it into left and non-left parts.

E <- E_nonleft E_left*  # This is the looping part

E_nonleft <- V

E_left <- left_hand_side '+' V  # left_hand_side given as argument

Obviously, E and E_nonleft can only give one match per position.

Orlando, your example makes it pretty clear that this is almost the transformation performed for directly left-recursive productions for Pappy and Rats!.

The difference is that there is no nonterminal argument, only a semantic value argument. I.e., E_left produces promises that take one argument, which are then forced when creating the value for E.

Rats! currently does this transformation only when the semantic value is automatically deduced but I think I can generalize it to arbitrary semantic actions. And following your discussion, I should be able to generalize it to mutually left-recursive productions as well.

Robert


_______________________________________________
PEG mailing list
PEG@lists.csail.mit.edu
https://lists.csail.mit.edu/mailman/listinfo/peg

Reply via email to