equation parser class.
synopsis:
EquationParser parses a general algebraic equation, involving numbers, variables, unary and binary operations, and parentheses. It returns a set of simpler, parsed (space-separated) equations with only 1, 2, or 3 token right-hand-side expressions: assignments, unary operations, binary operations.
constructor arguments:
- equation (string)
lhs=rhs string to be parsed
- postfix (boolean) (optional, default=False)
if True, generate postfix notation, otherwise infix
- varlist (list) (optional, default=None)
list of variables which are to be treated specially: if variable contains meta-character, it is replaced with a temporary name, then after parsing, re-replaced.
- debug (boolean) (optional, default=False)
if True, print out parsing information
- data_function_format (boolean) (default=True)
if True, print out functions in Data-object-compatible format.
operator precedence (low to high):
&& ||
< <= == != >= >
+ - (add, sub)
* / %
+ - ! (unary)
^
example:
>>> from decida.EquationParser import EquationParser
>>> ep = EquationParser("z =V(1)* sin(x+3.0)*ID(mp2)",
... varlist=["V(1)", "ID(mp2)"])
>>> eqns = ep.parse()
>>> for eqn in eqns :
>>> print eqn
zz1003 = x + 3.0
zz1004 = sin zz1003
zz1005 = V(1) * zz1004
z = zz1005 * ID(mp2)
public methods:
parse the equation and return the result.
results:
- return set of parsed equations with tokenized right-hand-side expressions of 1, 2 or 3 (space-separated) tokens.
return list of intermediate variables in the current result.
results :
- Lists all the intermediate lhsvars created in the set of parsed equations.