def p_exp_12(self, p):
     """exp : function_call"""
     print("""exp -> function_call""")
     p[0] = Nonterminal()
     p[0] = p[1]
     p[0].code = p[1].code
     p[0].place = p[1].get_value()
     p[0].func = 1
Exemple #2
0
    def p_unary_operation_2(self, p):
        """unary_operation : NOT exp"""
        print("""unary_operation -> NOT exp""")
        p[0] = Nonterminal()
        p[0].place = self.new_temp()
        arg1 = p[1]
        arg2 = p[2].value
        p[0].code = "L" + str(len(
            self.code_list)) + ": " + p[0].place + "=" + arg1 + arg2 + ";"

        self.code_list.append(p[0].code)
        print(self.code_list)
        self.produce_output()
 def p_function_call_1(self, p):
     """function_call : lvalue1 function_call_body"""
     print("""function_call -> lvalue1 function_call_body""")
     p[0] = Nonterminal()
     label = self.new_label()
     p[0].args = p[2].args
     if self.t_counter > -1 :
         for i in range(0, self.t_counter):
             self.FuncVARIABLES.append("TT"+str(i))
     p[0].code = CodeGenerator.storeVariables(self, self.FuncVARIABLES) + CodeGenerator.pushAddress(self,label)
     p[0].code += "// store arguments\n" + p[2].code + CodeGenerator.storeArgs(self,p[2].args)+  "\n goto " + p[1].get_value() + ";\n"
     p[0].place = self.new_temp()
     p[0].code += "// return label:\n" + label + ":\n" + "// load return value\n" + CodeGenerator.popVariable(self,p[0].place) +"\n  //varaiables:" + CodeGenerator.loadVariables(self,self.FuncVARIABLES)
     print(p[0].code)
     print("-------------function call--------------")
Exemple #4
0
    def generate_arithmetic_code(self, p, tmp, code_list):
        print(
            "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
        )
        p[0] = Nonterminal()
        p[0].place = tmp
        if len(p) == 4:
            print(
                "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^4"
            )
            arg1 = ""
            arg2 = ""

            if p[1].place == "":
                arg1 = p[1].value
            else:
                arg1 = p[1].place

            if p[3].place == "":
                arg2 = p[3].value
            else:
                arg2 = p[3].place

            p[0].code = "L" + str(
                len(code_list
                    )) + ": " + p[0].place + "=" + arg1 + p[2] + arg2 + ";"
            print(p[0].code)
            code_list.append(p[0].code)
            print(code_list)

        elif len(p) == 3:
            print(
                "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^3"
            )
            arg1 = ""
            arg2 = ""

            if p[2].place == "":
                arg1 = p[2].value
            else:
                arg1 = p[2].place

            p[0].code = "L" + str(
                len(code_list)) + ": " + p[0].place + "=" + p[1] + arg1 + ";"
            print(p[0].code)
            code_list.append(p[0].code)
            print(code_list)
 def p_exp_10(self, p):
     """exp : unary_operation"""
     print("""exp -> unary_operation""")
     p[0] = Nonterminal()
     p[0].code = p[1].code
     p[0].place = p[1].get_value()
 def p_exp_7(self, p):
     """exp : logical_operation"""
     print("""exp -> logical_operation""")
     p[0] = Nonterminal()
     p[0].code = p[1].code
     p[0].place = p[1].get_value()
 def p_exp_6(self, p):
     """exp : binary_operation %prec BIOP"""
     print("""exp -> binary_operation""")
     p[0] = Nonterminal()
     p[0].code = p[1].code
     p[0].place = p[1].get_value()
 def p_exp_5(self, p):
     """exp : lvalue"""
     print("""exp -> lvalue""")
     p[0] = Nonterminal()
     p[0].place = p[1].place
     p[0].ifexp = "if ( " + p[1].place + " ) goto " + self.TRUE_LABEL + ";\n" + "goto " + self.FALSE_LABEL + ";\n\n"
 def p_lval1(self, p):
     """lvalue1 : ID"""
     print("""lvalue1 -> ID""")
     p[0] = Nonterminal()
     p[0].place = p[1]
 def p_lvalue_2(self, p):
     """lvalue : lvalue2 %prec LVAL"""
     p[0] = Nonterminal()
     p[0].code = p[1].code
     p[0].place = p[1].place
     print("""lvalue -> lvalue2""")
 def p_exp_11(self, p):
     """exp : LP exp RP"""
     print("""exp -> LP exp RP""")
     p[0] = Nonterminal()
     p[0].place = p[2].place
     p[0].code = p[2].code