How Would You Do: Parsing and Expression Evaluation
ptmcg at austin.rr._bogus_.com
Tue Apr 27 14:36:09 CEST 2004
"Al Christians" <achrist at easystreet.com> wrote in message
news:108rren1js1hn71 at 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,
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 .
More information about the Python-list