The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Message from discussion Left and right recursion with subtraction

From:
To:
Cc:
Followup To:
Subject:
 Validation: For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon.

More options May 31 2011, 5:23 pm
From: astromme <andrew.stro...@gmail.com>
Date: Tue, 31 May 2011 14:23:36 -0700 (PDT)
Local: Tues, May 31 2011 5:23 pm
Subject: Re: Left and right recursion with subtraction
After consulting the dragon book and some online resources I've come
up with

group4end = Delayed()
add = ~symbol('+') & group3 & group4end > List
sub = ~symbol('-') & group3 & group4end > List
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).

Andrew

On May 31, 3:53 pm, Andrew Stromme <andrew.stro...@gmail.com> wrote:

> Hi there,

> A part of my parser deals with expressions matching. I'm handling operator
> precedence as shown onhttp://www.acooke.org/lepl/intro-4.html

> sub = group3 & ~symbol('-') & group4 > Sub._make
> group4 += add | sub | group3

> 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?

> Thanks,

> Andrew