Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Left and right recursion with subtraction
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
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. Listen and type the numbers you hear
 
astromme  
View profile  
 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
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).

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

> add = group3 & ~symbol('+') & group4 > Add._make
> 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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.