|Basic parser grammar question firstname.lastname@example.org (Denis Washington) (2007-04-20)|
|Basic parser grammar question email@example.com (O JuciE) (2007-04-26)|
|From:||O JuciE <firstname.lastname@example.org>|
|Date:||26 Apr 2007 09:34:45 -0400|
|Posted-Date:||26 Apr 2007 09:34:45 EDT|
Denis Washington <email@example.com> wrote:
> This piece of grammar works fine if I have simple additive expressions
> like "a + b", but fails to function if having longer arrays of additive
> expressions, e.g. "a + b + c". Why is that? Have I missed something? I
> hope you can help me.
I think your problem is that your productions aren't recursive. Let's
look at the following example, extracted from
: expression PLUS expression
| expression MINUS expression
| expression TIMES expression
| expression DIVIDE expression
Note the 'expression' production is recursive. That's why this grammar
can handle repetitions, like the ones you want your parser to grasp: a +
b + c is actually (a + b) + c.
I hope it helps, I am not a user of PLY myself, not even a regular
Return to the
Search the comp.compilers archives again.