I have constructed an SLR(1) parsing table with the following rules.
- S -> S + S + S (rule 1)
- S -> S + S (rule 2)
- S -> y
Is reducing rule 2, then shifting + and y, then again rule 2, equivalent to reducing rule 1? Can I claim to have reduced by rule 1, even though I did so indirectly?
S + S + S + S + S + S
). $\endgroup$ – Raphael♦ Dec 2 '14 at 13:03"y+y+y"
rule will not ne used since the"y+y"
will be used. Then, the parse tree or the AST can be transformed so that arguments are reorganized by groups of 3 arguments, if that is useful. Actually, program optimizers do things that are a lot more complicated than that. There is also the possibility of building several parse trees when the grammar is ambiguous. Actually, you can even manage to use a parser the will give preference to rule 1 whenever possible. But that requires very different and costlier parsing techniques (dynamic programming, with weighted grammar rules). $\endgroup$ – babou Dec 2 '14 at 23:17