On Dec 18, 10:43 pm, Federico <[EMAIL PROTECTED]> wrote: > Hi I've some trivial question: > > for exercise I want to parse a string that like this: > > "x -34 + 65 * 96 = 102" > > now if I had this ("(25+24)/2") is extremely easy to have a result but > I want to resolve the above string (for the 'x' variable) what can I > do? > > Especially for symbolic function I think that I've to build an > 'operations tree' with a variable table. > I want to know how Derive parse this kind of string. > > If I've to build a tree, please give me resources and/or examples of > what physically is a tree and how to build on python. > > Thanks :)
You can use a parser generator to build the syntax tree that you want. See http://wiki.python.org/moin/LanguageParsing for a list. Perhaps pyparsing is a good one to start with? http://pyparsing.wikispaces.com/ HTH -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list