Ejemplo n.º 1
0
 def parse(self):
     """This method takes the inputted equation in string format, tokenizes it and creates an AST"""
     lexer = Lexer(self.eqn_string)
     self.tokens = lexer.obilisk_lex()
     self.vars = deepcopy(lexer.vars)
     if self.vars:
         tokens = TreeBuilder(self.tokens, has_var=True)
     else:
         tokens = TreeBuilder(self.tokens)
     self.tree, self.exprs = tokens.build_tree()
Ejemplo n.º 2
0
from parser.lexer import Lexer
from parser.combinator import TreeBuilder
from parser.interpreter import Interpreter

lexer = Lexer("69+((21/3)^8.2)/(3*cos(45))")
list_of_tokens = lexer.obilisk_lex()
if not lexer.vars:
    tokens = TreeBuilder(list_of_tokens)
    tree, _ = tokens.build_tree()
    inter = Interpreter(tree)
    print(inter.solve())

lexer = Lexer("sqrt(-3)+2")
list_of_tokens = lexer.obilisk_lex()
if not lexer.vars:
    tokens = TreeBuilder(list_of_tokens)
    tree, _ = tokens.build_tree()
    inter = Interpreter(tree)
    print(inter.solve())

lexer = Lexer("2-0.7j*cos(45))")
list_of_tokens = lexer.obilisk_lex()
if not lexer.vars:
    tokens = TreeBuilder(list_of_tokens)
    tree, _ = tokens.build_tree()
    inter = Interpreter(tree)
    print(inter.solve())

lexer = Lexer("69*(((x-1)/(x+2))^8-((x-1)/(x+2))^6)=x+3")
list_of_tokens = lexer.obilisk_lex()
if not lexer.vars: