Basic parser grammar question

O JuciE <>
26 Apr 2007 09:34:45 -0400

          From comp.compilers

Related articles
Basic parser grammar question (Denis Washington) (2007-04-20)
Basic parser grammar question (O JuciE) (2007-04-26)
| List of all articles for this month |

From: O JuciE <>
Newsgroups: comp.compilers
Date: 26 Apr 2007 09:34:45 -0400
Organization: Compilers Central
References: 07-04-072
Keywords: parse,
Posted-Date: 26 Apr 2007 09:34:45 EDT

Denis Washington <> 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
Python user.


O JuciĘ

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.