def p_tipo_datos1(t): '''tipo : DATE ''' t[0] = Tipo(Tipo_Dato.DATE)
def __init__(self, lista, strGram, linea, columna): Instruccion.__init__(self, Tipo(Tipo_Dato.QUERY), linea, columna, strGram) self.lista = lista
def __init__(self, id, linea, columna): self.id = id Instruccion.__init__(self, Tipo(Tipo_Dato.ID), linea, columna)
def analizar(self, tabla, arbol): super().analizar(tabla, arbol) # Operación con dos operadores if (self.opDer != None): # Si existe algún error en el operador izquierdo, retorno el error. resultadoIzq = self.opIzq.analizar(tabla, arbol) if isinstance(resultadoIzq, Excepcion): return resultadoIzq # Si existe algún error en el operador derecho, retorno el error. resultadoDer = self.opDer.analizar(tabla, arbol) if isinstance(resultadoDer, Excepcion): return resultadoDer #print(resultadoIzq) self.opIzq.tipo = resultadoIzq self.opDer.tipo = resultadoDer # Comprobamos el tipo de operador if self.operador == '+': if self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: self.tipo = Tipo(Tipo_Dato.INTEGER) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.CHAR and self.opDer.tipo.tipo == Tipo_Dato.CHAR: self.tipo = Tipo(Tipo_Dato.CHAR) return self.tipo else: error = Excepcion( '42883', "Semántico", "el operador no existe: " + self.opIzq.tipo.toString() + " + " + self.opDer.tipo.toString(), self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error elif self.operador == '-': if self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: self.tipo = Tipo(Tipo_Dato.INTEGER) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo else: error = Excepcion( '42883', "Semántico", "el operador no existe: " + self.opIzq.tipo.toString() + " - " + self.opDer.tipo.toString(), self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error elif self.operador == '*': if self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: self.tipo = Tipo(Tipo_Dato.INTEGER) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo else: error = Excepcion( '42883', "Semántico", "el operador no existe: " + self.opIzq.tipo.toString() + " - " + self.opDer.tipo.toString(), self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error elif self.operador == '/': if self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: if resultadoDer == 0: error = Excepcion('42883', "Semántico", "No se puede dividir entre cero", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error self.tipo = Tipo(Tipo_Dato.INTEGER) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: if resultadoDer == 0: error = Excepcion('42883', "Semántico", "No se puede dividir entre cero", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: if resultadoDer == 0: error = Excepcion('42883', "Semántico", "No se puede dividir entre cero", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: if resultadoDer == 0: error = Excepcion('42883', "Semántico", "No se puede dividir entre cero", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: if resultadoDer == 0: error = Excepcion('42883', "Semántico", "No se puede dividir entre cero", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: if resultadoDer == 0: error = Excepcion('42883', "Semántico", "No se puede dividir entre cero", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: if resultadoDer == 0: error = Excepcion('42883', "Semántico", "No se puede dividir entre cero", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: if resultadoDer == 0: error = Excepcion('42883', "Semántico", "No se puede dividir entre cero", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: if resultadoDer == 0: error = Excepcion('42883', "Semántico", "No se puede dividir entre cero", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo else: error = Excepcion( '42883', "Semántico", "el operador no existe: " + self.opIzq.tipo.toString() + " / " + self.opDer.tipo.toString(), self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error elif self.operador == '^': if self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo else: error = Excepcion( '42883', "Semántico", "el operador no existe: " + self.opIzq.tipo.toString() + " ^ " + self.opDer.tipo.toString(), self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error elif self.operador == '%': if self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: if resultadoDer == 0: error = Excepcion('42883', "Semántico", "División entera o módulo por cero", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error self.tipo = Tipo(Tipo_Dato.INTEGER) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: if resultadoDer == 0: error = Excepcion('42883', "Semántico", "División entera o módulo por cero", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.INTEGER and self.opDer.tipo.tipo == Tipo_Dato.NUMERIC: if resultadoDer == 0: error = Excepcion('42883', "Semántico", "División entera o módulo por cero", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo elif self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC and self.opDer.tipo.tipo == Tipo_Dato.INTEGER: if resultadoDer == 0: error = Excepcion('42883', "Semántico", "División entera o módulo por cero", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo else: error = Excepcion( '42883', "Semántico", "el operador no existe: " + self.opIzq.tipo.toString() + " % " + self.opDer.tipo.toString(), self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error else: error = Excepcion('42883', "Semántico", "Operador desconocido.", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error # Operación unaria else: # Si existe algún error en el operador izquierdo, retorno el error. resultadoIzq = self.opIzq.analizar(tabla, arbol) if isinstance(resultadoIzq, Excepcion): return resultadoIzq self.opIzq.tipo = resultadoIzq if self.operador == '-': if self.opIzq.tipo.tipo == Tipo_Dato.INTEGER: self.tipo = Tipo(Tipo_Dato.INTEGER) return self.tipo if self.opIzq.tipo.tipo == Tipo_Dato.NUMERIC: self.tipo = Tipo(Tipo_Dato.NUMERIC) return self.tipo if self.opIzq.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: self.tipo = Tipo(Tipo_Dato.DOUBLE_PRECISION) return self.tipo else: error = Excepcion( '42883', "Semántico", "Tipo de datos incorrectos en la operación negativo", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error else: error = Excepcion('42883', "Semántico", "Operador desconocido.", self.linea, self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error return None
def __init__(self, opIzq, opDer, strGram, linea, columna): Instruccion.__init__(self, Tipo(Tipo_Dato.NUMERIC), linea, columna, strGram) self.opIzq = opIzq self.opDer = opDer
def p_operadores_matematica(t): '''expre : ABS PARIZQ expre PARDER | CBRT PARIZQ expre PARDER | CEIL PARIZQ expre PARDER | CEILING PARIZQ expre PARDER | DEGREES PARIZQ expre PARDER | DIV PARIZQ expre COMA expre PARDER | EXP PARIZQ expre PARDER | FACTORIAL PARIZQ expre PARDER | FLOOR PARIZQ expre PARDER | GCD PARIZQ expre COMA expre PARDER | LCM PARIZQ expre PARDER | LN PARIZQ expre PARDER | LOG PARIZQ expre PARDER | LOG10 PARIZQ expre PARDER | MIN_SCALE PARIZQ expre PARDER | MOD PARIZQ expre COMA expre PARDER | PI PARIZQ PARDER | POWER PARIZQ expre COMA expre PARDER | RADIANS PARIZQ expre PARDER | RANDOM PARIZQ PARDER | ROUND PARIZQ expre PARDER | SCALE PARIZQ expre PARDER | SETSEED PARIZQ expre PARDER | SIGN PARIZQ expre PARDER | SQRT PARIZQ expre PARDER | TRIM_SCALE PARIZQ expre PARDER | TRUNC PARIZQ expre PARDER | WIDTH_BUCKET PARIZQ expre PARDER ''' if t[1] == 'ABS': t[0] = Abs.Abs(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'CBRT': t[0] = Cbrt.Cbrt(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'CEIL': t[0] = Ceil.Ceil(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'CEILING': t[0] = Ceiling.Ceiling(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'DEGREES': t[0] = Degrees.Degrees(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'DIV': t[0] = Div.Div(t[3], t[5], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'EXP': t[0] = Exp.Exp(t[3], Tipo(Tipo_Dato.INTEGER), t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'FACTORIAL': t[0] = Factorial.Factorial(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'FLOOR': t[0] = Floor.Floor(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'GCD': t[0] = Gcd.Gcd(t[3], t[5], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'LCM': t[0] = Lcm.Lcm(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'LN': t[0] = Ln.Ln(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'LOG': t[0] = Log.Log(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'LOG10': t[0] = Log10.Log10(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'MIN_SCALE': t[0] = MinScale.MinScale(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'MOD': t[0] = Mod.Mod(t[3], t[5], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'PI': t[0] = PI.PI(t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'POWER': t[0] = Power.Power(t[3], t[5], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'RADIANS': t[0] = Radians.Radians(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'RANDOM': t[0] = Random.Random(t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'ROUND': t[0] = Round.Round(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'SCALE': t[0] = Scale.Scale(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'SETSEED': t[0] = SetSeed.SetSeed(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'SIGN': t[0] = Sign.Sign(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'SQRT': t[0] = Sqrt.Sqrt(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'TRIM_SCALE': t[0] = TrimScale.TrimScale(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'TRUNC': t[0] = Trunc.Trunc(t[3], t.lexer.lineno, t.lexer.lexpos) elif t[1] == 'WIDTH_BUCKET': t[0] = WidthBucket.WidthBucket(t[3], Tipo(Tipo_Dato.INTEGER), t.lexer.lineno, t.lexer.lexpos) pass
def __init__(self, opIzq, opDer, operador, strGram, linea, columna): Instruccion.__init__(self, Tipo(Tipo_Dato.BOOLEAN), linea, columna, strGram) self.opIzq = opIzq self.opDer = opDer self.operador = operador
def p_tipo_datos_int1(t): '''tipo : SMALLINT ''' t[0] = Tipo(Tipo_Dato.SMALLINT)
def p_tipo_datos_int2(t): '''tipo : INTEGER ''' t[0] = Tipo(Tipo_Dato.INTEGER)
def p_tipo_datos_varchar4(t): '''tipo : TEXT ''' t[0] = Tipo(Tipo_Dato.TEXT)
def p_tipo_datos_decimal2(t): '''tipo : DECIMAL ''' t[0] = Tipo(Tipo_Dato.DECIMAL)
def p_tipo_datos_varchar3(t): '''tipo : CHARACTER PARIZQ ENTERO PARDER ''' t[0] = Tipo(Tipo_Dato.CHARACTER, t[3])
def p_tipo_datos_varchar2(t): '''tipo : CHARACTER VARYING PARIZQ ENTERO PARDER ''' t[0] = Tipo(Tipo_Dato.VARYING, t[4])
def p_tipo_datos_varchar(t): '''tipo : VARCHAR PARIZQ ENTERO PARDER ''' t[0] = Tipo(Tipo_Dato.VARCHAR, t[3])
def p_tipo_datos_date1(t): '''tipo : TIME ''' t[0] = Tipo(Tipo_Dato.TIME)
def p_tipo_datos_int3(t): '''tipo : BIGINT ''' t[0] = Tipo(Tipo_Dato.BIGINT)
def p_tipo_datos_date2(t): '''tipo : INTERVAL ''' t[0] = Tipo(Tipo_Dato.INTERVAL)
def p_tipo_datos_int4(t): '''tipo : NUMERIC ''' t[0] = Tipo(Tipo_Dato.NUMERIC)
def __init__(self, opIzq, opDer, linea, columna): Instruccion.__init__(self, Tipo(Tipo_Dato.DOUBLE_PRECISION), linea, columna) self.opIzq = opIzq self.opDer = opDer
def p_tipo_datos_int5(t): '''tipo : REAL ''' t[0] = Tipo(Tipo_Dato.REAL)
def __init__(self, strGram, linea, columna, strSent): Instruccion.__init__(self, Tipo("", Tipo_Dato.DOUBLE_PRECISION), linea, columna, strGram, strSent)
def p_tipo_datos_int6(t): '''tipo : DOUBLE PRECISION ''' t[0] = Tipo(Tipo_Dato.DOUBLE_PRECISION)
def __init__(self, id, strGram, linea, columna, strSent): Instruccion.__init__(self, Tipo("", Tipo_Dato.ID), linea, columna, strGram, strSent) self.id = id
def p_tipo_datos_int7(t): '''tipo : MONEY ''' t[0] = Tipo(Tipo_Dato.MONEY)
def __init__(self, valor, strGram, linea, columna): Instruccion.__init__(self, Tipo(Tipo_Dato.NUMERIC), linea, columna, strGram) self.valor = valor
def p_tipo_datos_int8(t): '''tipo : BOOLEAN ''' t[0] = Tipo(Tipo_Dato.BOOLEAN)
def ejecutar(self, tabla, arbol): super().ejecutar(tabla,arbol) prim = None strGram = "" if self.tipo.tipo == Tipo_Dato.SMALLINT: prim = Primitivo(0, Tipo(Tipo_Dato.SMALLINT), strGram,0,0) elif self.tipo.tipo == Tipo_Dato.INTEGER: prim = Primitivo(0, Tipo(Tipo_Dato.INTEGER), strGram,0,0) elif self.tipo.tipo == Tipo_Dato.BIGINT: prim = Primitivo(0, Tipo(Tipo_Dato.BIGINT), strGram, 0,0) elif self.tipo.tipo == Tipo_Dato.DECIMAL: prim = Primitivo(0, Tipo(Tipo_Dato.DECIMAL),strGram, 0,0) elif self.tipo.tipo == Tipo_Dato.NUMERIC: prim = Primitivo(0, Tipo(Tipo_Dato.NUMERIC), strGram,0,0) elif self.tipo.tipo == Tipo_Dato.REAL: prim = Primitivo(0, Tipo(Tipo_Dato.REAL), strGram,0,0) elif self.tipo.tipo == Tipo_Dato.DOUBLE_PRECISION: prim = Primitivo(0, Tipo(Tipo_Dato.DOUBLE_PRECISION),strGram, 0,0) elif self.tipo.tipo == Tipo_Dato.MONEY: prim = Primitivo(0, Tipo(Tipo_Dato.MONEY),strGram, 0,0) elif self.tipo.tipo == Tipo_Dato.DATE: prim = Primitivo('1900-01-01', Tipo(Tipo_Dato.DATE),strGram, 0,0) elif self.tipo.tipo == Tipo_Dato.TIMESTAMP: prim = Primitivo('1900-01-01', Tipo(Tipo_Dato.TIMESTAMP),strGram, 0,0) elif self.tipo.tipo == Tipo_Dato.TIME: prim = Primitivo('1900-01-01', Tipo(Tipo_Dato.DATE),strGram, 0,0) elif self.tipo.tipo == Tipo_Dato.BOOLEAN: prim = Primitivo(True, Tipo(Tipo_Dato.BOOLEAN),strGram, 0,0) variable = Simbolo(self.nombre,self.tipo,prim.valor,0,0) resultadoInsertar = tabla.setVariable(variable) if resultadoInsertar != None: error = Excepcion("100","Semantico","La columna "+self.nombre+" yo existe",self.linea,self.columna) arbol.excepciones.append(error) arbol.consola.append(error.toString()) return error if self.expresion != None: resultado = self.expresion.ejecutar(tabla, arbol) if isinstance(resultado, Excepcion): return resultado return True
def p_tipo_datos_date(t): '''tipo : TIMESTAMP ''' t[0] = Tipo(Tipo_Dato.TIMESPACE)
def __init__(self, valor, strGram, linea, columna): Instruccion.__init__(self, Tipo(Tipo_Dato.DOUBLE_PRECISION), linea, columna, strGram) self.valor = valor
def p_tipo_datos(t): '''tipo : INT ''' t[0] = Tipo(Tipo_Dato.INTEGER)