def generate3d(self, environment, instanciaAux): try: name,tipo,value = SymbolTable.search_symbol(self.identificador) if isinstance(self.expresion, F1): newTemp = self.expresion.generate3d(environment,instanciaAux) instanciaAux.addToCode(f'\t{self.identificador} = {newTemp}') if tipo == TYPE.NUMBER: value = 1 elif tipo == TYPE.BOOLEAN: value = False else: value = "" SymbolTable.add_symbol(self.identificador,tipo,value,self.row,self.column,None) return try: TypeV=self.expresion.execute(environment).type except: instruction.semanticErrors.append( ( "ERROR: 42P18: tipo de dato indeterminado en '%s'" %self.identificador,self.row) ) return None if TypeV != tipo: instruction.semanticErrors.append( ( "ERROR: 42804: discorcondancia entre los tipos de datos en '%s'" %self.identificador,self.row) ) try: if not isinstance(self.expresion, Identifiers): value=self.expresion.value except: pass if isinstance(self.expresion, Primitive): SymbolTable.add_symbol(self.identificador,TypeV,value,self.row,self.column,None) instanciaAux.addToCode(f'\t{self.identificador} = {self.expresion.value}') elif not self.classType == None: if isinstance(self.expresion,FunctionCall): callValue=self.expresion.execute(environment).value SymbolTable.add_symbol(self.identificador,TypeV,callValue,self.row,self.column,None) instanciaAux.addToCode(f'\t{self.identificador} = {callValue}') else: newTemp=self.expresion.generate3d(environment,instanciaAux) callValue=self.expresion.execute(environment).value if isinstance(self.expresion, Identifiers): callValue=self.expresion.name SymbolTable.add_symbol(self.identificador,TypeV,callValue,self.row,self.column,None) instanciaAux.addToCode(f'\t{self.identificador} = {newTemp}') except: instruction.semanticErrors.append( ( "ERROR: la variable '%s' no se ha declarado" %self.identificador,self.row) )
def generate3d(self, environment, instanciaAux): #Agregacion a la tabla for (nombre, tipo) in self.params: valores = defaultValues(tipo[0]) SymbolTable.add_symbol(nombre, valores[0], valores[1], 0, 0, None) header = f'\n@with_goto\ndef {self.name}(' # solo le quite la f :v for param in range(len(self.params)): header += self.params[param][0] if param != len(self.params) - 1: header += "," header += '):' eFinal = instanciaAux.getNewLabel() newEnv = Environment(environment) newEnv.addVar('eFinal', eFinal, 'Etiqueta', self.row, self.column) instanciaAux.addToCode(header) self.block.generate3d(newEnv, instanciaAux) SymbolTable.symbolTable.clear() instanciaAux.addToCode(f'\tlabel .{eFinal}')
def generate3d(self,environment,instanciaAux): tipo=self.tipo[0].casefold() if not isinstance(self.valor,F1): try: TypeV = None if type(self.valor) in (str, bool, float, int): self.valor = None if self.valor != None: TypeV=self.valor.execute(environment).type print('El tipo es: '+TypeV.name) except: instruction.semanticErrors.append( ( "ERROR: 42P18: tipo de dato indeterminado en '%s'" %self.nombre,self.row) ) return None try: if not isinstance(self.valor, Identifiers): self.valor=self.valor.value except: pass try: if 'primitive'==self.classType or self.valor == None: if self.valor == None: if 'integer' in tipo or 'bigint' in tipo: self.valor=0 TypeV = TYPE.NUMBER elif 'numeric' in tipo or 'double precision' in tipo or 'money' in tipo or 'decimal' in tipo: self.valor=0.0 TypeV = TYPE.NUMBER elif 'text' in tipo or 'varchar' in tipo or 'char' in tipo or 'varying' in tipo: self.valor='\'\'' TypeV = TYPE.STRING elif 'boolean' in tipo: self.valor=False TypeV = TYPE.BOOLEAN elif 'timestamp' in tipo: self.valor=datetime.now().strftime("%Y-%m-%d %H:%M:%S") TypeV = TYPE.TIMESTAMP elif 'date' in tipo: self.valor=datetime.now().strftime("%Y-%m-%d") TypeV = TYPE.DATE elif 'time' in tipo: self.valor=datetime.now().strftime("%H:%M:%S") TypeV = TYPE.TIME else: pass else: if 'text' in tipo or 'varchar' in tipo or 'char' in tipo or 'varying' in tipo: if TypeV==TYPE.STRING: self.valor='\''+self.valor+'\'' else: instruction.semanticErrors.append( ( "ERROR: 42804: discorcondancia entre los tipos de datos en '%s'" %self.nombre,self.row) ) print(1) return None #return error de tipo elif 'timestamp' in tipo: if TypeV==TYPE.TIMESTAMP: self.valor='\''+datetime.now().strftime("%Y-%m-%d %H:%M:%S")+'\'' else: instruction.semanticErrors.append( ( "ERROR: 42804: discorcondancia entre los tipos de datos en '%s'" %self.nombre,self.row) ) print(2) return None elif 'date' in tipo: if TypeV==TYPE.DATE: self.valor='\''+datetime.now().strftime("%Y-%m-%d")+'\'' else: instruction.semanticErrors.append( ( "ERROR: 42804: discorcondancia entre los tipos de datos en '%s'" %self.nombre,self.row) ) print(3) return None elif 'time' in tipo: if TypeV==TYPE.TIME: self.valor='\''+datetime.now().strftime("%H:%M:%S")+'\'' else: instruction.semanticErrors.append( ( "ERROR: 42804: discorcondancia entre los tipos de datos en '%s'" %self.nombre,self.row) ) print(4) return None elif 'integer' in tipo or 'bigint' in tipo: if TypeV==TYPE.NUMBER: if not type(self.valor)==float: self.valor=self.valor else: instruction.semanticErrors.append( ( "ERROR: 42804: discorcondancia entre los tipos de datos en '%s'" %self.nombre,self.row) ) print(5) return None else: instruction.semanticErrors.append( ( "ERROR: 42804: discorcondancia entre los tipos de datos en '%s'" %self.nombre,self.row) ) print(6) return None elif 'numeric' in tipo or 'double precision' in tipo or 'money' in tipo or 'decimal' in tipo: if type(self.valor)==float: self.valor=self.valor else: instruction.semanticErrors.append( ( "ERROR: 42804: discorcondancia entre los tipos de datos en '%s'" %self.nombre,self.row) ) print(7) return None elif 'boolean' in tipo: if TypeV==TYPE.BOOLEAN: self.valor=self.valor else: instruction.semanticErrors.append( ( "ERROR: 42804: discorcondancia entre los tipos de datos en '%s'" %self.nombre,self.row) ) print(8) return None else: instruction.semanticErrors.append( "ERROR: 42P18: tipo de dato indeterminado en '%s'" %self.nombre ) return None SymbolTable.add_symbol(self.nombre,TypeV,self.valor,self.row,self.column,None) instanciaAux.addToCode(f'\t{self.nombre} = {self.valor}') elif not self.classType == None: if isinstance(self.valor,FunctionCall): callValue=self.valor.execute(environment).value SymbolTable.add_symbol(self.nombre,TypeV,callValue,self.row,self.column,None) instanciaAux.addToCode(f'\t{self.nombre} = {callValue}') elif isinstance(self.valor,F1): callTemp=self.valor.generate3d(environment,instanciaAux) SymbolTable.add_symbol(self.nombre,'Query',callTemp,self.row,self.column,None) instanciaAux.addToCode(f'\t{self.nombre} = {callTemp}') else: newTemp=self.valor.generate3d(environment,instanciaAux) callValue=self.valor.execute(environment).value if isinstance(self.valor, Identifiers): callValue=self.valor.name SymbolTable.add_symbol(self.nombre,TypeV,callValue,self.row,self.column,None) instanciaAux.addToCode(f'\t{self.nombre} = {newTemp}') except Exception() as e: instruction.semanticErrors.append( ( "ERROR: 42804: discorcondancia entre los tipos de datos en '%s'" %self.nombre,self.row) ) print(9, e) return None