コード例 #1
0
ファイル: EXPONENTE.py プロジェクト: sandymerida/tytus
 def getValueAbstract(self, entorno: Tabla_de_simbolos, arbol: Arbol):
     izquierdo: Valor = self.izq.getValueAbstract(entorno, arbol)  # <-- tiene un temporal
     derecho: Valor = self.der.getValueAbstract(entorno, arbol)  # <-- tiene un temporal
     if self.analizar_semanticamente(entorno, arbol) == 0:
         newVal: Valor = Valor(TIPO.ENTERO, int(str(izquierdo.data)) / int(str(derecho.data)))
         return newVal
     elif self.analizar_semanticamente(entorno, arbol) == 1:
         newVal: Valor = Valor(TIPO.DECIMAL, float(str(izquierdo.data)) / float(str(derecho.data)))
         return newVal
     elif self.analizar_semanticamente(entorno, arbol) == 2:
         #newVal: Valor = Valor(TIPO.CADENA, str(str(izquierdo.data)) / str(derecho.data))
         # ERROR SEMANTICO DE TIPOS NO SE PUEDEN OPERAR TIPOS CADENA
         return None
コード例 #2
0
ファイル: SUMA.py プロジェクト: sandymerida/tytus
    def getValueAbstract(self, entorno: Tabla_de_simbolos, arbol:Arbol):
        print('A1: ' + str(self.izq.getString(entorno, arbol)))
        print('A2: ' + str(self.der.getString(entorno, arbol)))
        print(self.esNecesarioOptimizar(entorno, arbol))
        self.hayQueOptimizar = self.esNecesarioOptimizar(entorno, arbol)

        izquierdo: Valor = self.izq.getValueAbstract(entorno, arbol) # <-- tiene un temporal
        derecho: Valor = self.der.getValueAbstract(entorno, arbol) # <-- tiene un temporal
        if self.analizar_semanticamente(entorno, arbol) == 0:
            newVal: Valor = Valor(TIPO.ENTERO, int(str(izquierdo.data)) + int(str(derecho.data)))
            return newVal
        elif self.analizar_semanticamente(entorno, arbol) == 1:
            newVal: Valor = Valor(TIPO.DECIMAL, float(str(izquierdo.data)) + float(str(derecho.data)))
            return newVal
        elif self.analizar_semanticamente(entorno, arbol) == 2:
            newVal: Valor = Valor(TIPO.CADENA, str(str(izquierdo.data)) + str(derecho.data))
            return newVal
コード例 #3
0
ファイル: argumento.py プロジェクト: sandymerida/tytus
 def traducir(self, entorno: Tabla_de_simbolos, arbol: Arbol):
     tmp = arbol.getTemp()
     arbol.addC3D(tmp + " = " + str(self.identificador))
     val_exp: Valor = Valor(TIPO.CADENA, 'NULL')
     simbol: Simbolo = Simbolo(str(self.identificador), val_exp.tipo,
                               val_exp)
     simbol.setTemp(str(tmp))
     entorno.insertar_variable(simbol)
コード例 #4
0
 def getValueAbstract(self, entorno: Tabla_de_simbolos, arbol: Arbol):
     value: Valor = Valor(2, self.data)
     return value
コード例 #5
0
 def execute(self, entorno: Tabla_de_simbolos, arbol: Arbol):
     value: Valor = Valor(TIPO.ENTERO, self.data)
     return value
コード例 #6
0
 def NuevoAmbito(self):
     nuevoAmito = [Simbolo("VACIO", 2, Valor(2, "VACIO"))]
     self.Pila_de_tablas.append(nuevoAmito)
コード例 #7
0
    def traducir(self, entorno: Tabla_de_simbolos, arbol:Arbol):
        if self.exp != None:

            expres = self.exp.traducir(entorno, arbol)

            # modulo de insercion a TS
            try:
                val_exp = self.exp.getValueAbstract(entorno, arbol)
                simbol: Simbolo = Simbolo(str(self.identificador), val_exp.tipo, val_exp)
                if str(expres[1]) == '8-12' or str(expres[1]) == '9-13' or str(expres[1]) == '10-14' or \
                        str(expres[1]) == '11-15' or str(expres[1]) == '16' or str(expres[1]) == '17' \
                        or str(expres[1]) == '18':
                    simbol.setTemp(str(expres[0]))
                else:
                    simbol.setTemp(str(expres))
                entorno.insertar_variable(simbol)
            except:
                val_exp = Valor(2, 'DML')
                simbol: Simbolo = Simbolo(str(self.identificador), val_exp.tipo, val_exp)
                if str(expres[1]) == '8-12' or str(expres[1]) == '9-13' or str(expres[1]) == '10-14' or \
                        str(expres[1]) == '11-15' or str(expres[1]) == '16' or str(expres[1]) == '17' \
                        or str(expres[1]) == '18':
                    simbol.setTemp(str(expres[0]))
                else:
                    simbol.setTemp(str(expres))
                entorno.insertar_variable(simbol)



            # -->
            # Modulo de rporteria:
            reportero = ReporteTS(str(self.identificador), str(self.identificador), 'Variable', 'N/A', str(self.linea), str(self.columna))
            arbol.ReporteTS.append(reportero)
            # -->


            # ----------------------------------------------------------------------------------

            # modulo de insercion a TS optimizado
            try:
                tmp = str(self.identificador)
                if str(expres[1]) == '8-12':
                    # Regla no. 9 -----------------------------
                    original = str(tmp) + ' = ' + str(expres[0]) + ' + 0'
                    optimizado = str(tmp) + ' = ' + str(expres[0])
                    reportero = ReporteOptimizacion('Regla 12', original, optimizado, str(self.linea),
                                                    str(self.columna))
                    arbol.ReporteOptimizacion.append(reportero)
                    # -----------------------------------------------------------------------------
                    return
                elif str(expres[1]) == '9-13':
                    # Regla no. 9 -----------------------------
                    original = str(tmp) + ' = ' + str(expres[0]) + ' - 0'
                    optimizado = str(tmp) + ' = ' + str(expres[0])
                    reportero = ReporteOptimizacion('Regla 13', original, optimizado, str(self.linea),
                                                    str(self.columna))
                    arbol.ReporteOptimizacion.append(reportero)
                    # -----------------------------------------------------------------------------
                    return
                elif str(expres[1]) == '10-14':
                    # Regla no. 9 -----------------------------
                    original = str(tmp) + ' = ' + str(expres[0]) + ' * 1'
                    optimizado = str(tmp) + ' = ' + str(expres[0])
                    reportero = ReporteOptimizacion('Regla 14', original, optimizado, str(self.linea),
                                                    str(self.columna))
                    arbol.ReporteOptimizacion.append(reportero)
                    # -----------------------------------------------------------------------------
                    return
                elif str(expres[1]) == '11-15':
                    # Regla no. 9 -----------------------------
                    original = str(tmp) + ' = ' + str(expres[0]) + ' / 1'
                    optimizado = str(tmp) + ' = ' + str(expres[0])
                    reportero = ReporteOptimizacion('Regla 15', original, optimizado, str(self.linea),
                                                    str(self.columna))
                    arbol.ReporteOptimizacion.append(reportero)
                    # -----------------------------------------------------------------------------
                    return
                elif str(expres[1]) == '16':
                    # Regla no. 16 -----------------------------
                    original = str(tmp) + ' = ' + str(expres[0]) + ' * 2'
                    optimizado = str(tmp) + ' = ' + str(expres[0]) + ' + ' + str(expres[0])
                    reportero = ReporteOptimizacion('Regla 16', original, optimizado, str(self.linea),
                                                    str(self.columna))
                    arbol.ReporteOptimizacion.append(reportero)
                    # -----------------------------------------------------------------------------
                    return
                elif str(expres[1]) == '17':
                    # Regla no. 17 -----------------------------
                    original = str(tmp) + ' = ' + str(expres[0]) + ' * 0'
                    optimizado = str(tmp) + ' = 0'
                    reportero = ReporteOptimizacion('Regla 17', original, optimizado, str(self.linea),
                                                    str(self.columna))
                    arbol.ReporteOptimizacion.append(reportero)
                    # -----------------------------------------------------------------------------
                    return
                elif str(expres[1]) == '18':
                    # Regla no. 18 -----------------------------
                    original = str(tmp) + ' = 0 / ' + str(expres[0])
                    optimizado = str(tmp) + ' = 0'
                    reportero = ReporteOptimizacion('Regla 18', original, optimizado, str(self.linea),
                                                    str(self.columna))
                    arbol.ReporteOptimizacion.append(reportero)
                    # -----------------------------------------------------------------------------
                    return
            except:
                pass
            # ----------------------------------------------------------------------------------




        else:
            tmp = arbol.getTemp()
            arbol.addC3D(tmp + " = '' #" + str(self.identificador))
            val_exp:Valor = Valor(2, 'NULL')
            simbol:Simbolo = Simbolo(str(self.identificador), val_exp.tipo, val_exp)
            simbol.setTemp(str(tmp))
            entorno.insertar_variable(simbol)

            # -->
            # Modulo de rporteria:
            reportero = ReporteTS(str(self.identificador), str(self.identificador), 'Variable', 'N/A', str(self.linea),
                                  str(self.columna))
            arbol.ReporteTS.append(reportero)
            # -->

        #self.analizar_semanticamente(entorno, arbol)
        return