A python implementation of an abstract syntax tree.
from pyast.parser import parse_operation
from pyast.constant import Constant
from pyast.variable import Variable
def parse_example():
to_parse = "a * bc + 123 / sin(3.1415 * n) ^ log_(2, 8) - e"
operation = parse_operation(to_parse)
# replace variables
evaluated = operation.evaluate(Variable("a"), Constant(5.0))
# replace functions
to_replace = parse_operation("sin(3.1415 * n)")
evaluated2 = operation.evaluate(to_replace, Constant(2.0))
if __name__ == '__main__':
parse_example()