I have a fairly simple language represented as a CFG.
S → A z
A → A y A
| A x A
| A w
| v
Since there's left-recursion, a recursive descent parser isn't going to cut it. However, I also need to find every possible interpretation: given v x v y v z
, I need my parser to find both (v x (v y v)) z
and ((v x v) y v) z
.
What options do I have? Shift-reduce with added backtracking to find all possibilities seems good, but I've heard that adding backtracking to a shift-reduce parser can give it exponential time complexity. This CFG is small enough that it shouldn't matter, but I'm going to need to scale this up to significantly larger grammars (with thousands of terminals).