Package ComboCode :: Package cc :: Package ivs :: Package sigproc :: Package lmfit :: Module asteval :: Class Interpreter
[hide private]
[frames] | no frames]

Class Interpreter

source code

mathematical expression compiler and interpreter.

This module compiles expressions and statements to AST representation,
using python's ast module, and then executes the AST representation
using a dictionary of named object (variable, functions).

This then gives a restricted version of Python, being a procedural
language (though working on Python objects) with a simplified, flat
namespace (this is overcome in related implementaions). The program
syntax here is expected to be valid Python.

The following Python syntax elements are not supported:
    Import, Exec, Lambda, Class, Global, Generators,
    Yield, Decorators, Finally for Try-Except

Many parts of Python syntax are supported, including:
   advanced slicing:    a[::-1], array[-3:, :, ::2]
   if-expressions:      out = one_thing if TEST else other
   list comprehension
   for-loops, while-loops
   if-then-elif-else conditionals
   try-except (but not the 'finally' variant...)
   function definitions with def

Instance Methods [hide private]
 
__init__(self, symtable=None, writer=None, use_numpy=True) source code
 
unimplemented(self, node)
unimplemented nodes
source code
 
raise_exception(self, node, exc=None, msg='', expr=None, lineno=None)
add an exception
source code
 
parse(self, text)
parse statement/expression to Ast representation
source code
 
run(self, node, expr=None, lineno=None, with_raise=True)
executes parsed Ast representation for an expression
source code
 
__call__(self, expr, **kw) source code
 
eval(self, expr, lineno=0, show_errors=True)
evaluates a single statement
source code
 
dump(self, node, **kw)
simple ast dumper
source code
 
on_expr(self, node)
expression
source code
 
on_index(self, node)
index
source code
 
on_return(self, node)
return statement: look for None, return special sentinal
source code
 
on_repr(self, node)
repr
source code
 
on_module(self, node)
module def
source code
 
on_pass(self, node)
pass statement
source code
 
on_ellipsis(self, node)
ellipses
source code
 
on_interrupt(self, node)
interrupt handler
source code
 
on_break(self, node)
break
source code
 
on_continue(self, node)
continue
source code
 
on_assert(self, node)
assert statement
source code
 
on_list(self, node)
list
source code
 
on_tuple(self, node)
tuple
source code
 
on_dict(self, node)
dictionary
source code
 
on_num(self, node)
return number
source code
 
on_str(self, node)
return string
source code
 
on_name(self, node)
Name node
source code
 
node_assign(self, node, val)
here we assign a value (not the node.value object) to a node this is used by on_assign, but also by for, list comprehension, etc.
source code
 
on_attribute(self, node)
extract attribute
source code
 
on_assign(self, node)
simple assignment
source code
 
on_augassign(self, node)
augmented assign
source code
 
on_slice(self, node)
simple slice
source code
 
on_extslice(self, node)
extended slice
source code
 
on_subscript(self, node)
subscript handling -- one of the tricky parts
source code
 
on_delete(self, node)
delete statement
source code
 
on_unaryop(self, node)
unary operator
source code
 
on_binop(self, node)
binary operator
source code
 
on_boolop(self, node)
boolean operator
source code
 
on_compare(self, node)
comparison operators
source code
 
on_print(self, node)
note: implements Python2 style print statement, not print() function.
source code
 
_printer(self, *out, **kws)
generic print function
source code
 
on_if(self, node)
regular if-then-else statement
source code
 
on_ifexp(self, node)
if expressions
source code
 
on_while(self, node)
while blocks
source code
 
on_for(self, node)
for blocks
source code
 
on_listcomp(self, node)
list comprehension
source code
 
on_excepthandler(self, node)
exception handler...
source code
 
on_tryexcept(self, node)
try/except blocks
source code
 
on_raise(self, node)
raise statement: note difference for python 2 and 3
source code
 
on_call(self, node)
function execution
source code
 
on_arg(self, node)
arg for function definitions
source code
 
on_functiondef(self, node)
define procedures
source code
Class Variables [hide private]
  supported_nodes = ('arg', 'assert', 'assign', 'attribute', 'au...
Method Details [hide private]

on_print(self, node)

source code 

note: implements Python2 style print statement, not print() function. May need improvement....


Class Variable Details [hide private]

supported_nodes

Value:
('arg',
 'assert',
 'assign',
 'attribute',
 'augassign',
 'binop',
 'boolop',
 'break',
...