-----Original Message-----
From: pyp...@li...
[mailto:pyp...@li...] On Behalf Of
happybrowndog
Sent: Saturday, May 17, 2008 3:25 PM
To: pyp...@li...
Subject: [Pyparsing] Function parameters that may have brackets
Hi,
I have been trying to solve this, but just can't figure it out.
I have a function with parameters that I want to parse. The function is of
this form:
NUMBERTOSTR(param)
where param is any expression that evaluates to an integer or floating point
number, for example:
3 + 2
(3 + 2) / 4
((3 + 2) / 4) + 7
param thus can have any number of brackets.
>>>>>>>>>>>>>>>>>>>>>>>>>>
Check out fourFn.py or simpleArith.py for examples on how to parse
arithmetic expressions. You are on the right track in that Forward() is
required, but you aren't really using it correctly. If you model your
grammar after simpleArith, then your code will use a call to
operatorPrecedence, but the implementation of operatorPrecedence uses
Forward to define the nested expressions. The grammar in fourFn.py will
show you how Forward should be used.
If you don't have these in your pyparsing examples directory, you can get
them directly from the pyparsing wiki Examples page:
http://pyparsing.wikispaces.com/Examples. Or write back for more help.
-- Paul
|