On Tue, Jun 21, 2011 at 09:54:09PM -0400, Andrew Stromme wrote:
> Hi Andrew,
> I'm just checking in with regards to the repetition vs recursion and left
> recursion/right recursion question I had a while back. The parsing part of
> my project was on the back burner but I'm picking it up again and remembered
> that I had this issue to look at. I had a look at the expression.py example
> but couldn't get it to work myself with Tokens.
> Thanks,
> Andrew Stromme
> On Tue, May 31, 2011 at 7:13 PM, andrew cooke <and...@acooke.org> wrote:
> > Hi,
> > I am trying to look at this, but am having some "issues" with running any
> > Python code at all, so it may be some time before I can get back.
> > FWIW it seems like you are right and that exmple is wrong. What I would
> > like
> > to do is extend the approach at
> > http://code.google.com/p/lepl/source/browse/src/lepl/_example/express...
> > which uses repeptition rather than recursion. I thnk that could give a
> > clean
> > solution, with some work (eg using "sum(...)")
> > Sorry I can't be more help right now - will try and be more useful in the
> > new
> > day or two.
> > Andrew
> > On Tue, May 31, 2011 at 02:23:36PM -0700, astromme wrote:
> > > 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 received this message because you are subscribed to the Google Groups
> > "lepl" group.
> > > To post to this group, send email to lepl@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > lepl+unsubscribe@googlegroups.com.
> > > For more options, visit this group at
> > http://groups.google.com/group/lepl?hl=en.
> > --
> > You received this message because you are subscribed to the Google Groups
> > "lepl" group.
> > To post to this group, send email to lepl@googlegroups.com.
> > To unsubscribe from this group, send email to
> > lepl+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/lepl?hl=en.
> --
> You received this message because you are subscribed to the Google Groups "lepl" group.
> To post to this group, send email to lepl@googlegroups.com.
> To unsubscribe from this group, send email to lepl+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/lepl?hl=en.