By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

How Would You Do: Parsing and Expression Evaluation

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.