Esempio n. 1
0
 def evaluate(self):
     left = self.left.evaluate()
     right = self.right.evaluate()
     if not isinstance(left, int):
         raise SemanticError()
     if not isinstance(right, int):
         raise SemanticError()
     return left * right
Esempio n. 2
0
 def evaluate(self):
     left = self.left.evaluate()
     right = self.right.evaluate()
     if type(left) != type(right):
         raise SemanticError.SemanticError()
     elif not isinstance(left, int) and not isinstance(left, str):
         raise SemanticError.SemanticError()
     return left + right
Esempio n. 3
0
 def execute(self):
     left = self.left.location()
     right = self.right.evaluate()
     if not isinstance(left, types.FunctionType):
         raise SemanticError.SemanticError()
     if not isinstance(right, int) and not isinstance(
             right, str) and not isinstance(right, list):
         raise SemanticError.SemanticError()
     left(right)
Esempio n. 4
0
 def evaluate(self):
     left = self.list.evaluate()
     right = self.indeces.evaluate()
     if not isinstance(left, str) and not isinstance(left, list):
         raise SemanticError()
     if not isinstance(right, list):
         raise SemanticError()
     for element in right:
         if not isinstance(element, int):
             raise SemanticError.SemanticError()
         if len(left) < element + 1:
             raise SemanticError.SemanticError()
         left = left[element]
     return left
Esempio n. 5
0
    def evaluate(self):
        for stack in reversed(glob.variables):
            if self.name in stack.keys():
                return stack[self.name]

        print(self.name)
        raise SemanticError()
Esempio n. 6
0
 def evaluate(self):
     expression = self.expression.evaluate()
     if (isinstance(expression, int)):
         if (expression != 0):
             return True
         else:
             return False
     raise SemanticError.SemanticError()
Esempio n. 7
0
 def execute(self, arguments=[]):
     function = glob.variables[0][self.name]
     if (len(arguments) != len(function["arguments"])):
         raise SemanticError()
     argumentsDict = {}
     for index, name in enumerate(function['arguments']):
         argumentsDict[name] = arguments[index]
     # print(argumentsDict)
     # print(function["statements"])
     function["statements"].execute(argumentsDict)
Esempio n. 8
0
 def setValue(self, array, index, value):
     if not isinstance(index[0], int):
         raise SemanticError.SemanticError()
     if len(index) == 1:
         array[index[0]] = value
         return array
     else:
         temp = array[index[0]]
         temp = self.setValue(temp, index[1:], value)
         array[index[0]] = temp
         return array
Esempio n. 9
0
 def location(self):
     """
     Evaluates this node for a location.
     """
     print("2")
     raise SemanticError.SemanticError()
Esempio n. 10
0
 def execute(self):
     """
     Executes this node.
     """
     raise SemanticError.SemanticError()