Related articles |
---|
Basic parser grammar question dwashington@gmx.net (Denis Washington) (2007-04-20) |
Basic parser grammar question jucie@ig.com.br (O JuciE) (2007-04-26) |
From: | Denis Washington <dwashington@gmx.net> |
Newsgroups: | comp.compilers |
Date: | 20 Apr 2007 10:24:12 -0400 |
Organization: | Compilers Central |
Keywords: | parse, question |
Posted-Date: | 20 Apr 2007 10:24:12 EDT |
Hello,
I have a small problem with a PLY [1] grammer, more particularly with
the part that parses arithmetic expressions, which looks like in the
following extract:
def p_additive_expression_pass(p):
"additive-expression : multiplicative-expression"
p[0] = p[1]
def p_additive_expression(p):
"additive-expression : additive-expression additive-operator
multiplicative-expression"
p[0] = operator_expression_to_call(p[2], p[1], [p[3]], filename,
p.lineno(1))
def p_additive_operator_plus(p):
"additive-operator : PLUS"
p[0] = "__add__"
def p_additive_operator_minus(p):
"additive-operator : MINUS"
p[0] = "__sub__"
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.
Regards,
Denis Washington
[1] http://www.dabeaz.com/ply/
Return to the
comp.compilers page.
Search the
comp.compilers archives again.