If I got a grammar rule like
a: A (C|D|E)
I can create AST for the rule by attaching rewrite rules for each alternative(C, D, E) like this:
a: A (C -> ^(A C)
| D -> ^(A D)
| E -> ^(A E))
But, if I got another slightly different grammar rule like
a: (A|B) (C|D|E)
how do I create AST for every possible match? I first tried like this:
a: (A|B) (C|D|E) -> ^((A|B) (C|D|E))
but, it did not work.
Is there a simple way to solve this problem?
Thanks in advance. 🙂
You have two options:
1
or:
2
Personally, I prefer the 2nd option.