Example #1
0
 public Expresiones Relexp_prime(Expresiones E)
 {
     try
     {
         if (currentToken.Tipo == Lexico.TipoToken.TK_IGUALDAD)
         {
             currentToken = lex.NextToken();
             Equal equal = new Equal(E, Addexp());
             return equal;
         }
         else if (currentToken.Tipo == Lexico.TipoToken.TK_DISTINTO)
         {
             currentToken = lex.NextToken();
             Distinto dist = new Distinto(E, Addexp());
             return dist;
         }
         else if (currentToken.Tipo == Lexico.TipoToken.TK_MAYORQUE)
         {
             currentToken = lex.NextToken();
             Expresiones x = Addexp();
             MayorQue mayorQ = new MayorQue(E, x);
             return mayorQ; ;
         }
         else if (currentToken.Tipo == Lexico.TipoToken.TK_MAYORIGUAL)
         {
             currentToken = lex.NextToken();
             MayorIgual mayorI = new MayorIgual(E, Addexp());
             return mayorI;
         }
         else if (currentToken.Tipo == Lexico.TipoToken.TK_MENORQUE)
         {
             currentToken = lex.NextToken();
             MenorQue menorQ = new MenorQue(E, Addexp());
             return menorQ;
         }
         else if (currentToken.Tipo == Lexico.TipoToken.TK_MENORIGUAL)
         {
             currentToken = lex.NextToken();
             MenorIgual menorI = new MenorIgual(E, Addexp());
             return menorI;
         }
         else if (currentToken.Tipo == Lexico.TipoToken.TK_MASMAS)
         {
             ExpMasMas mas = new ExpMasMas();
             if (E is Variable)
             {
                 Variable v = ((Variable)E);
                 mas.ID = v;
                 currentToken = lex.NextToken();
             }
             return mas;
         }
         else if (currentToken.Tipo == Lexico.TipoToken.TK_MENOSMENOS)
         {
             ExpMenosMenos menos = new ExpMenosMenos();
             if (E is Variable)
             {
                 Variable v = ((Variable)E);
                 menos.ID = v;
                 currentToken = lex.NextToken();
             }
             return menos;
         }
         return E;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #2
0
 S_For parseFor()
 {
     S_For ret = new S_For();
     ret.Tip = new Entero();
     if (currentToken.Tipo != TipoToken.TK_ID)
         throw new Exception("Se esperaba identificador.");
     else
     {
         ret.Var = new Variable(currentToken.Lexema, null);
         currentToken = lex.NextToken();
         if (currentToken.Tipo != TipoToken.TK_ASSIGN)
             throw new Exception("Se esperaba el operador de asignacion");
         else
         {
             currentToken = lex.NextToken();
             try
             {
                 ret.Inicio = Expr();
             }
             catch (Exception ex) { throw ex; }
             switch (currentToken.Tipo)
             {
                 case TipoToken.TK_TO:
                     currentToken = lex.NextToken();
                     MenorQue cond;
                     try
                     {
                         cond = new MenorQue(ret.Var, Expr());
                     }
                     catch (Exception ex) { throw ex; }
                     ExpMasMas it = new ExpMasMas();
                     it.ID = ret.Var;
                     ret.Condicion = cond;
                     ret.Iteracion = it;
                     break;
                 case TipoToken.TK_DOWNTO:
                     currentToken = lex.NextToken();
                     MayorQue cond1;
                     try
                     {
                         cond1 = new MayorQue(ret.Var, Expr());
                     }
                     catch (Exception ex) { throw ex; }
                     ExpMenosMenos it1 = new ExpMenosMenos();
                     it1.ID = ret.Var;
                     ret.Condicion = cond1;
                     ret.Iteracion = it1;
                     break;
                 default:
                     throw new Exception("Se esperaba to/Downto");
             }
             if (currentToken.Tipo != TipoToken.TK_DO)
                 throw new Exception("Se esperaba do.");
             else
             {
                 currentToken = lex.NextToken();
                 try
                 {
                     ret.S = CodeBlock();
                 }
                 catch (Exception ex) { throw ex; }
                 return ret;
             }
         }
     }
 }
Example #3
0
        public Expresiones RelExprP(Expresiones E)
        {
            try
            {
                if (currentToken.Tipo == TipoToken.TK_IGUALDAD)
                {
                    currentToken = lex.NextToken();
                    Equal eEqual = new Equal(E, AddExpr());
                    return eEqual;
                }
                else if (currentToken.Tipo == TipoToken.TK_DISTINTO)
                {
                    currentToken = lex.NextToken();
                    Distinto eDist = new Distinto(E, AddExpr());

                    return eDist;
                }
                else if (currentToken.Tipo == TipoToken.TK_MAYORQUE)
                {
                    currentToken = lex.NextToken();
                    MayorQue eMayQ = new MayorQue(E, AddExpr());

                    return eMayQ;
                }
                else if (currentToken.Tipo == TipoToken.TK_MENORQUE)
                {
                    currentToken = lex.NextToken();
                    MenorQue eMenQ = new MenorQue(E, AddExpr());

                    return eMenQ;
                }
                else if (currentToken.Tipo == TipoToken.TK_MENORIGUAL)
                {
                    currentToken = lex.NextToken();
                    MenorIgual eMenI = new MenorIgual(E, AddExpr());

                    return eMenI;
                }
                else if (currentToken.Tipo == TipoToken.TK_MAYORIGUAL)
                {
                    currentToken = lex.NextToken();
                    MayorIgual eMayI = new MayorIgual(E, AddExpr());

                    return eMayI;
                }
                else if (currentToken.Tipo == TipoToken.TK_MASMAS)
                {
                    ExpMasMas mas = new ExpMasMas();
                    if (E is Variable)
                    {
                        Variable v = ((Variable)E);
                        mas.ID = v;
                        currentToken = lex.NextToken();
                    }
                    return mas;
                }
                else if (currentToken.Tipo == TipoToken.TK_MENOSMENOS)
                {
                    ExpMenosMenos menos = new ExpMenosMenos();
                    if (E is Variable)
                    {
                        Variable v = ((Variable)E);
                        menos.ID = v;
                        currentToken = lex.NextToken();
                    }
                    return menos;
                }
                else
                {
                    return E;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }