473,320 Members | 1,868 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,320 software developers and data experts.

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 1854
"Al Christians" <ac*****@easystreet.com> wrote in message
news:10*************@corp.supernews.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*****@easystreet.com> wrote in message
news:10*************@corp.supernews.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
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...
22
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
by: junky_fellow | last post by:
Can someone suggest some good links for the "beginners" about how expressions are parsed in C ? thanx..
4
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....
5
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...
8
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 ...
21
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...
2
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...
32
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.