public override int GetHashCode() { int hash = 0; if (!string.IsNullOrWhiteSpace(AccessId)) { hash ^= AccessId.GetHashCode(); } if (!string.IsNullOrWhiteSpace(DataSourceName)) { hash ^= DataSourceName.GetHashCode(); } if (!string.IsNullOrWhiteSpace(EntityTypeName)) { hash ^= EntityTypeName.GetHashCode(); } if (!string.IsNullOrWhiteSpace(JobId)) { hash ^= JobId.GetHashCode(); } hash ^= IsActive.GetHashCode(); hash ^= IsPublic.GetHashCode(); hash ^= IsStaging.GetHashCode(); return(hash); }
public void UpdateUser(int id, AccessId accessid) { FileAccess access = new FileAccess(adminFile); using (var db = new App_Context()) { var result = db.Users.Find(id); bool isTheAdmin = IsAdmin(id); if (result != null && !isTheAdmin) { result.AccessId = accessid; access.WriteLogFile(id); db.SaveChanges(); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("Update succesfully!"); Console.ResetColor(); } else if (result != null && isTheAdmin) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("Invalid Action.You try to change the Admin privilages."); Console.ResetColor(); } else { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("The Id doesn't match.Update failed."); Console.ResetColor(); } } }
public Retorno compilar(Entorno ent) { if (this.anterior == null) { SimboloFunction symFunc = ent.searchFunc(this.id); if (symFunc == null) { throw new Error("Semántico", "No se encontro la función: " + this.id, ent.obtenerAmbito(), linea, columna); } LinkedList <Retorno> paramsValues = new LinkedList <Retorno>(); Generator generator = Generator.getInstance(); int size = generator.saveTemps(ent); //Guardo temporales foreach (Expresion param in this.parametros) { if (param is AccessId) { AccessId access = (AccessId)param; access.vieneDeRelacional = true; } paramsValues.AddLast(param.compilar(ent)); } //Verifico si viene el mismo numero de parametros if (paramsValues.Count != symFunc.parametros.Count) { throw new Error("Semántico", "Faltan parametros a enviar en la llamada a la funcion:" + this.id, ent.obtenerAmbito(), linea, columna); } //Verifico si coninciden los tipos de los parametros if (!this.validarTipoParametros(paramsValues, symFunc.parametros)) { throw new Error("Semántico", "No coincide un tipo de parametro en la llamada a la funcion:" + this.id, ent.obtenerAmbito(), linea, columna); } string temp = generator.newTemporal(); generator.freeTemp(temp); //Paso de parametros en cambio simulado if (paramsValues.Count != 0) { generator.addExpression(temp, "SP", "" + (ent.size + 1), "+"); //+1 porque la posicion 0 es para el retorno; int index = -1; foreach (Retorno value in paramsValues) { index++; Param param = symFunc.parametros.ElementAt(index); if (param.isRef) { if (value.symbol.isGlobal) { generator.addSetStack(temp, "" + value.symbol.position); generator.addExpression(temp, temp, "1", "+"); generator.addSetStack(temp, "1"); } else if (value.symbol.isHeap) { generator.addSetStack(temp, "" + value.symbol.position); generator.addExpression(temp, temp, "1", "+"); generator.addSetStack(temp, "0"); } else { string temp2 = generator.newTemporal(); generator.freeTemp(temp2); generator.addExpression(temp2, "SP", "" + value.symbol.position, "+"); generator.addSetStack(temp, temp2); generator.addExpression(temp, temp, "1", "+"); generator.addSetStack(temp, "1"); } } else { generator.addSetStack(temp, value.getValue()); } if (index != paramsValues.Count - 1) { generator.addExpression(temp, temp, "1", "+"); } } } generator.addNextEnv(ent.size); generator.addCall(symFunc.uniqueId); if (symFunc.type.tipo != Tipos.VOID) { generator.addGetStack(temp, "SP"); } generator.addAntEnv(ent.size); generator.recoverTemps(ent, size); generator.addTemp(temp); if (symFunc.type.tipo != Tipos.BOOLEAN) { return(new Retorno(temp, true, symFunc.type)); } Retorno retorno = new Retorno("", false, symFunc.type); this.trueLabel = this.trueLabel == "" ? generator.newLabel() : this.trueLabel; this.falseLabel = this.falseLabel == "" ? generator.newLabel() : this.falseLabel; generator.addIf(temp, "1", "==", this.trueLabel); generator.addGoto(this.falseLabel); retorno.trueLabel = this.trueLabel; retorno.falseLabel = this.falseLabel; return(retorno); } else { } throw new Error("Semántico", "Funcion no implementada", ent.obtenerAmbito(), linea, columna); }
public Retorno compilar(Entorno ent) { //Mi modificacion if (this.left is AccessId) { AccessId access = (AccessId)this.left; access.vieneDeRelacional = true; } Retorno left = this.left.compilar(ent); Retorno right; Generator generator = Generator.getInstance(); switch (left.type.tipo) { case Tipos.INTEGER: case Tipos.REAL: right = this.right.compilar(ent); switch (right.type.tipo) { case Tipos.INTEGER: case Tipos.REAL: this.trueLabel = this.trueLabel == "" ? generator.newLabel() : this.trueLabel; this.falseLabel = this.falseLabel == "" ? generator.newLabel() : this.falseLabel; if (this.isLessEqual) { generator.addIf(left.getValue(), right.getValue(), "<=", this.trueLabel); } else { generator.addIf(left.getValue(), right.getValue(), "<", this.trueLabel); } generator.addGoto(this.falseLabel); Retorno retorno = new Retorno("", false, new Tipo(Tipos.BOOLEAN)); retorno.trueLabel = this.trueLabel; retorno.falseLabel = this.falseLabel; return(retorno); default: break; } break; case Tipos.BOOLEAN: //Mi modificacion if (this.right is AccessId) { AccessId access = (AccessId)this.right; access.vieneDeRelacional = true; } right = this.right.compilar(ent); this.trueLabel = this.trueLabel == "" ? generator.newLabel() : this.trueLabel; this.falseLabel = this.falseLabel == "" ? generator.newLabel() : this.falseLabel; if (isLessEqual) { generator.addIf(left.getValue(), right.getValue(), "<=", trueLabel); } else { generator.addIf(left.getValue(), right.getValue(), "<=", trueLabel); } generator.addGoto(falseLabel); if (right.type.tipo == Tipos.BOOLEAN) { Retorno retorno = new Retorno("", false, new Tipo(Tipos.BOOLEAN)); retorno.trueLabel = this.trueLabel; retorno.falseLabel = this.falseLabel; return(retorno); } break; case Tipos.STRING: right = this.right.compilar(ent); if (right.type.tipo == Tipos.STRING) { string temp = generator.newTemporal(); string tempAux = generator.newTemporal(); generator.freeTemp(tempAux); generator.addExpression(tempAux, "SP", "" + (ent.getSize() + 1), "+"); generator.addSetStack(tempAux, left.getValue()); generator.addExpression(tempAux, tempAux, "1", "+"); generator.addSetStack(tempAux, right.getValue()); generator.addNextEnv(ent.getSize()); if (this.isLessEqual) { generator.addCall("native_lessEq_str"); } else { generator.addCall("native_less_str"); } generator.addGetStack(temp, "SP"); generator.addAntEnv(ent.getSize()); this.trueLabel = this.trueLabel == "" ? generator.newLabel() : this.trueLabel; this.falseLabel = this.falseLabel == "" ? generator.newLabel() : this.falseLabel; generator.addIf(temp, "1", "==", this.trueLabel); generator.addGoto(this.falseLabel); Retorno retorno = new Retorno("", false, new Tipo(Tipos.BOOLEAN)); retorno.trueLabel = this.trueLabel; retorno.falseLabel = this.falseLabel; return(retorno); } break; default: right = new Retorno("", false, new Tipo(Tipos.ERROR)); break; //ERROR } throw new Error("Semántico", "No se puede evaluar un < o <= entre un " + left.type.tipoToString() + " y un " + right.type.tipoToString(), ent.obtenerAmbito(), linea, columna); }
public object compilar(Entorno ent, Errores errores) { //CREO MIS UTILIDADES //ASIGNACION INICIAL AsignacionId target = new AsignacionId(id, null, linea, columna); Asignacion asignacionInicial = new Asignacion(target, primero, linea, columna); //ACTUALIZACION DE LA VARIABLE Y CONDICION A EVALUAR Asignacion actualizarVariable; Primitivo valorFAD = new Primitivo(Tipos.INTEGER, "1", linea, columna); Expresion condicion; AccessId left = new AccessId(id, null, linea, columna); if (fad.Equals("to")) { Less menorIgual = new Less(true, left, segundo, linea, columna); condicion = (Expresion)menorIgual; Suma suma = new Suma(left, valorFAD, linea, columna); actualizarVariable = new Asignacion(target, (Expresion)suma, linea, columna); } else //downto { Greater mayorIgual = new Greater(true, left, segundo, linea, columna); condicion = (Expresion)mayorIgual; Resta resta = new Resta(left, valorFAD, linea, columna); actualizarVariable = new Asignacion(target, (Expresion)resta, linea, columna); } //INICIO LA COMPILACION try { Generator generator = Generator.getInstance(); generator.addComment("Inicia FOR"); asignacionInicial.compilar(ent, errores); string lblFor = generator.newLabel(); generator.addLabel(lblFor); Retorno retcondicion = condicion.compilar(ent); if (retcondicion.type.tipo == Tipos.BOOLEAN) { ent.fors.AddLast(new IteFor(true, actualizarVariable)); ent.ybreak.AddLast(retcondicion.falseLabel); ent.ycontinue.AddLast(lblFor); generator.addLabel(retcondicion.trueLabel); foreach (Instruccion sentencia in sentencias) { sentencia.compilar(ent, errores); } actualizarVariable.compilar(ent, errores); generator.addGoto(lblFor); generator.addLabel(retcondicion.falseLabel); ent.fors.RemoveLast(); ent.ybreak.RemoveLast(); ent.ycontinue.RemoveLast(); generator.addComment("Finaliza FOR"); } else { throw new Error("Semántico", "La condicion a evaluar en el for no es de tipo Boolean", ent.obtenerAmbito(), linea, columna); } } catch (Error ex) { errores.agregarError(ex); } return(null); }
public OptionsMenu() { AdminUser manager = new AdminUser(); bool firstChoise = true; int select; while (firstChoise) { bool correctNum = false; do { Console.WriteLine("1.Application Login\n2.Login As Super Admin\n3.Create Account\n0.Close Application"); Console.WriteLine("================="); Console.WriteLine("Select from Menu:"); bool isNum = int.TryParse(Console.ReadLine(), out select); if (select < 0 || select > 3) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("Your choose it's out of range."); Console.ResetColor(); break; } else { correctNum = true; } } while (!correctNum); switch (select) { case 1: //This bool become true only if username and pass it's correct //otherwise still ask insert username and pass bool c = false; do { string user = CreateUser("Give", "username"); string pass = CreateUser("Give", "password"); AccessId x = manager.Login(user, pass); if (x != 0 && x != AccessId.Admin) { Console.WriteLine($"Welcome {user}"); switch (x) { case AccessId.Simple: SimpleMenu simpleMenu = new SimpleMenu(user); break; case AccessId.Basic: BasicMenu basicMenu = new BasicMenu(user); break; case AccessId.Edit: EditMenu editMenu = new EditMenu(user); break; case AccessId.Delete: DeleteMenu deleteMenu = new DeleteMenu(user); break; } c = true; } else { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("Your username or password it's incorrect.Try again."); Console.ResetColor(); } } while (!c); break; case 2: Console.Clear(); Console.WriteLine(String.Format("{0," + Console.WindowWidth / 2 + "}", "Admin Login Form")); string userAdmin = CreateUser("Give", "username"); string password = CreateUser("Give", "password"); AccessId adm = manager.Login(userAdmin, password); if (adm == AccessId.Admin) { Console.WriteLine($"Welcome {userAdmin}\n"); bool take = false; do { Console.Clear(); Console.WriteLine("1.Create a user\n2.View the user of system\n3.Delete a user\n4.Update a user\n0.Log Out"); int val; string email; bool n = int.TryParse(Console.ReadLine(), out val); switch (val) { case 1: try { userAdmin = CreateUser("Give", "username"); password = CreateUser("Give", "password"); email = CreateUser("Give", "email"); manager.Register(userAdmin, password, email); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Press any button to exit."); Console.ReadKey(); return; } break; case 2: manager.ViewUser(); break; case 3: try { int userId; bool id = int.TryParse(CreateUser("Give", "user id"), out userId); User a = new User() { Id = userId }; manager.DeleteUser(a); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Press any button to exit."); Console.ReadKey(); return; } break; case 4: Console.WriteLine("1.Change Password\n2.Change Access id\n3.Change email"); int takeVal, _id; bool _take = int.TryParse(Console.ReadLine(), out takeVal); string success, _email; AccessId e; switch (takeVal) { case 1: try { _take = int.TryParse(CreateUser("Give", "user id"), out _id); password = CreateUser("Give", "password"); manager.UpdateUser(_id, password); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Press any button to exit."); Console.ReadKey(); return; } break; case 2: try { bool _successBool = false; _take = int.TryParse(CreateUser("Give", "user id"), out _id); do { success = CreateUser("Give", "access id"); if (!ValidAccessId(success)) { Console.WriteLine("Not valid access id"); } else { _successBool = true; } } while (!_successBool); e = (AccessId)Enum.Parse(typeof(AccessId), success); manager.UpdateUser(_id, e); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Press any button to exit."); Console.ReadKey(); return; } break; case 3: try { _take = int.TryParse(CreateUser("Give", "user id"), out _id); _email = CreateUser("Give", "email"); manager.UpdateEmail(_id, _email); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Press any button to exit."); Console.ReadKey(); return; } break; } break; case 0: Environment.Exit(0); break; } Console.WriteLine("Do you want to continue?(Y/N)"); string answer = Console.ReadLine(); if (answer == "Y" || answer == "y") { take = false; } else { take = true; manager.Logout(); } } while (!take); } else { Console.WriteLine("You enter invalid details!"); Environment.Exit(0); } break; case 3: string usernameOne, passOne, emailOne; bool first = false; bool second = false; bool third = false; do { usernameOne = CreateUser("Give", "username").Trim(); var x = manager.ExistUser(usernameOne); if (!x) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("The username already exist."); Console.ResetColor(); } else if (usernameOne == "" || usernameOne.Length < 6 || usernameOne.Length > 12 || !x) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("The username must be between 6 and 12 characters."); Console.ResetColor(); first = false; } else { first = true; } } while (!first); do { passOne = CreateUser("Give", "password"); bool isValidPass = Regex.IsMatch(passOne, passPattern); if (!isValidPass) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("The password must contain between 8 and 15 characters." + "Also must contain 2 letters,one special character and one number."); Console.ResetColor(); second = false; } else { second = true; } } while (!second); do { emailOne = CreateUser("Give", "email").Trim(); bool isValidEmail = Regex.IsMatch(emailOne, emailPattern); if (!isValidEmail) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("The email doesn't have the correct format."); Console.ResetColor(); } else { third = true; } } while (!third); try { bool p = manager.Register(usernameOne, passOne, emailOne); if (p) { Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("Your account create succesfully."); Console.ResetColor(); Console.WriteLine($"Your username: {usernameOne}"); } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("Press any button to exit."); Console.ReadKey(); return; } Console.WriteLine("Do you want to continue? Y/N"); string yourChoose = Console.ReadLine(); if (yourChoose == "Y" || yourChoose == "y") { firstChoise = true; } else { firstChoise = false; manager.Logout(); } break; case 0: Environment.Exit(0); break; } } Console.ReadKey(); }
private object analizarNodo(ParseTreeNode actual) { //INICIO DE LA GRAMATICA if (compararNodo(actual, "S")) { LinkedList <Instruccion> instrucciones = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[0]); return(new AST(instrucciones)); } else if (compararNodo(actual, "P")) { LinkedList <Instruccion> pilatemp = new LinkedList <Instruccion>(); if (actual.ChildNodes.Count == 4) { //MAIN Bloque bloque = (Bloque)analizarNodo(actual.ChildNodes[3]); recorrerBloque(pilatemp, bloque); } else if (actual.ChildNodes.Count == 5) { //L_AC; MAIN LinkedList <Bloque> bloques = ((LinkedList <Bloque>)analizarNodo(actual.ChildNodes[3])); //L_AC foreach (Bloque bloque in bloques) { recorrerBloque(pilatemp, bloque); //Agrego las instrucciones que viene en pilatemp } recorrerBloque(pilatemp, (Bloque)analizarNodo(actual.ChildNodes[4])); //MAIN } return(pilatemp); } else if (compararNodo(actual, "L_AC")) { LinkedList <Bloque> acciones = new LinkedList <Bloque>(); foreach (ParseTreeNode hijo in actual.ChildNodes) { acciones.AddLast((Bloque)analizarNodo(hijo)); //AC } return(acciones); } else if (compararNodo(actual, "AC")) { return(analizarNodo(actual.ChildNodes[0])); //retornando Bloque } else if (compararNodo(actual, "G_CNT")) { return(new Bloque((LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[1]))); } else if (compararNodo(actual, "L_CNT")) { LinkedList <Instruccion> constantes = new LinkedList <Instruccion>(); foreach (ParseTreeNode hijo in actual.ChildNodes) { constantes.AddLast((Instruccion)analizarNodo(hijo)); } return(constantes); } else if (compararNodo(actual, "CNT")) { string id = getLexema(actual.ChildNodes[0]); Expresion value = (Expresion)analizarNodo(actual.ChildNodes[2]); return(new DeclaConstante(id, value, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else if (compararNodo(actual, "G_TY")) { return(new Bloque((LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[1]))); } else if (compararNodo(actual, "L_TY")) { LinkedList <Instruccion> instrucciones = new LinkedList <Instruccion>(); foreach (ParseTreeNode hijo in actual.ChildNodes) { instrucciones.AddLast((Instruccion)analizarNodo(hijo)); } return(instrucciones); } else if (compararNodo(actual, "TY")) { string id = getLexema(actual.ChildNodes[0]); if (compararNodo(actual.ChildNodes[2].ChildNodes[0], "OBJ")) { LinkedList <Param> paramList = (LinkedList <Param>)analizarNodo(actual.ChildNodes[2].ChildNodes[0]); //OBJ return(new StructSt(id, paramList, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else //ARRAY { LinkedList <Dimension> dimensiones = (LinkedList <Dimension>)analizarNodo(actual.ChildNodes[2].ChildNodes[0].ChildNodes[2]); //L_DIM Tipo tipoArreglo = (Tipo)analizarNodo(actual.ChildNodes[2].ChildNodes[0].ChildNodes[5]); //ZTIPO return(new ArraySt(id, dimensiones, tipoArreglo, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } } else if (compararNodo(actual, "L_DIM")) { LinkedList <Dimension> dimensiones = new LinkedList <Dimension>(); int numero = 0; foreach (ParseTreeNode hijo in actual.ChildNodes) { Dimension dimension = (Dimension)analizarNodo(hijo); numero++; dimension.numero = numero; dimensiones.AddLast(dimension); } return(dimensiones); } else if (compararNodo(actual, "DIM")) { Primitivo inferior = (Primitivo)obtenerLiteral(actual.ChildNodes[0]); Primitivo superior = (Primitivo)obtenerLiteral(actual.ChildNodes[3]); return(new Dimension(inferior, superior)); } else if (compararNodo(actual, "OBJ")) { return(analizarNodo(actual.ChildNodes[2])); } else if (compararNodo(actual, "L_AT")) { LinkedList <Param> paramList = new LinkedList <Param>(); foreach (ParseTreeNode hijo in actual.ChildNodes) { LinkedList <Param> paramhijos = (LinkedList <Param>)analizarNodo(hijo); foreach (Param paramhijo in paramhijos) { paramList.AddLast(paramhijo); } } return(paramList); } else if (compararNodo(actual, "AT")) { LinkedList <string> idList = (LinkedList <string>)analizarNodo(actual.ChildNodes[0]); //L_ID Tipo tipo = (Tipo)analizarNodo(actual.ChildNodes[2]); //ZTIPO LinkedList <Param> atributos = new LinkedList <Param>(); foreach (string id in idList) { atributos.AddLast(new Param(id, tipo)); } return(atributos); } else if (compararNodo(actual, "DECLAS")) { return(new Bloque((LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[1]))); } else if (compararNodo(actual, "L_VR")) { LinkedList <Instruccion> declaraciones = new LinkedList <Instruccion>(); foreach (ParseTreeNode hijo in actual.ChildNodes) { declaraciones.AddLast((Instruccion)analizarNodo(hijo)); } return(declaraciones); } else if (compararNodo(actual, "VR")) { LinkedList <string> idList; Tipo tipo; if (actual.ChildNodes.Count == 6) { idList = (LinkedList <string>)analizarNodo(actual.ChildNodes[0]); tipo = (Tipo)analizarNodo(actual.ChildNodes[2]); Expresion value = (Expresion)analizarNodo(actual.ChildNodes[4]); return(new Declaracion(tipo, idList, value, actual.ChildNodes[1].Token.Location.Line, actual.ChildNodes[1].Token.Location.Column)); } else //4 HIJOS { idList = (LinkedList <string>)analizarNodo(actual.ChildNodes[0]); tipo = (Tipo)analizarNodo(actual.ChildNodes[2]); Expresion value = null; if (tipo.tipo == Tipos.STRUCT) { value = new NewStruct(tipo.tipoId, actual.ChildNodes[1].Token.Location.Line, actual.ChildNodes[1].Token.Location.Column); } return(new Declaracion(tipo, idList, value, actual.ChildNodes[1].Token.Location.Line, actual.ChildNodes[1].Token.Location.Column)); } } else if (compararNodo(actual, "L_ID")) { LinkedList <string> idList = new LinkedList <string>(); foreach (ParseTreeNode hijo in actual.ChildNodes) { idList.AddLast(getLexema(hijo)); } return(idList); } else if (compararNodo(actual, "ZTIPO")) { Tipos tipoenum; if (compararID(actual.ChildNodes[0])) { tipoenum = Tipo.Tipos.STRUCT; return(new Tipo(tipoenum, getLexema(actual.ChildNodes[0]))); } else //TIPO { tipoenum = (Tipos)analizarNodo(actual.ChildNodes[0]); return(new Tipo(tipoenum)); } } else if (compararNodo(actual, "TIPO")) { string tipocadena = getLexema(actual.ChildNodes[0]).ToLower(); switch (tipocadena) { case "integer": return(Tipos.INTEGER); case "real": return(Tipos.REAL); case "string": return(Tipos.STRING); default: return(Tipos.BOOLEAN); //boolean } } else if (compararNodo(actual, "L_PROF")) { LinkedList <Instruccion> funciones = new LinkedList <Instruccion>(); foreach (ParseTreeNode hijo in actual.ChildNodes) { funciones.AddLast((Instruccion)analizarNodo(hijo)); } return(new Bloque(funciones)); } else if (compararNodo(actual, "PROF")) { return(analizarNodo(actual.ChildNodes[0])); } else if (compararNodo(actual, "PRO")) { Tipo tipo = new Tipo(Tipo.Tipos.VOID); string id = getLexema(actual.ChildNodes[1]); LinkedList <Param> parametros = new LinkedList <Param>(); LinkedList <Bloque> bloques; if (actual.ChildNodes.Count == 7) { parametros = (LinkedList <Param>)analizarNodo(actual.ChildNodes[3]); bloques = (LinkedList <Bloque>)analizarNodo(actual.ChildNodes[6]); } else if (actual.ChildNodes.Count == 6) { bloques = (LinkedList <Bloque>)analizarNodo(actual.ChildNodes[5]); } else //4 hijos { bloques = (LinkedList <Bloque>)analizarNodo(actual.ChildNodes[3]); } return(new FunctionSt(tipo, id, parametros, bloques, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else if (compararNodo(actual, "FUN")) { string id = getLexema(actual.ChildNodes[1]); Tipo tipo; LinkedList <Param> parametros = new LinkedList <Param>(); LinkedList <Bloque> bloques; if (actual.ChildNodes.Count == 9) { parametros = (LinkedList <Param>)analizarNodo(actual.ChildNodes[3]); tipo = (Tipo)analizarNodo(actual.ChildNodes[6]); bloques = (LinkedList <Bloque>)analizarNodo(actual.ChildNodes[8]); } else if (actual.ChildNodes.Count == 8) { tipo = (Tipo)analizarNodo(actual.ChildNodes[5]); bloques = (LinkedList <Bloque>)analizarNodo(actual.ChildNodes[7]); } else //6 hijos { tipo = (Tipo)analizarNodo(actual.ChildNodes[3]); bloques = (LinkedList <Bloque>)analizarNodo(actual.ChildNodes[5]); } return(new FunctionSt(tipo, id, parametros, bloques, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else if (compararNodo(actual, "L_PARAM")) { LinkedList <Param> parametros = new LinkedList <Param>(); LinkedList <Param> paramhijos; foreach (ParseTreeNode hijo in actual.ChildNodes) { paramhijos = (LinkedList <Param>)analizarNodo(hijo); foreach (Param param in paramhijos) { parametros.AddLast(param); } } return(parametros); } else if (compararNodo(actual, "PARAM")) { LinkedList <string> idList; Tipo tipo; bool isRef; if (actual.ChildNodes.Count == 3) { idList = (LinkedList <string>)analizarNodo(actual.ChildNodes[0]); tipo = (Tipo)analizarNodo(actual.ChildNodes[2]); //ZTIPO isRef = false; } else //4 HIJOS { idList = (LinkedList <string>)analizarNodo(actual.ChildNodes[1]); tipo = (Tipo)analizarNodo(actual.ChildNodes[3]); //ZTIPO isRef = true; } LinkedList <Param> atributos = new LinkedList <Param>(); foreach (string id in idList) { atributos.AddLast(new Param(id, tipo, isRef)); } return(atributos); } else if (compararNodo(actual, "SPACE")) { LinkedList <Bloque> bloques; Bloque nuevobloque; LinkedList <Instruccion> sentencias; if (actual.ChildNodes.Count == 1) //BEG { bloques = new LinkedList <Bloque>(); sentencias = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[0]); nuevobloque = new Bloque(sentencias); bloques.AddLast(nuevobloque); } else //L_DEF BEG { bloques = (LinkedList <Bloque>)analizarNodo(actual.ChildNodes[0]); sentencias = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[1]); nuevobloque = new Bloque(sentencias); bloques.AddLast(nuevobloque); } return(bloques); } else if (compararNodo(actual, "L_DEF")) { LinkedList <Bloque> bloques = new LinkedList <Bloque>(); foreach (ParseTreeNode hijo in actual.ChildNodes) { bloques.AddLast((Bloque)analizarNodo(hijo)); } return(bloques); } else if (compararNodo(actual, "DEF")) { //retorno un bloque return(analizarNodo(actual.ChildNodes[0])); } else if (compararNodo(actual, "MAIN")) { //L_SEN return(new Bloque((LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[1]))); } else if (compararNodo(actual, "L_SEN")) { LinkedList <Instruccion> sentencias = new LinkedList <Instruccion>(); foreach (ParseTreeNode hijo in actual.ChildNodes) { sentencias.AddLast((Instruccion)analizarNodo(hijo)); //SEN } return(sentencias); } else if (compararNodo(actual, "SEN")) { return(analizarNodo(actual.ChildNodes[0])); } else if (compararNodo(actual, "BEG")) { return(analizarNodo(actual.ChildNodes[1])); //retorna lista de sentencias } else if (compararNodo(actual, "L_SENCU")) { LinkedList <Instruccion> sentencias = new LinkedList <Instruccion>(); foreach (ParseTreeNode hijo in actual.ChildNodes) { LinkedList <Instruccion> sentenciashijo = (LinkedList <Instruccion>)analizarNodo(hijo); foreach (Instruccion senhijo in sentenciashijo) { sentencias.AddLast(senhijo); } } return(sentencias); } else if (compararNodo(actual, "SENCU")) { LinkedList <Instruccion> sentencias; if (compararNodo(actual.ChildNodes[0], "BEG")) { sentencias = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[0]); } else //SEN { sentencias = new LinkedList <Instruccion>(); sentencias.AddLast((Instruccion)analizarNodo(actual.ChildNodes[0])); } return(sentencias); } else if (compararNodo(actual, "ASIG")) { Expresion target = (Expresion)analizarNodo(actual.ChildNodes[0]); Expresion value = (Expresion)analizarNodo(actual.ChildNodes[2]); return(new Asignacion(target, value, actual.ChildNodes[1].Token.Location.Line, actual.ChildNodes[1].Token.Location.Column)); } else if (compararNodo(actual, "ASID")) { if (actual.ChildNodes.Count == 3) { Expresion anterior = (Expresion)analizarNodo(actual.ChildNodes[0]); string id = getLexema(actual.ChildNodes[2]); return(new AsignacionId(id, anterior, actual.ChildNodes[1].Token.Location.Line, actual.ChildNodes[1].Token.Location.Column)); } else //UN HIJO { string id = getLexema(actual.ChildNodes[0]); return(new AsignacionId(id, null, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } } else if (compararNodo(actual, "IF")) { Expresion condicion = (Expresion)analizarNodo(actual.ChildNodes[1]); LinkedList <Instruccion> sentencias = new LinkedList <Instruccion>(); LinkedList <Instruccion> sentenciasElse; if (actual.ChildNodes.Count <= 5) { if (compararNodo(actual.ChildNodes[3], "BEG")) { sentencias = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[3]); } else //SEN { sentencias.AddLast((Instruccion)analizarNodo(actual.ChildNodes[3])); } sentenciasElse = null; if (actual.ChildNodes.Count == 5) { sentenciasElse = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[4]); //ELSE } } else //7 HIJOS { sentencias = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[4]); sentenciasElse = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[6]); } return(new If(condicion, sentencias, sentenciasElse, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else if (compararNodo(actual, "ELSE")) { LinkedList <Instruccion> sentencias; if (compararNodo(actual.ChildNodes[1], "BEG")) { sentencias = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[1]); } else //SEN { sentencias = new LinkedList <Instruccion>(); sentencias.AddLast((Instruccion)analizarNodo(actual.ChildNodes[1])); } return(sentencias); } else if (compararNodo(actual, "CASE")) { string id; AccessId variable; LinkedList <Opcion> opciones; LinkedList <Instruccion> sentenciasElse = null; if (actual.ChildNodes.Count == 6) { id = getLexema(actual.ChildNodes[1]); variable = new AccessId(id, null, actual.ChildNodes[1].Token.Location.Line, actual.ChildNodes[1].Token.Location.Column); opciones = (LinkedList <Opcion>)analizarNodo(actual.ChildNodes[3]); } else if (actual.ChildNodes.Count == 7) { id = getLexema(actual.ChildNodes[1]); variable = new AccessId(id, null, actual.ChildNodes[1].Token.Location.Line, actual.ChildNodes[1].Token.Location.Column); opciones = (LinkedList <Opcion>)analizarNodo(actual.ChildNodes[3]); sentenciasElse = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[4]); } else if (actual.ChildNodes.Count == 8) { id = getLexema(actual.ChildNodes[2]); variable = new AccessId(id, null, actual.ChildNodes[2].Token.Location.Line, actual.ChildNodes[2].Token.Location.Column); opciones = (LinkedList <Opcion>)analizarNodo(actual.ChildNodes[5]); } else // 9 HIJOS { id = getLexema(actual.ChildNodes[2]); variable = new AccessId(id, null, actual.ChildNodes[2].Token.Location.Line, actual.ChildNodes[2].Token.Location.Column); opciones = (LinkedList <Opcion>)analizarNodo(actual.ChildNodes[5]); sentenciasElse = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[6]); } return(new Case(variable, opciones, sentenciasElse, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else if (compararNodo(actual, "L_OPC")) { LinkedList <Opcion> opciones = new LinkedList <Opcion>(); foreach (ParseTreeNode hijo in actual.ChildNodes) { opciones.AddLast((Opcion)analizarNodo(hijo)); } return(opciones); } else if (compararNodo(actual, "OPC")) { LinkedList <Expresion> etiquetas = (LinkedList <Expresion>)analizarNodo(actual.ChildNodes[0]); LinkedList <Instruccion> sentencias = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[2]); return(new Opcion(etiquetas, sentencias, actual.ChildNodes[1].Token.Location.Line, actual.ChildNodes[1].Token.Location.Column)); } else if (compararNodo(actual, "LETC")) { LinkedList <Expresion> etiquetas = new LinkedList <Expresion>(); foreach (ParseTreeNode hijo in actual.ChildNodes) { etiquetas.AddLast((Expresion)analizarNodo(hijo)); } return(etiquetas); } else if (compararNodo(actual, "ETC")) { if (actual.ChildNodes.Count == 2) { Primitivo numero = (Primitivo)obtenerLiteral(actual.ChildNodes[1]); numero.value = "-" + numero.value.ToString(); return(numero); } else { return(obtenerLiteral(actual.ChildNodes[0])); } } else if (compararNodo(actual, "REP")) { LinkedList <Instruccion> sentencias = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[1]); Expresion condicion = (Expresion)analizarNodo(actual.ChildNodes[3]); return(new Repeat(condicion, sentencias, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else if (compararNodo(actual, "WH")) { Expresion condicion = (Expresion)analizarNodo(actual.ChildNodes[1]); LinkedList <Instruccion> sentencias = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[3]); return(new While(condicion, sentencias, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else if (compararNodo(actual, "FOR")) { string id = getLexema(actual.ChildNodes[1]); Expresion primero = (Expresion)analizarNodo(actual.ChildNodes[3]); string fad = getLexema(actual.ChildNodes[4].ChildNodes[0]); Expresion segundo = (Expresion)analizarNodo(actual.ChildNodes[5]); LinkedList <Instruccion> sentencias = (LinkedList <Instruccion>)analizarNodo(actual.ChildNodes[7]); return(new For(id, primero, fad, segundo, sentencias, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else if (compararNodo(actual, "BRK")) { return(new Break(actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else if (compararNodo(actual, "COT")) { return(new Continue(actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else if (compararNodo(actual, "WRT")) { bool esSalto = false; if (getLexema(actual.ChildNodes[0]).ToLower() == "writeln") { esSalto = true; //sino es write } return(new Writeln((LinkedList <Expresion>)analizarNodo(actual.ChildNodes[2]), esSalto, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else if (compararNodo(actual, "EXT")) { if (actual.ChildNodes.Count == 5) { return(new Return((Expresion)analizarNodo(actual.ChildNodes[2]), actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else // 4 HIJOS { return(new Return(null, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } } else if (compararNodo(actual, "L_EXP")) { LinkedList <Expresion> expresiones = new LinkedList <Expresion>(); foreach (ParseTreeNode hijo in actual.ChildNodes) { expresiones.AddLast((Expresion)analizarNodo(hijo)); } return(expresiones); } else if (compararNodo(actual, "EXPLOG")) { if (actual.ChildNodes.Count == 3) { if (compararNodo(actual.ChildNodes[0], "(")) // ( EXPLOG ) { return(analizarNodo(actual.ChildNodes[1])); } else { //EXPLOG SIGNO EXPLOG Expresion izquierda = (Expresion)analizarNodo(actual.ChildNodes[0]); Expresion derecha = (Expresion)analizarNodo(actual.ChildNodes[2]); return(getOperacion(actual.ChildNodes[1], izquierda, derecha)); } } else if (actual.ChildNodes.Count == 2) { //not EXPLOG return(new Not((Expresion)analizarNodo(actual.ChildNodes[1]), actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } if (actual.ChildNodes.Count == 1) { //UN HIJO return(analizarNodo(actual.ChildNodes[0])); } } else if (compararNodo(actual, "EXPRELA")) { if (actual.ChildNodes.Count == 3) { if (compararNodo(actual.ChildNodes[0], "(")) // ( EXPRELA ) { return(analizarNodo(actual.ChildNodes[1])); } else { //EXPRELA SIGNO EXPRELA Expresion izquierda = (Expresion)analizarNodo(actual.ChildNodes[0]); Expresion derecha = (Expresion)analizarNodo(actual.ChildNodes[2]); return(getOperacion(actual.ChildNodes[1], izquierda, derecha)); } } else //UN HIJO { return(analizarNodo(actual.ChildNodes[0])); } } else if (compararNodo(actual, "EXPNUMERICA")) { if (actual.ChildNodes.Count == 3) { if (compararNodo(actual.ChildNodes[0], "(")) // ( EXPNUMERICA ) { return(analizarNodo(actual.ChildNodes[1])); } else { //EXPNUMERICA operador EXPNUMERICA Expresion izquierda = (Expresion)analizarNodo(actual.ChildNodes[0]); Expresion derecha = (Expresion)analizarNodo(actual.ChildNodes[2]); return(getOperacion(actual.ChildNodes[1], izquierda, derecha)); } } else if (actual.ChildNodes.Count == 2) { Expresion unario = (Expresion)analizarNodo(actual.ChildNodes[1]); return(new RestaUni(unario, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else //UN HIJO { if (compararID(actual.ChildNodes[0])) { } else { return(analizarNodo(actual.ChildNodes[0])); //LITERAL o ACCESS } } } else if (compararNodo(actual, "ACCESS")) { return(analizarNodo(actual.ChildNodes[0])); } else if (compararNodo(actual, "ACCID")) { if (actual.ChildNodes.Count == 3) { Expresion anterior = (Expresion)analizarNodo(actual.ChildNodes[0]); string id = getLexema(actual.ChildNodes[2]); return(new AccessId(id, anterior, actual.ChildNodes[1].Token.Location.Line, actual.ChildNodes[1].Token.Location.Column)); } else //UN HIJO { string id = getLexema(actual.ChildNodes[0]); return(new AccessId(id, null, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } } else if (compararNodo(actual, "CALL")) { string id = getLexema(actual.ChildNodes[0]); LinkedList <Expresion> parametros = new LinkedList <Expresion>(); if (actual.ChildNodes.Count == 5) { parametros = (LinkedList <Expresion>)analizarNodo(actual.ChildNodes[2]); } return(new AsignacionFunc(id, parametros, null, actual.ChildNodes[0].Token.Location.Line, actual.ChildNodes[0].Token.Location.Column)); } else if (compararLiteral(actual)) //LITERAL { return(obtenerLiteral(actual)); } return(null); }