Esempio n. 1
0
 def createFunctionDefinition(self, def_token, var_token, params, val_node):
     lamToken = LexToken()
     lamToken.value = 'lambda'
     lamToken.type = 'LAMBDA'
     return LetNode(def_token, [
         VariableNode(var_token),
         LambdaNode(lamToken, [Node(None, None, nodes(params)), val_node]),
     ])
Esempio n. 2
0
from Node import EquationNode, VariableNode

if __name__ == '__main__':
    A = VariableNode("A", 3)
    B = VariableNode("B", None)
    Fx = EquationNode("Fx")
    Fx.construct_tree([A, B, "*", 2, "-"]) # 3B*2-
    #print(equation1.print_in_order(equation1.root)) # 
    #print(equation1.calculate_in_order(equation1.root))
    try:
        Fx.calc_value()
        print(C.data)
    except: 
        pass
    Gx = EquationNode("Gx")
    Gx.construct_tree([A, 2, "/"])
    C = VariableNode("C", None, [Gx])
    C.calc_value()
    print(C.data)
Esempio n. 3
0
 def createString(self, var_token):
     return VariableNode(var_token)
Esempio n. 4
0
 def createBoolean(self, var_token):
     return VariableNode(var_token)
Esempio n. 5
0
 def createInteger(self, var_token):
     return VariableNode(var_token)
Esempio n. 6
0
    def createVariable(self, var_token):
        if var_token.value in self.functionMapping:
            var_token.value = self.functionMapping[var_token.value]

        return VariableNode(var_token)
Esempio n. 7
0
def nodes(tokens):
    return list(map(lambda x: VariableNode(x), tokens))
Esempio n. 8
0
 def createLambda(self, lambda_token, params, val):
     if len(params) > 0:
         return LambdaNode(lambda_token,
                           [Node(None, None, nodes(params)), val])
     else:
         return VariableNode(lambda_token, [val])
Esempio n. 9
0
 def createVariableDefinition(self, def_token, var_token, val_node):
     return LetNode(def_token, [VariableNode(var_token), val_node])