473,578 Members | 2,919 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How Would You Do: Parsing and Expression Evaluation

I've got an idea for an application, and I wonder how much of what it
takes to create it is available in open source python components.

My plan is this -- I want to do a simple spreadsheet-like application:
I've used a wxGrid, so I expect that wxPython will do fine for the user
interface. The spreadsheet can be organized vertically, one item per
line. It might need no more than 100 rows or so. On each line, the
user will enter in one column an item (variable) name and, in another
column, a formula or expression for computing the item's value. A
third column will show the computed value. There will usually be some
circular references between the items, but their values will converge
quickly with repeated evaluation.

The final feature is a button that the user can click when they have the
sheet set up correctly -- it will translate the formulas into simple C
and python code to perform the same calculations as the spreadsheet.

The formulas should be pretty easy -- add, subtract, multiply, divide,
log, exponential, and perhaps some user-defined functions.

Are there any off-the-shelf python libraries that would make this kind
of app much easier? I don't have any special experience related to such
things, so I surely don't want to re-invent the wheel out of pure
ignorance -- should I try the parsing tools in the standard python
library, or will something else work better for me?

TIA for any advice,
Al
Jul 18 '05 #1
2 1861
"Al Christians" <ac*****@easyst reet.com> wrote in message
news:10******** *****@corp.supe rnews.com...
I've got an idea for an application, and I wonder how much of what it
takes to create it is available in open source python components.

My plan is this -- I want to do a simple spreadsheet-like application:
I've used a wxGrid, so I expect that wxPython will do fine for the user
interface. The spreadsheet can be organized vertically, one item per
line. It might need no more than 100 rows or so. On each line, the
user will enter in one column an item (variable) name and, in another
column, a formula or expression for computing the item's value. A
third column will show the computed value. There will usually be some
circular references between the items, but their values will converge
quickly with repeated evaluation.

The final feature is a button that the user can click when they have the
sheet set up correctly -- it will translate the formulas into simple C
and python code to perform the same calculations as the spreadsheet.

The formulas should be pretty easy -- add, subtract, multiply, divide,
log, exponential, and perhaps some user-defined functions.

Are there any off-the-shelf python libraries that would make this kind
of app much easier? I don't have any special experience related to such
things, so I surely don't want to re-invent the wheel out of pure
ignorance -- should I try the parsing tools in the standard python
library, or will something else work better for me?

TIA for any advice,
Al


One of the examples that comes with pyparsing is a simple 4-function
expression parser and evaluator, that is easily extendable to add
exponentiation and user-defined functions.

Download pyparsing at http://pyparsing.sourceforge.net .

-- Paul
Jul 18 '05 #2
I may not be understanding what you want to do but
here goes:

You might just want to use eval() function and have
the expression evaluated by Python. That way your
expression could be any Python expression and you
don't have to parse the expression at all (e.g eval
parses and executes it and returns the value). You
also don't have to "translate" the formulas. They
are already Python expressions. Python expression
syntax is pretty much like what you would want.

Larry Bates
Syscon, Inc.

"Al Christians" <ac*****@easyst reet.com> wrote in message
news:10******** *****@corp.supe rnews.com...
I've got an idea for an application, and I wonder how much of what it
takes to create it is available in open source python components.

My plan is this -- I want to do a simple spreadsheet-like application:
I've used a wxGrid, so I expect that wxPython will do fine for the user
interface. The spreadsheet can be organized vertically, one item per
line. It might need no more than 100 rows or so. On each line, the
user will enter in one column an item (variable) name and, in another
column, a formula or expression for computing the item's value. A
third column will show the computed value. There will usually be some
circular references between the items, but their values will converge
quickly with repeated evaluation.

The final feature is a button that the user can click when they have the
sheet set up correctly -- it will translate the formulas into simple C
and python code to perform the same calculations as the spreadsheet.

The formulas should be pretty easy -- add, subtract, multiply, divide,
log, exponential, and perhaps some user-defined functions.

Are there any off-the-shelf python libraries that would make this kind
of app much easier? I don't have any special experience related to such
things, so I surely don't want to re-invent the wheel out of pure
ignorance -- should I try the parsing tools in the standard python
library, or will something else work better for me?

TIA for any advice,
Al

Jul 18 '05 #3

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

Similar topics

1
2688
by: Simon Wigzell | last post by:
A client wants have acess to an online databases records controlled by group strings and evaluation strings e.g., each use would have in his client record a group string like this: And each record in a database would have an evaluation string like this : ( OR OR OR ) AND OR ) etc.
22
3783
by: Tony Johansson | last post by:
Hello Experts! I'm reading i a book about C++ and they mention infix with telling what it is. I hope you out there can do so. Many thanks! //Tony
12
1792
by: junky_fellow | last post by:
Can someone suggest some good links for the "beginners" about how expressions are parsed in C ? thanx..
4
2567
by: Frank Wallingford | last post by:
Note: For those with instant reactions, this is NOT the common "why is i = i++ not defined?" question. Please read on. I came across an interesting question when talking with my colleagues. According to the standard, most operators evaluate their operands in an unspecified order. This means that in code like this: f() + g()
5
3251
by: gamehack | last post by:
Hi all, I was thinking about parsing equations but I can't think of any generic approach. Basically I have a struct called math_term which is something like: struct math_term { char sign; int constant; int x; int y;
8
2189
by: junky_fellow | last post by:
Hi, Sorry, for asking similar questions again and again. 1) I want to know how should we reslove the ambiguities in a c expression ? Should we use precedence table as mentioned in K&R book or should we refer to the ANSI C grammar ? 2) As told by many people in this newsgroup that ANSI C grammar does
21
2380
by: Steven T. Hatton | last post by:
I'm trying to improve my formal understanding of C++. One significant part of that effort involves clarifying my understanding of the vocabulary used to describe the language. This is from the C++ Standard: "" "...sequence of operators and operands that specifies a computation...". That means to me that an expression can be...
2
401
by: Tim Johnson | last post by:
I'm having trouble understanding this part of the expression evaluation rules ('6.5 Expressions', second item, C99 spec; the C++ wording is presumably identical): What precisely does the second part of this statement mean? The example states that "a = i" is invalid. But what about, for example: a = (b = c) || (c = d);
32
3280
by: silpau | last post by:
hi, i am a bit confused on expression evaluation order in expressions involving unary increment.decrement operators along with binary operators. For example in the following expression x += i + j + k++;
0
7850
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7779
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8126
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8291
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6524
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5343
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3786
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2293
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1391
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.