Exemplo n.º 1
0
    def visit(self, node, scope: InterScope):
        lvalue = self.visit(node.lvalue, scope)
        rvalue = self.visit(node.rvalue, scope)

        result = Instance('Int', self.type_graph.types_nodes['Int'].begin)
        result.info['value'] = lvalue.info['value'] + rvalue.info['value']

        return result
Exemplo n.º 2
0
    def visit(self, node: our_ast.IsVoidNode, scope: InterScope):
        instance = self.visit(node.expr, scope)
        result = Instance('Bool', self.type_graph.types_nodes['Bool'].begin)
        if instance.begin:
            result.info['value'] = False
            return result

        result.info['value'] = True
        return result
Exemplo n.º 3
0
    def _do_substr(self, tipe: Instance, index: Instance, length: Instance):

        instance = Instance('String',
                            self.type_graph.types_nodes['String'].begin)
        point = index.info['value']
        long = length.info['value']
        substr = tipe.info['value'][point:(point + long)]
        instance.info['value'] = substr

        return instance
Exemplo n.º 4
0
    def visit(self, node: our_ast.AssigNode, scope: InterScope):
        value: Instance
        value = self.visit(node.value, scope)
        begin = self.type_graph.types_nodes[value.tipe].begin

        if value.tipe == 'Int':
            instance = Instance('Int', begin)
            instance.info['value'] = value.info['value']
            value = instance

        elif value.tipe == 'String':
            instance = Instance('String', begin)
            instance.info['value'] = value.info['value']
            value = instance

        elif value.tipe == 'Bool':
            instance = Instance('Bool', begin)
            instance.info['value'] = value.info['value']
            value = instance

        if node.name in scope.locals:
            scope.locals[node.name][1] = value

        else:
            scope.locals['self'][1].info[node.name] = value
        return value
Exemplo n.º 5
0
    def visit(self, node, scope: InterScope):
        lvalue = self.visit(node.lvalue, scope)
        rvalue = self.visit(node.rvalue, scope)

        result = Instance('Bool', self.type_graph.types_nodes['Bool'].begin)
        if lvalue.info['value'] < rvalue.info['value']:
            result.info['value'] = True
            return result

        result.info['value'] = False
        return result
Exemplo n.º 6
0
    def visit(self, node: our_ast.EqualNode, scope: InterScope):
        lvalue = self.visit(node.lvalue, scope)
        rvalue = self.visit(node.rvalue, scope)

        result = Instance('Bool', self.type_graph.types_nodes['Bool'].begin)

        if (lvalue.tipe in (
                'String',
                'Bool',
                'Int',
        ) and lvalue.info['value']
                == rvalue.info['value']) or lvalue == rvalue:
            result.info['value'] = True
        else:
            result.info['value'] = False

        return result
Exemplo n.º 7
0
    def visit(self, node: our_ast.NewNode, scope: InterScope):
        instance = Instance(node.type,
                            self.type_graph.types_nodes[node.type].begin)
        if node.type == 'String':
            instance.info['value'] = ''
            return instance
        if node.type == 'Int':
            instance.info['value'] = 0
            return instance
        if node.type == 'Bool':
            instance.info['value'] = False
            return instance

        new_scope = InterScope()
        new_scope.locals['self'] = [node.type, instance]

        self._build(node.type, new_scope)

        return instance
Exemplo n.º 8
0
    def visit(self, node: our_ast.AttrNode, scope: InterScope):
        if node.value:
            return self.visit(node.value, scope)

        instance = Instance(node.type,
                            self.type_graph.types_nodes[node.type].begin)
        if node.type == 'String':
            instance.info['value'] = ''
            return instance

        if node.type == 'Bool':
            instance.info['value'] = False
            return instance

        if node.type == 'Int':
            instance.info['value'] = 0
            return instance

        return Instance(node.type)
Exemplo n.º 9
0
 def visit(self, node: our_ast.BoolNode, scope: InterScope):
     begin = self.type_graph.types_nodes['Bool'].begin
     instance = Instance('Bool', begin)
     instance.info['value'] = node.value
     return instance
Exemplo n.º 10
0
 def _do_in_int(self):
     number = input()
     instance = Instance('Int', self.type_graph.types_nodes['Int'].begin)
     instance.info['value'] = int(number)
     return instance
Exemplo n.º 11
0
 def _do_in_string(self):
     number = input()
     instance = Instance('String',
                         self.type_graph.types_nodes['String'].begin)
     instance.info['value'] = number
     return instance
Exemplo n.º 12
0
    def _do_concat(self, tipe1: Instance, tipe2: Instance):

        instance = Instance('String',
                            self.type_graph.types_nodes['String'].begin)
        instance.info['value'] = tipe1.info['value'] + tipe2.info['value']
        return instance
Exemplo n.º 13
0
 def _do_type_name(self, tipe: Instance):
     instance = Instance('String',
                         self.type_graph.types_nodes['String'].begin)
     instance.info['value'] = tipe.tipe
     return instance
Exemplo n.º 14
0
 def _do_length(self, tipe: Instance):
     instance = Instance('Int', self.type_graph.types_nodes['Int'].begin)
     instance.info['value'] = len(tipe.info['value'])
     return instance
Exemplo n.º 15
0
 def visit(self, node, scope: InterScope):
     begin = self.type_graph.types_nodes['Int'].begin
     instance = Instance('Int', begin)
     instance.info['value'] = node.value
     return instance
Exemplo n.º 16
0
    def visit(self, node: our_ast.WhileNode, scope: InterScope):

        while self.visit(node.condition, scope).info['value']:
            self.visit(node.body, scope)

        return Instance('Object', 0)
Exemplo n.º 17
0
 def visit(self, node: our_ast.NotNode, scope: InterScope):
     value = self.visit(node.value, scope)
     result = Instance('Bool', self.type_graph.types_nodes['Bool'].begin)
     result.info['value'] = not value.info['value']
     return result
Exemplo n.º 18
0
 def visit(self, node: our_ast.NegationNode, scope: InterScope):
     value = self.visit(node.value, scope)
     result = Instance('Int', self.type_graph.types_nodes['Int'].begin)
     result.info['value'] = (-1) * value.info['value']
     return result