After consulting the dragon book and some online resources I've come
group4end = Delayed()
add = ~symbol('+') & group3 & group4end > List
sub = ~symbol('-') & group3 & group4end > List
group4end += Optional(add | sub)
group4 += group3 & group4end > List
which should associate things as expected, I think? However, this
makes it a lot harder to generate nodes on the fly. I still would like
to have nodes that look sort of like (subtract (subtract 4 3) 2).
On May 31, 3:53 pm, Andrew Stromme <andrew.stro...@gmail.com> wrote:
> Lets assume that I am trying to parse 4 - 3 - 2 to get -1. The above grammar
> matches expressions incorrectly because ((4 - 3) - 2) is different from (4 -
> (3 - 2)). The parser generates an AST that corresponds to the 2nd option,
> which is wrong. I could rewrite the grammar as a left-recursive grammar, but
> that isn't good because it's best not to memoize. Any ideas?