build a syntax tree

Discussion in 'Python' started by Federico, Dec 18, 2007.

  1. Federico

    Federico Guest

    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 :)
     
    Federico, Dec 18, 2007
    #1
    1. Advertising

  2. On Dec 18, 10:43 pm, Federico <> 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
     
    Arnaud Delobelle, Dec 19, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ramkumar Menon

    B+ Tree versus Ternary Search Tree

    Ramkumar Menon, Aug 16, 2005, in forum: Java
    Replies:
    2
    Views:
    1,606
    Roedy Green
    Aug 16, 2005
  2. Ramkumar Menon

    B+ Tree versus Ternary Search Tree

    Ramkumar Menon, Aug 16, 2005, in forum: Java
    Replies:
    0
    Views:
    444
    Ramkumar Menon
    Aug 16, 2005
  3. Ramkumar Menon

    B+ Tree versus Ternary Search Tree

    Ramkumar Menon, Aug 16, 2005, in forum: Java
    Replies:
    1
    Views:
    459
    Andrew Thompson
    Aug 16, 2005
  4. Joris Gillis
    Replies:
    2
    Views:
    1,543
    Joris Gillis
    Jun 16, 2006
  5. Stub

    B tree, B+ tree and B* tree

    Stub, Nov 12, 2003, in forum: C Programming
    Replies:
    3
    Views:
    10,145
Loading...

Share This Page