Example #1
0
def generarListaDeclaraciones(instruccion, ts):
    global cadenaTraduccion
    tipo = instruccion.tipo
    for declaracion in instruccion.declaraciones:
        if declaracion.exp is None:
            temporal = generarTemporalT()
            simbolo = TS.Simbolo(declaracion.id, getTipo(tipo), getEmpty(tipo), temporal)
            ts.agregar(simbolo)
            cadenaTraduccion += '\t\n'
            cadenaTraduccion += '\t' + str(temporal) + " = " + str(getEmpty(tipo)) + ''
        else:
            temporal1 = generarExpresion(declaracion.exp, ts)
            temporal2 = generarTemporalT()
            simbolo = TS.Simbolo(declaracion.id, getTipo(tipo), temporal1, temporal2)
            ts.agregar(simbolo)
            cadenaTraduccion += '\t\n'
            cadenaTraduccion += '\t' + str(temporal2) + " = " + str(temporal1) + ''
Example #2
0
def generarAsignacion(instruccion, ts):
    global cadenaTraduccion
    temporal1 = generarExpresion(instruccion.exp, ts)
    simboloTemporal = ts.obtener(instruccion.id)
    temporal2 = simboloTemporal.temporal
    if temporal1 != temporal2:
        simbolo = TS.Simbolo(instruccion.id, simboloTemporal.tipo, temporal1, temporal2)
        ts.agregar(simbolo)
        cadenaTraduccion += '\t\n'
        cadenaTraduccion += '\t' + str(temporal2) + " = " + str(temporal1) + ""
Example #3
0
def agregarFunciones():
    global tf, cadenaTraduccion, tf2
    for funcion in tf2.funciones:
        instruccion = tf2.obtener(funcion)
        tsTemp = TS.TablaDeSimbolos()
        if instruccion.parametros[0] != None:
            contador = 0
            for parametro in instruccion.parametros:
                simbolo = TS.Simbolo(parametro.id, parametro.tipo, getEmpty(parametro.tipo), instruccion.temporales[contador])
                tsTemp.agregar(simbolo)
                contador = contador + 1
        cadenaTraduccion += '\t\n'
        cadenaTraduccion += '\t\n'
        cadenaTraduccion += '\t' + 'label. ' + str(instruccion.id)
        generarPrincipal(instruccion.instrucciones, tsTemp)
        cadenaTraduccion += '\t\n'
        cadenaTraduccion += '\tgoto. retorno'