Esempio n. 1
0
def popRelop(main):
    POperSize = len(POper)
    if POperSize > 0:
        if (POper[POperSize - 1] == '>' or POper[POperSize - 1] == '>='
                or POper[POperSize - 1] == '<' or POper[POperSize - 1] == '<='
                or POper[POperSize - 1] == '=='
                or POper[POperSize - 1] == '<>'):
            right_operand = PilaO.pop()
            right_type = PTypes.pop()
            right_value = AVAIL.pop()
            left_operand = PilaO.pop()
            left_type = PTypes.pop()
            left_value = AVAIL.pop()
            operator = POper.pop()
            result_type = semantic(left_type, right_type, operator)
            if (result_type != 'error'):
                if left_value is not None and right_value is not None:
                    if (operator == '>'):
                        result = left_value > right_value
                    elif (operator == '>='):
                        result = left_value >= right_value
                    elif (operator == '<'):
                        result = left_value < right_value
                    elif (operator == '<='):
                        result = left_value <= right_value
                    elif (operator == '=='):
                        result = left_value == right_value
                    elif (operator == '<>'):
                        result = left_value != right_value
                    if main:
                        dir = memo.getVirtualMainTemp(result_type)
                        memo.updateMainTempInMemory(result, dir, result_type)
                    else:
                        dir = memo.getVirtualTemp(result_type)
                        memo.updateTempInMemory(result, dir, result_type)
                    quadr = quadruple(len(Quad), operator, left_operand,
                                      right_operand, dir)
                    Quad.append(quadr)
                    PilaO.append(dir)
                    AVAIL.append(result)
                    PTypes.append(result_type)
                else:
                    print("ERROR: Variable sin valor asignado.")
                    sys.exit()
            else:
                print("ERROR: Type mismatch.")
                sys.exit()
Esempio n. 2
0
def arregloCinco(main, base, tipo):
    aux1 = PilaO.pop()
    if main:
        t = memo.getVirtualMainTemp('int')
    else:
        t = memo.getVirtualTemp('int')
    quadr = quadruple(len(Quad), '+', aux1, 0, t)
    Quad.append(quadr)
    if main:
        dir = memo.getVirtualMainTemp('int')
        memo.updateMainTempInMemory(aux1, dir, 'int')
    else:
        dir = memo.getVirtualTemp('int')
        memo.updateTempInMemory(aux1, dir, 'int')
    quadr = quadruple(len(Quad), '+', t, base, dir)
    Quad.append(quadr)
    PilaO.append('(' + str(dir) + ')')
    PTypes.append(tipo)
    POper.pop()