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; } }
public Sentencia StatementP(Variable Id) { if (currentToken.Tipo == TipoToken.TK_OPENPAR) { S_LlamadaFunc sLlamadaFunc = new S_LlamadaFunc(); sLlamadaFunc.Var = Id; currentToken = lex.NextToken(); sLlamadaFunc.VarList = ExprList(); if (currentToken.Tipo == TipoToken.TK_CLOSEPAR) { currentToken = lex.NextToken(); return sLlamadaFunc; } else { throw new Exception("Error Sintactico - Falta simbolo )"); } } else { Sentencia S =new Sentencia(); S = StatementP2(Id); return S; } }
public Sentencia DeclarationP(Sentencia C) { if (currentToken.Tipo == TipoToken.TK_COMA) { currentToken = lex.NextToken(); Campos CP = new Campos(); if (currentToken.Tipo == TipoToken.TK_ID) { Variable Var = new Variable(); Var.id = currentToken.Lexema; currentToken = lex.NextToken(); C.sig = DeclarationP(CP); return C; } else { throw new Exception("Error Sintactico - Se esperaba un identificador"); } } else if (currentToken.Tipo == TipoToken.TK_ASSIGN) { return AssignDeclaration(C); } else if (currentToken.Tipo == TipoToken.TK_OPENPAR) { currentToken = lex.NextToken(); S_Functions sFunctions = new S_Functions(); sFunctions.Retorno = ((Campos)C).Tip; sFunctions.var.id = ((Campos)C).Var.id; sFunctions.Campo = ParameterList(); if (currentToken.Tipo == TipoToken.TK_CLOSEPAR) { currentToken = lex.NextToken(); sFunctions.S = CompoundStatement(); return sFunctions; } else { throw new Exception("Error Sintactico - Se esperaba simbolo )"); } } else if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA) { currentToken = lex.NextToken(); return C; } else { throw new Exception("Error Sintactico - Se esperaba un fin sentencia"); } }
public Sentencia Statement() { if (currentToken.Tipo == TipoToken.TK_PRINT) { #region Print currentToken = lex.NextToken(); if (currentToken.Tipo == TipoToken.TK_OPENPAR) { currentToken = lex.NextToken(); S_Print sPrint = new S_Print(); sPrint.Expr = Expr(); if (currentToken.Tipo == TipoToken.TK_CLOSEPAR) { currentToken = lex.NextToken(); if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA) { currentToken = lex.NextToken(); return sPrint; } 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 if (currentToken.Tipo == TipoToken.TK_IF) { #region If currentToken = lex.NextToken(); if (currentToken.Tipo == TipoToken.TK_OPENPAR) { currentToken = lex.NextToken(); S_If sIf = new S_If(); sIf.Condicion = Expr(); if (currentToken.Tipo == TipoToken.TK_CLOSEPAR) { currentToken = lex.NextToken(); sIf.Cierto = CompoundStatement(); sIf.Falso = ELSE(); return sIf; } else { throw new Exception("Error Sintactico - Se esperaba simbolo )"); } } else { throw new Exception("Error Sintactico - Se esperaba simbolo ("); } #endregion } else if (currentToken.Tipo == TipoToken.TK_WHILE) { #region While currentToken = lex.NextToken(); if (currentToken.Tipo == TipoToken.TK_OPENPAR) { currentToken = lex.NextToken(); S_While sWhile = new S_While(); sWhile.Condicion = Expr(); if (currentToken.Tipo == TipoToken.TK_CLOSEPAR) { currentToken = lex.NextToken(); sWhile.S = CompoundStatement(); return sWhile; } else { throw new Exception("Error Sintactico - Se esperaba simbolo )"); } } else { throw new Exception("Error Sintactico - Se esperaba simbolo ("); } #endregion } else if (currentToken.Tipo == TipoToken.TK_DO) { #region Do currentToken = lex.NextToken(); S_Do sDo = new S_Do(); sDo.S = CompoundStatement(); if (currentToken.Tipo == TipoToken.TK_WHILE) { currentToken = lex.NextToken(); if (currentToken.Tipo == TipoToken.TK_OPENPAR) { currentToken = lex.NextToken(); sDo.Condicion = Expr(); if (currentToken.Tipo == TipoToken.TK_CLOSEPAR) { currentToken = lex.NextToken(); if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA) { currentToken = lex.NextToken(); return sDo; } 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 ("); } } else { throw new Exception("Error Sintactico - Se esperaba palabra fin de ciclo While"); } #endregion } else if (currentToken.Tipo == TipoToken.TK_FOR) { #region For currentToken = lex.NextToken(); if (currentToken.Tipo == TipoToken.TK_OPENPAR) { currentToken = lex.NextToken(); S_For sFor = new S_For(); if (currentToken.Tipo == TipoToken.TK_CHAR || currentToken.Tipo == TipoToken.TK_FLOAT || currentToken.Tipo == TipoToken.TK_INT) { sFor.Tip = Type(); } if (currentToken.Tipo == TipoToken.TK_ID) { sFor.Var.id = currentToken.Lexema; currentToken = lex.NextToken(); if (currentToken.Tipo == TipoToken.TK_ASSIGN) { currentToken = lex.NextToken(); sFor.Inicio = Expr(); if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA) { currentToken = lex.NextToken(); sFor.Condicion = Expr(); if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA) { currentToken = lex.NextToken(); sFor.Iteracion = Expr(); if (currentToken.Tipo == TipoToken.TK_CLOSEPAR) { currentToken = lex.NextToken(); sFor.S = CompoundStatement(); return sFor; } 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 ;"); } } else { throw new Exception("Error Sintactico - Se esperaba simbolo asignacion ="); } } else { throw new Exception("Error Sintactico - Se esperaba un Identificador"); } } else { throw new Exception("Error Sintactico - Se esperaba simbolo ("); } #endregion } else if (currentToken.Tipo == TipoToken.TK_RETURN) { #region Return currentToken = lex.NextToken(); S_Return sReturn = new S_Return(); sReturn.Expr = Expr(); if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA) { currentToken = lex.NextToken(); return sReturn; } else { throw new Exception("Error Sintactico - Se esperaba simbolo ;"); } #endregion } else if (currentToken.Tipo == TipoToken.TK_BREAK) { #region Break currentToken = lex.NextToken(); if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA) { S_Break sBreak = new S_Break(); currentToken = lex.NextToken(); return sBreak; } else { throw new Exception("Error Sintactico - Se esperaba simbolo ;"); } #endregion } else if (currentToken.Tipo == TipoToken.TK_ID) { #region Id Sentencia S = new Sentencia(); Variable Id = new Variable(); Id.id = currentToken.Lexema; currentToken = lex.NextToken(); S = StatementP(Id); if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA) { currentToken = lex.NextToken(); return S; } else { throw new Exception("Error Sintactico - Se esperaba simbolo ;"); } #endregion } else if (currentToken.Tipo == TipoToken.TK_CHAR || currentToken.Tipo == TipoToken.TK_BOOL || currentToken.Tipo == TipoToken.TK_STRING || currentToken.Tipo == TipoToken.TK_FLOAT || currentToken.Tipo == TipoToken.TK_INT || currentToken.Tipo == TipoToken.TK_PRIVATE || currentToken.Tipo == TipoToken.TK_PUBLIC) { #region Declaraciones Sentencia S = new Sentencia(); S = Declaration(); return S; #endregion } else if (currentToken.Tipo == Lexico.TipoToken.TK_SWITCH) { #region Switch currentToken = lex.NextToken(); if (currentToken.Tipo != Lexico.TipoToken.TK_OPENPAR) throw new Exception("Error Sintactico - Se esperaba un ("); currentToken = lex.NextToken(); S_Switch sSwitch = new S_Switch(); sSwitch.Var = Expr(); if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSEPAR) throw new Exception("Error Sintactico - Se esperaba una )"); currentToken = lex.NextToken(); if (currentToken.Tipo != Lexico.TipoToken.TK_OPENLLAVE) throw new Exception("Error Sintactico - Se esperaba una {"); currentToken = lex.NextToken(); sSwitch.Casos = Cases(); if (currentToken.Tipo != Lexico.TipoToken.TK_DEFAULT) throw new Exception("Error Sintactico - Se esperaba la palabra reservada DEFAULT"); currentToken = lex.NextToken(); if (currentToken.Tipo != Lexico.TipoToken.TK_DOSPUNTOS) throw new Exception("Error Sintactico - Se esperaba el simbolo :"); currentToken = lex.NextToken(); sSwitch.sdefault = StatementList(); if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSELLAVE) throw new Exception("Error Sintactico - Se esperaba una }"); currentToken = lex.NextToken(); return sSwitch; #endregion } else if (currentToken.Tipo == TipoToken.TK_CLASS) { return Clases(); } return null; }
public Sentencia CompoundStatement() { if (currentToken.Tipo == Lexico.TipoToken.TK_OPENLLAVE) { currentToken = lex.NextToken(); Sentencia S = new Sentencia(); S=StatementList(); if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSELLAVE) throw new Exception("Se esperaba una }"); currentToken = lex.NextToken(); return S; } return null; }
public Sentencia CompoundStatement() { if (currentToken.Tipo == TipoToken.TK_OPENLLAVE) { currentToken = lex.NextToken(); Sentencia S = new Sentencia(); S = StatementList(); if (currentToken.Tipo == TipoToken.TK_CLOSELLAVE) { currentToken = lex.NextToken(); return S; } else { throw new Exception("Error Sintactico - Se esperaba simbolo }"); } } else { return null; } }
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 StatementP(Variable id) { if (currentToken.Tipo == Lexico.TipoToken.TK_OPENPAR) { S_LlamadaFunc sfunc = new S_LlamadaFunc(); sfunc.Var=id; currentToken = lex.NextToken(); sfunc.VarList= ExpreList(); if (currentToken.Tipo == Lexico.TipoToken.TK_CLOSEPAR) { currentToken = lex.NextToken(); return sfunc; } else throw new Exception("Se esperaba el token )"); } else { Sentencia S = new Sentencia(); S=StatementP2(id); return S; } }
public Sentencia Statement() { if (this.currentToken.Tipo == Lexico.TipoToken.TK_PRINT) { this.currentToken = lex.NextToken(); if (currentToken.Tipo != Lexico.TipoToken.TK_OPENPAR) throw new Exception("Se esperaba un ("); S_Print sprint = new S_Print(); sprint.Expr = Expression(); if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSEPAR) throw new Exception("Se esperaba un )"); this.currentToken = lex.NextToken(); if (currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA) throw new Exception("Se esperaba un ;"); this.currentToken = lex.NextToken(); return sprint; } else if (this.currentToken.Tipo == Lexico.TipoToken.TK_READ) { this.currentToken = lex.NextToken(); if (currentToken.Tipo != Lexico.TipoToken.TK_OPENPAR) throw new Exception("Se esperaba un ("); this.currentToken = lex.NextToken(); if (currentToken.Tipo != Lexico.TipoToken.TK_ID) throw new Exception("Se esperaba un ID"); S_Read sread = new S_Read(); sread.var.id = currentToken.Lexema; this.currentToken = lex.NextToken(); if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSEPAR) throw new Exception("Se esperaba un )"); this.currentToken = lex.NextToken(); if (currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA) throw new Exception("Se esperaba un ;"); this.currentToken = lex.NextToken(); return sread; } else if (this.currentToken.Tipo == Lexico.TipoToken.TK_IF) { S_If sif = new S_If(); this.currentToken = lex.NextToken(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_OPENPAR) throw new Exception("Se esperaba un ("); this.currentToken = lex.NextToken(); sif.Condicion = Expression(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_CLOSEPAR) throw new Exception("Se esperaba un )"); this.currentToken = lex.NextToken(); sif.Cierto = CompoundStatement(); sif.Falso = Else(); return sif; } else if (this.currentToken.Tipo == Lexico.TipoToken.TK_WHILE) { S_While swhile = new S_While(); this.currentToken = lex.NextToken(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_OPENPAR) throw new Exception("Se esperaba un ("); this.currentToken = lex.NextToken(); swhile.Condicion = Expression(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_CLOSEPAR) throw new Exception("Se esperaba un )"); this.currentToken = lex.NextToken(); swhile.S = CompoundStatement(); return swhile; } else if (this.currentToken.Tipo == Lexico.TipoToken.TK_DO) { S_Do sdo = new S_Do(); this.currentToken = lex.NextToken(); sdo.S = CompoundStatement(); if (this.currentToken.Tipo == Lexico.TipoToken.TK_WHILE) { this.currentToken = lex.NextToken(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_OPENPAR) throw new Exception("Se esperaba un ("); this.currentToken = lex.NextToken(); sdo.Condicion = Expression(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_CLOSEPAR) throw new Exception("Se esperaba un )"); this.currentToken = lex.NextToken(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA) throw new Exception("Se esperaba un ;"); this.currentToken = lex.NextToken(); return sdo; } else throw new Exception("Se esperaba la palabra reservada WHILE"); } else if (this.currentToken.Tipo == Lexico.TipoToken.TK_FOR) { S_For sfor = new S_For(); this.currentToken = lex.NextToken(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_OPENPAR) throw new Exception("Se esperaba un ("); this.currentToken = lex.NextToken(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_ID) throw new Exception("Se esperaba un ID"); sfor.Var.id = this.currentToken.Lexema; this.currentToken = lex.NextToken(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_ASSIGN) throw new Exception("Se esperaba el simbolo ="); this.currentToken = lex.NextToken(); sfor.Inicio = Expression(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA) throw new Exception("Se esperaba un ;"); this.currentToken = lex.NextToken(); sfor.Condicion = Expression(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA) throw new Exception("Se esperaba un ;"); this.currentToken = lex.NextToken(); sfor.Iteracion = Expression(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_CLOSEPAR) throw new Exception("Se esperaba un )"); this.currentToken = lex.NextToken(); sfor.S = CompoundStatement(); return sfor; } else if (this.currentToken.Tipo == Lexico.TipoToken.TK_RETURN) { S_Return sreturn = new S_Return(); this.currentToken = lex.NextToken(); sreturn.Expr=Expression(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA) throw new Exception("Se esperaba un ;"); this.currentToken = lex.NextToken(); return sreturn; } else if (this.currentToken.Tipo == Lexico.TipoToken.TK_BREAK) { S_Break sbreak = new S_Break(); this.currentToken = lex.NextToken(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA) throw new Exception("Se esperaba un ;"); this.currentToken = lex.NextToken(); return sbreak; } else if (this.currentToken.Tipo == Lexico.TipoToken.TK_SWITCH) { S_Switch sSwitch = new S_Switch(); this.currentToken = lex.NextToken(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_OPENPAR) throw new Exception("Se esperaba un ("); this.currentToken = lex.NextToken(); sSwitch.Var= Expression(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_CLOSEPAR) throw new Exception("Se esperaba una )"); this.currentToken = lex.NextToken(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_OPENLLAVE) throw new Exception("Se esperaba una {"); this.currentToken = lex.NextToken(); sSwitch.Casos= Cases(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_DEFAULT) throw new Exception("Se esperaba la palabra reservada DEFAULT"); this.currentToken = lex.NextToken(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_DOSPUNTOS) throw new Exception("Se esperaba el simbolo :"); this.currentToken = lex.NextToken(); sSwitch.sdefault=StatementList(); if (this.currentToken.Tipo != Lexico.TipoToken.TK_CLOSELLAVE) throw new Exception("Se esperaba una }"); this.currentToken = lex.NextToken(); return sSwitch; } else if (currentToken.Tipo == Lexico.TipoToken.TK_ID) { Sentencia S = new Sentencia(); Variable Id = new Variable(); Id.id= currentToken.Lexema; currentToken = lex.NextToken(); S=StatementP(Id); if (currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA) throw new Exception("Se esperaba el simbolo ;"); currentToken = lex.NextToken(); return S; } else if (currentToken.Tipo == Lexico.TipoToken.TK_PUBLIC || currentToken.Tipo == Lexico.TipoToken.TK_PRIVATE) { currentToken = lex.NextToken(); Sentencia s = new Sentencia(); s=Declaration(); return s; } else if (currentToken.Tipo == Lexico.TipoToken.TK_INT || currentToken.Tipo == Lexico.TipoToken.TK_FLOAT || currentToken.Tipo == Lexico.TipoToken.TK_CHAR || currentToken.Tipo == Lexico.TipoToken.TK_TRUE || currentToken.Tipo == Lexico.TipoToken.TK_FALSE) { Sentencia s = new Sentencia(); s = Declaration(); return s; } 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 ListaDeclaracion(Sentencia Decls) { if (currentToken.Tipo == TipoToken.TK_CHAR || currentToken.Tipo == TipoToken.TK_BOOL || currentToken.Tipo == TipoToken.TK_STRING || currentToken.Tipo == TipoToken.TK_FLOAT || currentToken.Tipo == TipoToken.TK_INT || currentToken.Tipo == TipoToken.TK_PRIVATE || currentToken.Tipo == TipoToken.TK_PUBLIC || currentToken.Tipo == TipoToken.TK_CLASS || currentToken.Tipo == TipoToken.TK_VOID) { try { Decls = Declaraciones(); Decls.sig = ListaDeclaracion(Decls); } catch (Exception ex) { throw ex; } return Decls; } else if (currentToken.Tipo == TipoToken.TK_ID) { try { Decls = DeclaracionesClase(); Decls.sig = ListaDeclaracion(Decls); } catch (Exception ex) { throw ex; } return Decls; } return null; }