コード例 #1
0
    def set_idents(self):
        for i in range(len(self.tree.nodes)):
            local_index = 0
            if self.tree.nodes[i].type == "ident_block":
                for j in range(len(self.tree.nodes[i].body)):
                    for k in range(len(self.tree.nodes[i].body[j].values)):
                        self.idents.append(
                            Ident(self.tree.nodes[i].body[j].values[k],
                                  self.tree.nodes[i].body[j]._type,
                                  self.global_index, "g", None, False, None,
                                  None))
                        self.global_index += 1

            elif self.tree.nodes[i].type == "block_dot":
                for j in range(len(self.tree.nodes[i].body)):
                    if self.tree.nodes[i].body[j].classtype == "ident":
                        for k in range(len(self.tree.nodes[i].body[j].values)):
                            self.idents.append(
                                Ident(self.tree.nodes[i].body[j].values[k],
                                      self.tree.nodes[i].body[j]._type,
                                      local_index, "l", None, False, None,
                                      None))
                            local_index += 1

            elif self.tree.nodes[i].type == "func_proc_block":
                for j in range(len(self.tree.nodes[i].body)):
                    self.idents.append(
                        Ident(None, None, None, None, None, True,
                              self.tree.nodes[i].body[j], self.tree.expr_list))
        write = my_ast_nodes.Procedure("Write", None, None)
        read = my_ast_nodes.Function("Read", None, None, "char", None)
        inc = my_ast_nodes.Function("Inc", None, None, "integer", None)
        dec = my_ast_nodes.Function("Dec", None, None, "integer", None)
        abc = my_ast_nodes.Function("Abs", None, None, "integer", None)

        self.idents.append(
            Ident(None, None, None, None, None, True, write,
                  self.tree.expr_list))
        self.idents.append(
            Ident(None, None, None, None, None, True, read,
                  self.tree.expr_list))
        self.idents.append(
            Ident(None, None, None, None, None, True, inc,
                  self.tree.expr_list))
        self.idents.append(
            Ident(None, None, None, None, None, True, dec,
                  self.tree.expr_list))
        self.idents.append(
            Ident(None, None, None, None, None, True, abc,
                  self.tree.expr_list))
コード例 #2
0
def p_function_full_no_param_block(t):
    '''function_full_no_param_block : FUNCTION ident LPAREN RPAREN COLON type SEMICOLON begin expression_list END SEMICOLON'''
    expr_index = str(len(mytree.expr_list))
    mytree.expr_list[expr_index] = my_ast_nodes.Function(
        t[2], None, None, t[6], t[9])
    t[0] = expr_index
コード例 #3
0
def p_function_no_rparam_block(t):
    '''function_norparam_block : FUNCTION ident LPAREN identification_list RPAREN COLON type SEMICOLON begin expression_list END SEMICOLON'''
    expr_index = str(len(mytree.expr_list))
    mytree.expr_list[expr_index] = my_ast_nodes.Function(
        t[2], None, t[4], t[7], t[10])
    t[0] = expr_index