public Firma(string lexema, NodoTablaSimbolos.TipoDeDato tipo, bool esRef, bool esConstante) { this.Lexema = lexema; this.Tipo = tipo; this.EsReferencia = esRef; this.EsConstante = esConstante; }
internal void AgregarVariable(string nombre, NodoTablaSimbolos.TipoDeDato tdato, bool esConstante, NodoTablaSimbolos.TipoContexto contexto, string nombreProc, string valor) { this.listaNodos.Add(new NodoTablaSimbolos(nombre, NodoTablaSimbolos.TipoDeEntrada.Variable, tdato, esConstante, contexto, nombreProc) { ValorTexto = valor }); }
public override void ChequearAtributos(Terminal t) { if (this.hijosNodo.Count > 1) { NodoTablaSimbolos.TipoDeDato tipo1 = this.hijosNodo[0].TipoDato; NodoTablaSimbolos.TipoDeDato tipo2 = this.hijosNodo[1].TipoDato; NodoTablaSimbolos.TipoDeDato tipo3 = this.hijosNodo[2].TipoDato; if (tipo3 != NodoTablaSimbolos.TipoDeDato.Ninguno) { if (tipo1 != tipo2) { throw new ErrorSemanticoException(new ErrorOperarExpresionesTipoIncorrecto(tipo1, tipo2)); } else { if (tipo2 != tipo3) { throw new ErrorSemanticoException(new ErrorOperarExpresionesTipoIncorrecto(tipo2, tipo3)); } } } else { if (tipo1 != tipo2) { throw new ErrorSemanticoException(new ErrorOperarExpresionesTipoIncorrecto(tipo1, tipo2)); } } //this.Temporal = ManagerTemporales.Instance.CrearNuevoTemporal(this.nombreContextoLocal, this.ToString()); //this.TablaSimbolos.AgregarTemporal(this.Temporal.Nombre, tipo2); } }
internal bool AgregarArregloParametroDeProc(string nombre, NodoTablaSimbolos.TipoDeDato tipoDeDato, NodoTablaSimbolos.TipoContexto tipoContexto, string nombreProc, string rango) { double rangoNum; if (!double.TryParse(rango, System.Globalization.NumberStyles.Number, new CultureInfo("es-AR"), out rangoNum)) { NodoTablaSimbolos nodoConstante = this.listaNodos.Find(x => x.Nombre.ToUpper().Equals(rango.ToUpper()) && x.EsConstante); rangoNum = nodoConstante.Valor; } //o sea, que sea entero if (Math.Truncate(rangoNum) == rangoNum) { this.listaNodos.Add(new NodoTablaSimbolos(nombre, NodoTablaSimbolos.TipoDeEntrada.Parametro, tipoDeDato, true, false, tipoContexto, nombreProc) { Valor = rangoNum }); return(true); } else { //Esto seria un error, no se puede tener un arreglo con rango decimal return(false); } }
public FirmaProc(string nombre, NodoTablaSimbolos.TipoDeDato tipo, bool arr, bool esRef) { TipoDato = tipo; EsArreglo = arr; Lexema = nombre; EsPorReferencia = esRef; }
public NodoTipoArreglo(NodoTablaSimbolos.TipoDeDato dato, string r) { StringBuilder strBldr = new StringBuilder(); this.tipoDato = dato; this.rango = r; this.nombre = RandomManager.RandomStringConPrefijo(string.Format("{0}_{1}_", EnumUtils.stringValueOf(tipoDato), rango), 6, true); }
internal void AgregarFuncionDelFramework(string nombre, List <FirmaProc> firma, NodoTablaSimbolos.TipoDeDato tdato, string codigoPascal, string nombreFunc) { this.listaNodos.Add(new NodoTablaSimbolos(nombre, NodoTablaSimbolos.TipoDeEntrada.Funcion, tdato, firma) { EsDelFramework = true, CodigoPascalParaElFramework = codigoPascal, NombreFuncionEnPascal = nombreFunc } ); }
public override NodoArbolSemantico SalvarAtributosParaContinuar() { string nombre = this.hijosNodo[0].Lexema; NodoTablaSimbolos.TipoDeDato tipo = this.hijosNodo[2].TipoDato; if (!this.TablaSimbolos.ExisteVariableEnEsteContexto(nombre, this.ContextoActual, this.NombreContextoLocal)) { this.TablaSimbolos.AgregarVariable(nombre, tipo, this.EsConstante, this.ContextoActual, this.NombreContextoLocal); } return(this); }
public override NodoArbolSemantico CalcularAtributos(Terminal t) { this.EsSino = this.hijosNodo[4].EsSino; NodoTablaSimbolos.TipoDeDato tipoDato = this.hijosNodo[2].TipoDato; if (tipoDato != NodoTablaSimbolos.TipoDeDato.Booleano) { throw new ErrorSemanticoException(new ErrorCondicionSiNoBooleana()); } return(this); }
public override NodoArbolSemantico CalcularAtributos(Terminal t) { nombreVarControladora = RandomManager.RandomStringConPrefijo("mientrasVar", 20, true); this.TablaSimbolos.AgregarAuxiliarParaCodIntermedio(nombreVarControladora, TablaDeSimbolos.NodoTablaSimbolos.TipoDeDato.Numero); NodoTablaSimbolos.TipoDeDato tipoDato = this.hijosNodo[2].TipoDato; if (tipoDato != NodoTablaSimbolos.TipoDeDato.Booleano) { throw new ErrorSemanticoException(new ErrorCondicionMientrasNoBooleana()); } return(this); }
public override void ChequearAtributos(Terminal t) { TipoOperatoria operacion = this.hijosNodo[1].Operacion; NodoTablaSimbolos.TipoDeDato tipo1 = this.hijosNodo[0].TipoDato; NodoTablaSimbolos.TipoDeDato tipo2 = this.hijosNodo[1].TipoDato; if (operacion != TipoOperatoria.Ninguna) { if (tipo1 != tipo2) { throw new ErrorSemanticoException(new ErrorOperarExpresionesTipoIncorrecto(tipo1, tipo2)); } } }
internal string AgregarTipoArreglo(NodoTablaSimbolos.TipoDeDato tipo, string rango) { string nombreTipo; if (!listaTiposArreglos.Exists(m => m.Rango == rango && m.TipoDato == tipo)) { NodoTipoArreglo t = new NodoTipoArreglo(tipo, rango); listaTiposArreglos.Add(t); nombreTipo = t.Nombre; } else { NodoTipoArreglo t = listaTiposArreglos.Find(m => m.Rango == rango && m.TipoDato == tipo); nombreTipo = t.Nombre; } return(nombreTipo); }
public override NodoArbolSemantico CalcularAtributos(Terminal t) { string nombre = this.hijosNodo[0].Lexema; NodoTablaSimbolos.TipoDeDato tipo = this.hijosNodo[2].TipoDato; if (this.DeclaracionesPermitidas == TipoDeclaracionesPermitidas.Constantes) { if (!this.TablaSimbolos.ExisteVariableEnEsteContexto(nombre, this.ContextoActual, this.NombreContextoLocal)) { if (tipo != this.hijosNodo[4].TipoDato) { throw new ErrorSemanticoException(new ErrorTipoInvalidoEnConstante(nombre, tipo, this.hijosNodo[4].TipoDato)); } this.ValorConstanteNumerica = this.hijosNodo[4].ValorConstanteNumerica; this.ValorConstanteTexto = this.hijosNodo[4].ValorConstanteTexto; if (tipo == NodoTablaSimbolos.TipoDeDato.Numero) { this.TablaSimbolos.AgregarConstante(nombre, tipo, this.ContextoActual, this.NombreContextoLocal, this.ValorConstanteNumerica); } else { this.TablaSimbolos.AgregarConstante(nombre, tipo, this.ContextoActual, this.NombreContextoLocal, this.ValorConstanteTexto); } //this.TablaSimbolos.AgregarVariable(nombre, tipo, this.EsConstante, this.ContextoActual, this.NombreContextoLocal); } else { throw new ErrorSemanticoException(new ErrorConstanteRepetida(nombre)); } } else { throw new ErrorSemanticoException(new ErrorDeclaracionConstanteFueraLugar()); } return(this); }
internal bool AgregarArreglo(string nombre, NodoTablaSimbolos.TipoDeDato tdato, NodoTablaSimbolos.TipoContexto contexto, string nombreContexto, string rango, bool esConst) { //Para que no falle pq se puso mal el rango del arrego, si viene en null, se pone en 1 if (rango == null) { rango = "1"; } double rangoNum; if (!double.TryParse(rango, System.Globalization.NumberStyles.Number, new CultureInfo("es-AR"), out rangoNum)) { NodoTablaSimbolos nodoConstante = this.listaNodos.Find(x => x.Nombre.ToUpper().Equals(rango.ToUpper()) && x.EsConstante); rangoNum = nodoConstante.Valor; } //o sea, que sea entero if (Math.Truncate(rangoNum) == rangoNum) { this.listaNodos.Add( new NodoTablaSimbolos(nombre, NodoTablaSimbolos.TipoDeEntrada.Variable, tdato, true, esConst, contexto, nombreContexto) { Valor = rangoNum } ); return(true); } else { //Esto seria un error, no se puede tener un arreglo con rango decimal return(false); } }
internal void AgregarConstante(string nombre, NodoTablaSimbolos.TipoDeDato tipo, NodoTablaSimbolos.TipoContexto tipoContexto, string nombreProc, string valorTexto) { AgregarVariable(nombre, tipo, true, tipoContexto, nombreProc, valorTexto); }
public override NodoArbolSemantico CalcularAtributos(Terminal t) { string nombre = this.hijosNodo[0].Lexema; bool esArreglo = this.hijosNodo[0].EsArreglo; Gargar = string.Format("{0} {1} {2}{3}", this.hijosNodo[0].Gargar, this.hijosNodo[1].Gargar, this.hijosNodo[2].Gargar, this.hijosNodo[3].Gargar); NodoTablaSimbolos.TipoDeDato tipoExp = this.hijosNodo[2].TipoDato; NodoTablaSimbolos.TipoDeDato tipo; StringBuilder strbldr; LineaCorrespondiente = GlobalesCompilador.UltFila; if (!esArreglo) { if (this.TablaSimbolos.ExisteVariable(nombre, this.ContextoActual, this.NombreContextoLocal)) { tipo = this.TablaSimbolos.ObtenerTipoVariable(nombre, this.ContextoActual, this.NombreContextoLocal); if (tipo == tipoExp) { if (this.TablaSimbolos.EsModificableValorVarible(nombre, this.ContextoActual, this.NombreContextoLocal)) { //esto es para agarrar que no se haga nada raro en el procedimiento salida if (this.TablaSimbolos.EsParametroDeEsteProc(nombre, this.ContextoActual, this.NombreContextoLocal)) { this.ModificaParametros = true; } if (this.TablaSimbolos.EsVariableGlobal(nombre, this.ContextoActual, this.NombreContextoLocal)) { this.UsaVariablesGlobales = true; } this.AsignaParametros = this.hijosNodo[2].AsignaParametros; this.UsaVariablesGlobales = this.UsaVariablesGlobales || this.hijosNodo[2].UsaVariablesGlobales; } else { throw new ErrorSemanticoException(new ErrorUsoConstanteComoVariable(nombre)); } } else { throw new ErrorSemanticoException(new ErrorVariableAsignarTipoInvalido(nombre, tipo, tipoExp)); } } else { if (this.TablaSimbolos.ExisteArreglo(nombre, this.ContextoActual, this.NombreContextoLocal)) { throw new ErrorSemanticoException(new ErrorUsoArregloSinIndice(nombre)); } else { throw new ErrorSemanticoException(new ErrorUsoVariableNoDeclarada(nombre)); } } } else { if (this.TablaSimbolos.ExisteArreglo(nombre, this.ContextoActual, this.NombreContextoLocal)) { tipo = this.TablaSimbolos.ObtenerTipoArreglo(nombre, this.ContextoActual, this.NombreContextoLocal); if (tipo == tipoExp) { //this.TablaSimbolos.ModificarValorPosicionArreglo(nombre, indice, valorExp); //esto es para agarrar que no se haga nada raro en el procedimiento salida if (this.TablaSimbolos.EsParametroDeEsteProc(nombre, this.ContextoActual, this.NombreContextoLocal)) { this.ModificaParametros = true; } if (this.TablaSimbolos.EsVariableGlobal(nombre, this.ContextoActual, this.NombreContextoLocal)) { this.UsaVariablesGlobales = true; } this.AsignaParametros = this.hijosNodo[2].AsignaParametros; } else { throw new ErrorSemanticoException(new ErrorArregloAsignarTipoInvalido(nombre, tipo, tipoExp)); } } else { //mejora de error. Me fijo si no ta declarada ya como arreglo o variable if (this.TablaSimbolos.ExisteVariable(nombre, this.ContextoActual, this.NombreContextoLocal)) { throw new ErrorSemanticoException(new ErrorUsoVariableComoArreglo(nombre)); } else { throw new ErrorSemanticoException(new ErrorUsoVariableNoDeclarada(nombre)); } } } return(this); }
public override NodoArbolSemantico CalcularAtributos(Terminal t) { List <Variable> variables = this.hijosNodo[0].VariablesACrear; NodoTablaSimbolos.TipoDeDato tipo = this.hijosNodo[2].TipoDato; this.RangoArregloSinPrefijo = this.hijosNodo[2].RangoArregloSinPrefijo; StringBuilder textoParaArbol = new StringBuilder(); if (DeclaracionesPermitidas == TipoDeclaracionesPermitidas.Variables) { List <string> nombresVariables = new List <string>(); if (variables.Count > 0) { foreach (Variable v in variables) { if (!this.hijosNodo[2].EsArreglo) //if (!v.EsArreglo) { if (!this.TablaSimbolos.ExisteVariableEnEsteContexto(v.Lexema, this.ContextoActual, this.NombreContextoLocal)) { this.TablaSimbolos.AgregarVariable(v.Lexema, tipo, this.EsConstante, this.ContextoActual, this.NombreContextoLocal); textoParaArbol.Append("Declaracion de variable ").Append(v.Lexema).Append(" ").Append(EnumUtils.stringValueOf(this.ContextoActual)); textoParaArbol.Append(" de tipo ").Append(EnumUtils.stringValueOf(tipo)); nombresVariables.Add(v.Lexema); } else { throw new ErrorSemanticoException(new ErrorVariableRepetida(v.Lexema)); } } else { if (!this.TablaSimbolos.ExisteArregloEnEsteContexto(v.Lexema, this.ContextoActual, this.NombreContextoLocal)) { bool res = this.TablaSimbolos.AgregarArreglo(v.Lexema, tipo, this.ContextoActual, this.NombreContextoLocal, this.RangoArregloSinPrefijo, false); if (!res) { throw new ErrorSemanticoException(new ErrorArregloTopeDecimal()); } nombresVariables.Add(v.Lexema); } else { throw new ErrorSemanticoException(new ErrorArregloRepetido(v.Lexema)); } } } //if (!this.hijosNodo[2].EsArreglo) //{ // AgregarVariableViewModel(string.Join(",", nombresVariables.ToArray()), tipo); //} //else //{ // AgregarArregloViewModel(string.Join(",", nombresVariables.ToArray()), tipo, this.RangoArregloSinPrefijo); //} } } else { throw new ErrorSemanticoException(new ErrorDeclaracionVariableFueraLugar()); } return(this); }
public override NodoArbolSemantico CalcularAtributos(Terminal t) { bool esFuncion = (this.hijosNodo[0].Lexema.ToUpper() == "FUNCION"); string nombre = this.hijosNodo[1].Lexema; this.Lexema = nombre; List <FirmaProc> listaFirmas = new List <FirmaProc>(); NodoTablaSimbolos.TipoDeDato devolucion = NodoTablaSimbolos.TipoDeDato.Ninguno; if (esFuncion) { devolucion = this.hijosNodo[6].TipoDato; } foreach (Firma f in this.hijosNodo[3].ListaFirma) { listaFirmas.Add(new FirmaProc(f.Lexema, f.Tipo, f.EsArreglo, f.EsReferencia)); } if (!this.ProcPrincipalCrearUnaVez) { this.ProcPrincipalYaCreadoyCorrecto = false; } //if (!this.ProcSalidaCrearUnaVez) //{ // this.ProcSalidaYaCreadoyCorrecto = false; //} if (esFuncion) { if (!nombre.ToLower().Equals(GlobalesCompilador.NOMBRE_PROC_PRINCIPAL.ToLower())) { if (!this.TablaSimbolos.ExisteFuncion(nombre)) { if (devolucion == this.hijosNodo[11].TipoDato) { this.TablaSimbolos.AgregarFuncion(nombre, listaFirmas, devolucion); } else { throw new ErrorSemanticoException(new ErrorFuncionDevuelveExpresionOtroTipo(nombre, devolucion, this.hijosNodo[11].TipoDato)); } } else { throw new ErrorSemanticoException(new ErrorFuncionRepetido(nombre)); } } else { throw new ErrorSemanticoException(new ErrorProcedimientoPrincipalComoFuncion()); } } else { if (nombre.ToLower().Equals(GlobalesCompilador.NOMBRE_PROC_PRINCIPAL.ToLower())) { if (!this.ProcPrincipalYaCreadoyCorrecto && this.ProcPrincipalCrearUnaVez) { this.ProcPrincipalYaCreadoyCorrecto = true; this.ProcPrincipalCrearUnaVez = false; } } if (!this.TablaSimbolos.ExisteProcedimiento(nombre)) { List <ErrorSemanticoException> listaExcepciones = new List <ErrorSemanticoException>(); this.TablaSimbolos.AgregarProcedimiento(nombre, listaFirmas); //Arrojo todas las excepciones juntas if (listaExcepciones.Count > 0) { throw new AggregateException(listaExcepciones); } } else { throw new ErrorSemanticoException(new ErrorProcedimientoRepetido(nombre)); } } //Saco todas las variables locales que creo este procedimiento de la tabla de simbolos //this.TablaSimbolos.EliminarVariablesContextoLocal(this.nombreContextoLocal); return(this); }
internal void AgregarFuncion(string nombre, List <FirmaProc> firma, NodoTablaSimbolos.TipoDeDato tdato) { this.listaNodos.Add(new NodoTablaSimbolos(nombre, NodoTablaSimbolos.TipoDeEntrada.Funcion, tdato, firma)); }
internal void AgregarParametroDeProc(string nombre, NodoTablaSimbolos.TipoDeDato tdato, NodoTablaSimbolos.TipoContexto contexto, string nombreProc) { this.listaNodos.Add(new NodoTablaSimbolos(nombre, NodoTablaSimbolos.TipoDeEntrada.Parametro, tdato, false, contexto, nombreProc)); }
internal void AgregarAuxiliarParaCodIntermedio(string nombre, NodoTablaSimbolos.TipoDeDato tdato) { this.listaNodos.Add(new NodoTablaSimbolos(nombre, NodoTablaSimbolos.TipoDeEntrada.AuxiliarCodigoIntermedio, tdato, false, NodoTablaSimbolos.TipoContexto.Global, null)); }