Skip to content
/ pyast Public

A python implementation of an abstract syntax tree.

License

Notifications You must be signed in to change notification settings

mtresnik/pyast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyast

License version PRs Welcome


A python implementation of an abstract syntax tree.

Sample Code

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()

About

A python implementation of an abstract syntax tree.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages