예제 #1
0
def popAssign():
    POperSize = len(POper)
    if POperSize > 0:
        if POper[POperSize - 1] == '=':
            right_operand = PilaO.pop()
            right_type = PTypes.pop()
            right_value = AVAIL.pop()
            left_operand = PilaO.pop()
            left_type = PTypes.pop()
            AVAIL.pop()
            operator = POper.pop()
            result_type = semantic(left_type, right_type, operator)
            if (result_type != 'error'):
                if right_value is not None:
                    result = right_value
                    quadr = quadruple(len(Quad), operator, right_operand, None,
                                      left_operand)
                    Quad.append(quadr)
                else:
                    print("ERROR: Variable sin valor asignado.")
                    sys.exit()
            else:
                print("ERROR: Type mismatch.")
                sys.exit()
    return result
예제 #2
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()
예제 #3
0
def assignFunc(id):
    tipoFunc = simbolos[id].type_data
    POperSize = len(POper)
    if POperSize > 0:
        if POper[POperSize - 1] == '=':
            PilaO.pop()
            PTypes.pop()
            AVAIL.pop()
            result = PilaO.pop()
            type = PTypes.pop()
            AVAIL.pop()
            operator = POper.pop()
            result_type = semantic(type, tipoFunc, operator)
            if result_type != 'error':
                quadr = quadruple(len(Quad), '=', 150000, None, result)
                Quad.append(quadr)
            else:
                print('ERROR: Type mismatch.')
                sys.exit()