Ejemplo n.º 1
0
 Expresiones LIT()
 {
     switch (currentToken.Tipo)
     {
         case TipoToken.TK_INT_LIT:
             LiteralEntero asd = new LiteralEntero(int.Parse(currentToken.Lexema));
             currentToken = lex.NextToken();
             return asd;
         case TipoToken.TK_FLOAT_LIT:
             LiteralFlotante flo = new LiteralFlotante(float.Parse(currentToken.Lexema));
             currentToken = lex.NextToken();
             return flo;
         case TipoToken.TK_CHAR_LIT:
             string car = currentToken.Lexema;
             currentToken = lex.NextToken();
             return new LitChar(car);
         case TipoToken.TK_STRING_LIT:
             string cad = currentToken.Lexema;
             currentToken = lex.NextToken();
             return new LitString(cad);
         case TipoToken.TK_TRUE:
             currentToken = lex.NextToken();
             return new LitBool(true);
         case TipoToken.TK_FALSE:
             currentToken = lex.NextToken();
             return new LitBool(false);
         default:
             throw new Exception("Se esperaba una literal");
     }
 }
Ejemplo n.º 2
0
        public Expresiones Parexp()
        {
            try
            {
                if (currentToken.Tipo == Lexico.TipoToken.TK_INT_LIT)
                {
                    LiteralEntero lit = new LiteralEntero(Convert.ToInt32(currentToken.Lexema));
                    currentToken = lex.NextToken();
                    return lit;
                }
                else if (currentToken.Tipo == Lexico.TipoToken.TK_FLOAT_LIT)
                {
                    LiteralFlotante lit = new LiteralFlotante(float.Parse(currentToken.Lexema));
                    currentToken = lex.NextToken();
                    return lit;
                }
                else if (currentToken.Tipo == Lexico.TipoToken.TK_CHAR_LIT)
                {
                    LitChar lit = new LitChar(currentToken.Lexema);
                    currentToken = lex.NextToken();
                    return lit;
                }
                else if (currentToken.Tipo == Lexico.TipoToken.TK_STRING_LIT)
                {
                    LitString lit = new LitString(currentToken.Lexema);
                    currentToken = lex.NextToken();
                    return lit;
                }
                else if (currentToken.Tipo == Lexico.TipoToken.TK_TRUE)
                {
                    LitBool lit = new LitBool(true);
                    currentToken = lex.NextToken();
                    return lit;
                }
                else if (currentToken.Tipo == Lexico.TipoToken.TK_FALSE)
                {
                    LitBool lit = new LitBool(false);
                    currentToken = lex.NextToken();
                    return lit;
                }
                else if (currentToken.Tipo == Lexico.TipoToken.TK_ID)
                {
                    ExprFuncion V = new ExprFuncion();
                    V.ID = new Variable(currentToken.Lexema, null);
                    currentToken = lex.NextToken();
                    if (currentToken.Tipo == Lexico.TipoToken.TK_PUNTO || currentToken.Tipo == Lexico.TipoToken.TK_ID || currentToken.Tipo == Lexico.TipoToken.TK_OPENPAR || currentToken.Tipo == Lexico.TipoToken.TK_OPENCOR)
                    {
                        try
                        {
                            V.ID.accesor = Accesories(V.ID.accesor);
                            Access tmp = ((Access)V.ID.accesor);
                            if (tmp.Next != null)
                            {
                                tmp = tmp.Last();
                            }
                            if (V.ID.accesor != null && tmp is AccessFunc)
                            {
                                AccessFunc v = ((AccessFunc)tmp);
                                V.VarList = v.Variables;
                                return V;
                            }
                            else
                                return V.ID;
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    else
                    {
                        return V.ID;
                    }
                }
                return null;

                /*
                ExprFuncion V = new ExprFuncion();
                V.ID = new Variable(currentToken.Lexema, null);
                currentToken = lex.NextToken();
                V.ID.accesor = Accesories(V.ID.accesor);
                if (V.ID.accesor != null)
                    return V;
                else
                    return V.ID;
                */

                // return null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }