public Sentencia AssignDeclaration(Sentencia S) { if (currentToken.Tipo == TipoToken.TK_ASSIGN) { S_Asignacion sAsignacion = new S_Asignacion(); currentToken = lex.NextToken(); sAsignacion.id.id = ((Campos)S).Var.id; sAsignacion.Valor = Expr(); return DeclarationP(sAsignacion); } else { return S; } }
public Sentencia StatementP2(Variable Id) { if (currentToken.Tipo == TipoToken.TK_ASSIGN || currentToken.Tipo == TipoToken.TK_MASIGUAL || currentToken.Tipo == TipoToken.TK_MENOSIGUAL || currentToken.Tipo == TipoToken.TK_PORIGUAL || currentToken.Tipo == TipoToken.TK_ENTREIGUAL) { var Tip = currentToken.Tipo; currentToken = lex.NextToken(); if (currentToken.Tipo == TipoToken.TK_READ) { S_Read sRead = new S_Read(); sRead.var = Id; #region Read currentToken = lex.NextToken(); if (currentToken.Tipo == TipoToken.TK_OPENPAR) { currentToken = lex.NextToken(); if (currentToken.Tipo == TipoToken.TK_CLOSEPAR) { currentToken = lex.NextToken(); if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA) { currentToken = lex.NextToken(); return sRead; } else { throw new Exception("Error Sintactico - Se esperaba simbolo ;"); } } else { throw new Exception("Error Sintactico - Se esperaba simbolo )"); } } else { throw new Exception("Error Sintactico - Se esperaba simbolo ("); } #endregion } else { Expresiones E = Expr(); S_Asignacion sAsignacion = new S_Asignacion(); sAsignacion.id = Id; if (Tip == TipoToken.TK_ASSIGN) sAsignacion.Op = new Igual(); else if (Tip == TipoToken.TK_MASIGUAL) sAsignacion.Op = new MasIgual(); else if (Tip == TipoToken.TK_MENOSIGUAL) sAsignacion.Op = new MenosIgual(); else if (Tip == TipoToken.TK_PORIGUAL) sAsignacion.Op = new PorIgual(); else if (Tip == TipoToken.TK_ENTREIGUAL) sAsignacion.Op = new EntreIgual(); sAsignacion.Valor = E; return sAsignacion; } } else if (currentToken.Tipo == TipoToken.TK_OPENCOR) { currentToken = lex.NextToken(); S_Asignacion sAsignacion = new S_Asignacion(); sAsignacion.id = Id; sAsignacion.id.acces = Expr(); if (currentToken.Tipo == TipoToken.TK_CLOSECOR) { currentToken = lex.NextToken(); Sentencia S = new Sentencia(); S = StatementP2(sAsignacion.id); sAsignacion.Valor = ((S_Asignacion) S).Valor; /*if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA) { currentToken = lex.NextToken(); return sAsignacion; }*/ return sAsignacion; /*else { throw new Exception("Error Sintactico - Se esperaba simbolo ;"); }*/ } else { throw new Exception("Error Sintactico - Se esperaba simbolo ]"); } } else if (currentToken.Tipo == TipoToken.TK_MASMAS || currentToken.Tipo == TipoToken.TK_MENOSMENOS) { S_Asignacion sAsignacion = new S_Asignacion(); sAsignacion.id = Id; if (currentToken.Tipo == TipoToken.TK_MASMAS) sAsignacion.Op = new MasMas(); else if (currentToken.Tipo == TipoToken.TK_MENOSMENOS) sAsignacion.Op = new MenosMenos(); Expresiones Ex = Expr(); sAsignacion.Valor = Ex; return sAsignacion; } else { return null; } }
//Asume que no se ha consumido el ID Sentencia parseAssignOrCall() { string tmp = currentToken.Lexema; currentToken = lex.NextToken(); switch (currentToken.Tipo) { case TipoToken.TK_PUNTO: case TipoToken.TK_OPENCOR: { S_Asignacion ret = new S_Asignacion(); try { ret.id = new Variable(tmp, AccessList(tmp)); } catch (Exception ex) { throw ex; } if (currentToken.Tipo != TipoToken.TK_ASSIGN) throw new Exception("Se esperaba Asignacion."); else { currentToken = lex.NextToken(); try { ret.Valor = Expr(); } catch (Exception ex) { throw ex; } return ret; } } case TipoToken.TK_OPENPAR: { currentToken = lex.NextToken(); S_LlamadaFunc ret = new S_LlamadaFunc(); ret.Var = new Variable(tmp, null); ret.Variables = new ListaExpre(); try { ret.Variables.Ex = ExprList(); } catch (Exception ex) { throw ex; } if (currentToken.Tipo != TipoToken.TK_CLOSEPAR) throw new Exception("Se esperaba )."); else { currentToken = lex.NextToken(); return ret; } } default: throw new Exception("Sentencia no reconocida."); } }
public Sentencia StatementP2(Variable id) { if (currentToken.Tipo == Lexico.TipoToken.TK_ASSIGN) { S_Asignacion sasign = new S_Asignacion(); sasign.Op = new Igual(); sasign.id = id; currentToken = lex.NextToken(); sasign.Valor= Expression(); return sasign; } else if(currentToken.Tipo == Lexico.TipoToken.TK_MASIGUAL) { S_Asignacion sasign = new S_Asignacion(); sasign.Op = new MasIgual(); sasign.id = id; currentToken = lex.NextToken(); sasign.Valor = Expression(); return sasign; } else if(currentToken.Tipo == Lexico.TipoToken.TK_MENOSIGUAL) { S_Asignacion sasign = new S_Asignacion(); sasign.Op = new MenosIgual(); sasign.id = id; currentToken = lex.NextToken(); sasign.Valor = Expression(); return sasign; } else if(currentToken.Tipo == Lexico.TipoToken.TK_PORIGUAL) { S_Asignacion sasign = new S_Asignacion(); sasign.Op = new PorIgual(); sasign.id = id; currentToken = lex.NextToken(); sasign.Valor = Expression(); return sasign; } else if(currentToken.Tipo == Lexico.TipoToken.TK_ENTREIGUAL) { S_Asignacion sasign = new S_Asignacion(); sasign.Op = new EntreIgual(); sasign.id = id; currentToken = lex.NextToken(); sasign.Valor = Expression(); return sasign; } else if (currentToken.Tipo == Lexico.TipoToken.TK_OPENCOR) { currentToken = lex.NextToken(); S_Asignacion assig = new S_Asignacion(); assig.id = id; assig.id.acces=Expression(); if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSECOR) throw new Exception("Se esperaba el token ]"); Sentencia S = new Sentencia(); S=StatementP2(assig.id); assig.Valor = ((S_Asignacion)S).Valor; if(currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA) throw new Exception("Se esperaba el token ;"); currentToken = lex.NextToken(); return assig; } else if (currentToken.Tipo == Lexico.TipoToken.TK_MENOSMENOS || currentToken.Tipo == Lexico.TipoToken.TK_MASMAS) { S_Asignacion sAsignacion = new S_Asignacion(); sAsignacion.id = id; if (currentToken.Tipo == Lexico.TipoToken.TK_MASMAS) sAsignacion.Op = new MasMas(); else if (currentToken.Tipo == Lexico.TipoToken.TK_MENOSMENOS) sAsignacion.Op = new MenosMenos(); Expresiones Ex = Expression(); sAsignacion.Valor = Ex; return sAsignacion; } return null; }
public Sentencia DeclarationP(Sentencia campos) { if (currentToken.Tipo == Lexico.TipoToken.TK_COMA) { currentToken = lex.NextToken(); Campos c = new Campos(); if (currentToken.Tipo != Lexico.TipoToken.TK_ID) throw new Exception("Se esperaba el token ID"); c.Var.id = currentToken.Lexema; currentToken = lex.NextToken(); campos.sig=DeclarationP(c); return campos; } else if (currentToken.Tipo == Lexico.TipoToken.TK_ASSIGN) { S_Asignacion sasignacion = new S_Asignacion(); sasignacion.id.id = ((Campos)campos).Var.id; currentToken = lex.NextToken(); sasignacion.Valor= Expression(); return DeclarationP(sasignacion); } else if (currentToken.Tipo == Lexico.TipoToken.TK_OPENPAR) { S_Functions sfunciones = new S_Functions(); currentToken = lex.NextToken(); sfunciones.Retorno = ((Campos)campos).Tip; sfunciones.var.id = ((Campos)campos).Var.id; sfunciones.Campo= ParametroList(); if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSEPAR) throw new Exception("Se esperaba el token )"); currentToken = lex.NextToken(); sfunciones.S= CompoundStatement(); return sfunciones; } else if (currentToken.Tipo == Lexico.TipoToken.TK_FINSENTENCIA) { currentToken = lex.NextToken(); return campos; } else throw new Exception("Se esperaba el token ;"); }
public Sentencia SentenciaASSIGN_LLAMFUNC() { if (currentToken.Tipo == TipoToken.TK_ID) { Variable var = new Variable(currentToken.Lexema, null); currentToken = lex.NextToken(); if (currentToken.Tipo == TipoToken.TK_PUNTO || currentToken.Tipo == TipoToken.TK_OPENCOR) { try { Access a=Accesories(var.accesor); var.accesor = a; } catch (Exception ex) { throw ex; } } if (currentToken.Tipo == TipoToken.TK_ASSIGN || currentToken.Tipo == TipoToken.TK_MASIGUAL || currentToken.Tipo == TipoToken.TK_MENOSIGUAL || currentToken.Tipo == TipoToken.TK_PORIGUAL || currentToken.Tipo == TipoToken.TK_ENTREIGUAL) { S_Asignacion sAssig = new S_Asignacion(); if (currentToken.Tipo == TipoToken.TK_ASSIGN) sAssig.Op = new Igual(); else if (currentToken.Tipo == TipoToken.TK_MASIGUAL) sAssig.Op = new MasIgual(); else if (currentToken.Tipo == TipoToken.TK_MENOSIGUAL) sAssig.Op = new MenosIgual(); else if (currentToken.Tipo == TipoToken.TK_PORIGUAL) sAssig.Op = new PorIgual(); else if (currentToken.Tipo == TipoToken.TK_ENTREIGUAL) sAssig.Op = new EntreIgual(); currentToken = lex.NextToken(); sAssig.id = var; try { sAssig.Valor = Expr(); } catch (Exception ex) { throw ex; } if (currentToken.Tipo != TipoToken.TK_FINSENTENCIA) throw new Exception("Error Sintactico - Se esperaba fin sentencia"); currentToken = lex.NextToken(); return sAssig; } else if (currentToken.Tipo == TipoToken.TK_ID) { Declaracion Decl = new Declaracion(); Class TipClass = new Class(); TipClass.Nombre = var.id; Variable vVar = new Variable(currentToken.Lexema, null); Decl.Var = vVar; Decl.Tip = TipClass; currentToken = lex.NextToken(); if (currentToken.Tipo != TipoToken.TK_FINSENTENCIA) throw new Exception("Error Sintactico - Se esperaba fin sentencia"); currentToken = lex.NextToken(); return Decl; } else if(currentToken.Tipo == TipoToken.TK_OPENPAR) { currentToken = lex.NextToken(); S_LlamadaFunc sLlamadaFunc = new S_LlamadaFunc(); sLlamadaFunc.Var = var; if (currentToken.Tipo == TipoToken.TK_CLOSEPAR) { currentToken = lex.NextToken(); if (currentToken.Tipo != TipoToken.TK_FINSENTENCIA) throw new Exception("Error Sintactico - Se esperaba fin sentencia"); currentToken = lex.NextToken(); return sLlamadaFunc; } else { //VERIFICAR VIENE UN LITERAL O VARIABLE Y AGREGARLO LUEGO LLAMAR EXPRLIST PARA QUE AGREGUE LO DEMAS Y VERIFICAR CLOSEPAR if (currentToken.Tipo == TipoToken.TK_ID || currentToken.Tipo == TipoToken.TK_INT_LIT || currentToken.Tipo == TipoToken.TK_FLOAT_LIT || currentToken.Tipo == TipoToken.TK_STRING_LIT || currentToken.Tipo == TipoToken.TK_CHAR_LIT) { ListaExpre listaExpre = new ListaExpre(); try { listaExpre.Ex.Add(Expr()); } catch(Exception ex) { throw ex; } if (currentToken.Tipo == TipoToken.TK_COMA) { try { sLlamadaFunc.Variables = ExprList(listaExpre); } catch(Exception ex) { throw ex; } if (currentToken.Tipo == TipoToken.TK_CLOSEPAR) { currentToken = lex.NextToken(); if (currentToken.Tipo != TipoToken.TK_FINSENTENCIA) throw new Exception("Error Sintactico - Se esperaba fin sentencia"); currentToken = lex.NextToken(); return sLlamadaFunc; } else { throw new Exception("Error Sintatico - Se esperaba simbolo )"); } } else { sLlamadaFunc.Variables = listaExpre; if (currentToken.Tipo == TipoToken.TK_CLOSEPAR) { currentToken = lex.NextToken(); if (currentToken.Tipo != TipoToken.TK_FINSENTENCIA) throw new Exception("Error Sintactico - Se esperaba fin sentencia"); currentToken = lex.NextToken(); return sLlamadaFunc; } else { throw new Exception("Error Sintatico - Se esperaba simbolo )"); } } } } } else if (currentToken.Tipo == TipoToken.TK_MASMAS) { currentToken = lex.NextToken(); s_masmas sMasmas = new s_masmas(); ExpMasMas expMasMas = new ExpMasMas(); expMasMas.ID = var; sMasmas.param = expMasMas; return sMasmas; } else if (currentToken.Tipo == TipoToken.TK_MENOSMENOS) { currentToken = lex.NextToken(); s_menosmenos sMenosmenos = new s_menosmenos(); ExpMenosMenos expMenosMenos = new ExpMenosMenos(); expMenosMenos.ID = var; sMenosmenos.param = expMenosMenos; return sMenosmenos; } else { if (currentToken.Tipo != TipoToken.TK_FINSENTENCIA) throw new Exception("Error Sintactico - Se esperaba fin sentencia"); currentToken = lex.NextToken(); if (var.accesor.Last() is AccessFunc) { S_LlamadaFunc sLlamadaFunc = new S_LlamadaFunc(); sLlamadaFunc.Var = var; return sLlamadaFunc; } } } return null; }
public Sentencia SentenciaAssign_LlamaFun() { try { if (currentToken.Tipo == Lexico.TipoToken.TK_ID) { Variable var = new Variable(currentToken.Lexema, null); currentToken = lex.NextToken(); if (currentToken.Tipo == Lexico.TipoToken.TK_PUNTO || currentToken.Tipo == Lexico.TipoToken.TK_OPENCOR || currentToken.Tipo == Lexico.TipoToken.TK_OPENPAR) { Access a = Accesories(var.accesor); var.accesor = a; } if (currentToken.Tipo == Lexico.TipoToken.TK_ASSIGN || currentToken.Tipo == Lexico.TipoToken.TK_MASIGUAL || currentToken.Tipo == Lexico.TipoToken.TK_MENORIGUAL || currentToken.Tipo == Lexico.TipoToken.TK_PORIGUAL || currentToken.Tipo == Lexico.TipoToken.TK_ENTREIGUAL) { S_Asignacion sAsignacion = new S_Asignacion(); if (currentToken.Tipo == Lexico.TipoToken.TK_ASSIGN) sAsignacion.Op = new Igual(); else if (currentToken.Tipo == Lexico.TipoToken.TK_MASIGUAL) sAsignacion.Op = new MasIgual(); else if (currentToken.Tipo == Lexico.TipoToken.TK_MENOSIGUAL) sAsignacion.Op = new MenosIgual(); else if (currentToken.Tipo == Lexico.TipoToken.TK_PORIGUAL) sAsignacion.Op = new PorIgual(); else if (currentToken.Tipo == Lexico.TipoToken.TK_ENTREIGUAL) sAsignacion.Op = new EntreIgual(); currentToken = lex.NextToken(); sAsignacion.id = var; sAsignacion.Valor = Expression(); return sAsignacion; } else if (currentToken.Tipo == Lexico.TipoToken.TK_ID) { Declaracion decl = new Declaracion(); Struct str = new Struct(); str.nombre = var.id; Variable vVar = new Variable(currentToken.Lexema, null); decl.Var = vVar; decl.Tip = str; currentToken = lex.NextToken(); if (currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA) throw new Exception("Error Sintactico --Se esperaba ;"); return decl; } else { if (currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA) throw new Exception("Error Sintactico --Se esperaba ;"); //if (var.accesor.Last() is AccessFunc) //{ S_LlamadaFunc sllamadafunc = new S_LlamadaFunc(); sllamadafunc.Var = var; return sllamadafunc; //} } } return null; } catch (Exception ex) { throw ex; } }