parenthesis
Scott Gilbert
xscottgjunk at yahoo.com
Tue Nov 5 15:39:33 EST 2002
mis6 at pitt.edu (Michele Simionato) wrote:
>
> Suppose I want to parse the following expression:
>
> >>> exp='(a*(b+c*(2-x))+d)+f(s1)'
>
I'm not sure if you want to understand why simple regexps can't do
what you want, or if you just want a solution to your problem. Here
is one path you could try:
>>> from compiler import parse
>>> parse(exp)
Module(None, Stmt([Discard(Add((Add((Mul((Name('a'), Add((Name('b'),
Mul((Name('c'), Sub((Const(2), Name('x'))))))))), Name('d'))),
CallFunc(Name('f'), [Name('s1')], None, None))))]))
Cheers,
-Scott
More information about the Python-list
mailing list