예제 #1
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;
             }
         }
     }
 }
예제 #2
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;
            }
        }
예제 #3
0
        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;
        }
예제 #4
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;
     }
 }