Esempio n. 1
0
 def test_no_tokens_should_return_empty_root_node(self):
     node = build_tree([])
     assert isinstance(node, RootNode)
     assert node.eval() is None
Esempio n. 2
0
 def test_nested_expression(self):
     lexer = Lexer()
     tokens = lexer.analyze('(+ 1 (+ 1 (+ 1 1)))')
     node = build_tree(tokens)
     assert 4 == node.eval()
Esempio n. 3
0
 def test_empty_expression(self):
     lexer = Lexer()
     tokens = lexer.analyze('()')
     node = build_tree(tokens)
     assert node.eval() is None
Esempio n. 4
0
 def test_simple_expression(self):
     lexer = Lexer()
     tokens = lexer.analyze('(+ 1 1)')
     node = build_tree(tokens)
     assert 2 == node.eval()
Esempio n. 5
0
def eval(expr):
    lexer = Lexer()
    node = build_tree(lexer.analyze(expr))
    return node.eval()