public override void checkSemantica(TablaSimbolos tabla) { Object sym = tabla.buscar(id); bool exists = true, esVariable; //chequear que el método exista if (sym == null || sym.GetType() != typeof(FuncionDef)) { SemantErrorReport.Instancia.semantError(this, "no se encuentra la definición para la función \"" + id + "\""); exists = false; } //chequear que los tipos de los paramétros se correspondan con los de la función if (exists) { FuncionDef f = (FuncionDef)sym; if (f.Parametros.getLongitud() != lparams.getLongitud()) { SemantErrorReport.Instancia.semantError(this, "la cantidad de paramétros no coincide con la definición de la función \"" + id + "\""); } else { for (int i = 0; i < lparams.getLongitud(); i++) { Expresion param = lparams.getLista()[i]; //si el paramétro es una variable agregarlo a la tabla de simbolo esVariable = false; if (param.GetType() == typeof(Variable)) { if (tabla.buscar(((Variable)param).Nombre) == null) { tabla.agregarId(((Variable)param).Nombre, param); } esVariable = true; } param.checkSemantica(tabla); if (!param.Tipo_Expr.Equals(f.Parametros.getLista()[i].Tipo) || (f.Parametros.getLista()[i].EsDireccion && !esVariable)) { SemantErrorReport.Instancia.semantError(param, "el tipo de paramétro no coincide con la definición de la función \"" + id + "\""); } } } } }
public override void checkSemantica(TablaSimbolos tabla) { //Chequear que si la variable existe, sea una variable Object sym = tabla.buscar(id.Nombre); if (sym != null && sym.GetType() != typeof(Variable)) { SemantErrorReport.Instancia.semantError(id, "el identificador " + id.Nombre + " es inválido"); } expr.checkSemantica(tabla); //Agregar el id a la tabla de símbolos if (sym == null) { tabla.agregarId(id.Nombre, id); } id.checkTipo(tabla); //chequear el tipo del id y la expresión if (!id.Tipo_Expr.Equals(expr.Tipo_Expr)) { SemantErrorReport.Instancia.semantError(id, "no se puede convertir valor de tipo " + expr.Tipo_Expr + " a tipo " + id.Tipo_Expr); } }
public override void checkSemantica(TablaSimbolos tabla) { Object sym = tabla.buscar(nombre); checkTipo(tabla); if (sym == null) { SemantErrorReport.Instancia.semantError(this, "la variable \"" + nombre + "\" no ha sido inicializada"); } else if (sym.GetType() != typeof(Variable)) //verificar que sea una nombre de variable { SemantErrorReport.Instancia.semantError(this, "el identificador \"" + nombre + "\" es inválido"); } }