I have a simple PEG parser that generates an AST tree. Every operator is right associative, so parsing A + B + C + D returns a tree [1]. Is there a simple way to transform [1] tree to one that would be created by left associative operator [2]?
[1] + [2] +
/ \ / \
A + + D
/ \ / \
B + + C
/ \ / \
C D A B
PEG generate right associative trees by default. You can add a post-processing step to invert it, like this: