473,396 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

build a syntax tree

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 :)
Dec 18 '07 #1
1 2695
On Dec 18, 10:43 pm, Federico <federico.bertola....@gmail.comwrote:
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

Dec 19 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
4
by: Bob hotmail.com> | last post by:
Everyone I have been spending weeks looking on the web for a good tutorial on how to use regular expressions and other methods to satisfy my craving for learning how to do FAST c-style syntax...
11
by: ajikoe | last post by:
Hello, I used Visual C# Standard Edition. I want to comment my program using xml commentary method, I don't know why if I use value and example tag, it is not working / showed in the html...
7
by: (Jamie Andrews) | last post by:
For a research project, we're looking for a reliable parser for C that will take an ANSI C program and yield a tree representation of the program (as a Java or C++ object). Of course a grammar...
2
by: glomde | last post by:
Hi I would like to extend python so that you could create hiercical tree structures (XML, HTML etc) easier and that resulting code would be more readable. The syntax i would like is something...
6
by: Heiko Wundram | last post by:
Hi all! The following PEP tries to make the case for a slight unification of for statement and list comprehension syntax. Comments appreciated, including on the sample implementation. ===...
7
by: plumb and tree | last post by:
I've been trying for days to build 64 bit python with Solaris 10 + Sun Studio 12. Can anyone helpl please. This is how I tried to do build: # ./configure --prefix=/opt/python2.4...
11
by: MonkeeSage | last post by:
A quick question about how python parses a file into compiled bytecode. Does it parse the whole file into AST first and then compile the AST, or does it build and compile the AST on the fly as it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.