Is there a simple transformation or workaround to make this work in ANTLR4?
a : a p
| b q
| c
;
b : b r
| a s
| d
;
That is, a and b are self-left-recursive and mutual-left-recursive, the other rules (c, d, p, q, r, s) are just placeholders for simple rules.
Firstly, remove direct left recursion from both rules. Let's consider the rule
a:Simplify:
Do a similar transformation for the rule
b:Now it's possible to replace
bidentifier in ruleawith the body of ruleb:Or to replace
aidentifier in rulebwith the body of rulea:It's also possible to get rid of direct left recursion if needed.