Пример #1
0
    def p_relopexp_extended6(self, p):
        """relopexp : relopexp GE exp"""
        p[0] = NonTerminal()
        p[0].isRel = True
        p[0].place = self.new_temp()
        p[0].trueVal = p[0].place + " = " + str(1)
        p[0].falseVal = p[0].place + " = " + str(0)
        p[0].lastExp = str(p[3].get_value())
        first = self.new_label()
        sec = self.new_label()
        third = self.new_label()
        fourth = self.new_label()
        fifth = self.new_label()
        after = self.new_label()
        x = self.new_label()

        p[0].code = "int " + p[0].place + ";\n"
        p[0].code += p[1].code + p[3].code + "if (" + str(
            p[1].get_value()) + " " + p[2] + " " + str(
                p[3].get_value()) + "){\n\tgoto " + fourth + ";\n}\n"
        p[0].code += sec + ": ;\n" + p[0].falseVal + ";\n"
        p[0].code += third + ": ;\n" + "goto " + after + ";\n"
        p[0].code += fourth + ": ;\n" + p[0].trueVal + ";\n"
        # p[0].code += p[0].place + " = " + str(p[1].get_value()) + " && " + str(p[0].get_value()) + ";\n"
        p[0].code += after + ": ;\n"
        self.labelCount -= 1
Пример #2
0
 def p_paramdec_1(self, p):
     """paramdec : ID COLON type"""
     p[0] = NonTerminal()
     p[0].place = p[1].place
     p[0].code = p[1] + p[2] + p[3].value
     print(p[0].code)
     pass
Пример #3
0
 def p_paramdecslist_extended(self, p):
     """paramdecslist : paramdecslist COMMA paramdec"""
     p[0] = NonTerminal()
     p[0].place = self.new_temp()
     p[0].code = p[1].code + p[2] + p[3].code
     print(p[0].code)
     pass
Пример #4
0
 def p_exp_false(self, p):
     """exp : FALSE"""
     p[0] = NonTerminal()
     p[0].place = self.new_temp()
     p[0].value = 0
     # p[0].false_list = self.make_list(self.nextState)
     # p[0].code = "goto " + p[0].label + "anam;\n"
     pass
Пример #5
0
 def p_const_true(self, p):
     """exp : TRUE"""
     p[0] = NonTerminal()
     p[0].place = self.new_temp()
     p[0].value = 1
     # p[0].true_list = self.make_list(self.nextState)
     # p[0].code = "goto " + p[0].label + "manam;\n"
     pass
Пример #6
0
 def p_exp_expsub(self, p):
     """exp : SUB exp"""
     p[0] = NonTerminal()
     p[0].place = self.new_temp()
     p[0].code = "int " + p[0].place + ";\n"
     p[0].code += p[2].code + p[0].place + " = " + p[1] + str(
         p[2].get_value()) + ";\n"
     pass
Пример #7
0
 def p_exp_mod(self, p):
     """exp : exp MOD exp"""
     p[0] = NonTerminal()
     p[0].place = self.new_temp()
     p[0].code = p[1].code + p[3].code + "int " + p[0].place + " = "
     p[0].code += str(p[1].get_value()) + " " + p[2] + " " + str(
         p[3].get_value()) + ";\n"
     pass
Пример #8
0
 def p_exp_expnot(self, p):
     """exp : NOT exp"""
     p[0] = NonTerminal()
     p[0].place = self.new_temp()
     # p[0].true_list = p[2].false_list
     # p[0].false_list = p[2].true_list
     p[0].code = p[2].code + p[0].place + " = " + "!" + str(
         p[2].get_value()) + ";\n"
     pass
Пример #9
0
    def p_exp_or(self, p):
        """exp : exp OR exp"""
        p[0] = NonTerminal()
        p[0].place = self.new_temp()

        p[0].code = "int " + p[0].place + ";\n"
        p[0].code += p[1].code + p[3].code + p[0].place + " = " + str(
            p[1].get_value()) + " || " + str(p[3].get_value()) + ";\n"
        pass
Пример #10
0
 def p_exp_lrbexprrb(self, p):
     """exp : LRB exp RRB"""
     p[0] = NonTerminal()
     p[0].place = p[2].place
     p[0].code = p[2].code
     pass
Пример #11
0
 def p_exp_relop(self, p):
     """exp : relopexp %prec EXP"""
     p[0] = NonTerminal()
     p[0].code = p[1].code
     p[0].place = p[1].place
Пример #12
0
 def p_paramdecslist_paramdec(self, p):
     """paramdecslist : paramdec"""
     p[0] = NonTerminal()
     p[0].place = self.new_temp()
     p[0].code = p[1].code
     pass