Beispiel #1
0
        public Expresiones ParExpr()
        {
            if (currentToken.Tipo == TipoToken.TK_ID)
            {
                Variable V = new Variable();
                V.id = currentToken.Lexema;
                currentToken = lex.NextToken();
                StatementP(V);
                return V;

            }
            else if (currentToken.Tipo == TipoToken.TK_INT_LIT)
            {
                LiteralEntero LE = new LiteralEntero(Convert.ToInt32(currentToken.Lexema));
                currentToken = lex.NextToken();
                return LE;
            }
            else if (currentToken.Tipo == TipoToken.TK_FLOAT_LIT)
            {
                LiteralFlotante LF = new LiteralFlotante(float.Parse(currentToken.Lexema));
                currentToken = lex.NextToken();
                return LF;
            }
            else if (currentToken.Tipo == TipoToken.TK_STRING_LIT)
            {
                LitString LS = new LitString(currentToken.Lexema);
                currentToken = lex.NextToken();
                return LS;
            }
            else if (currentToken.Tipo == TipoToken.TK_CHAR_LIT)
            {
                LitChar LC = new LitChar(currentToken.Lexema);
                currentToken = lex.NextToken();
                return LC;
            }
            else if (currentToken.Tipo == TipoToken.TK_TRUE)
            {
                LitBool LB = new LitBool(true);
                currentToken = lex.NextToken();
                return LB;
            }
            else if (currentToken.Tipo == TipoToken.TK_FALSE)
            {
                LitBool LB = new LitBool(false);
                currentToken = lex.NextToken();
                return LB;
            }
            else if (currentToken.Tipo == TipoToken.TK_OPENPAR)
            {
                currentToken = lex.NextToken();
                Expresiones EX = Expr();
                if (currentToken.Tipo == TipoToken.TK_CLOSEPAR)
                {
                    currentToken = lex.NextToken();
                    return EX;
                }
                else
                {
                    throw new Exception("Error Sintactico - Se esperaba simbolo )");
                }
            }
            else if (currentToken.Tipo == TipoToken.TK_MASMAS || currentToken.Tipo == TipoToken.TK_MENOSMENOS)
            {
                currentToken = lex.NextToken();
            }

            return null;
        }
Beispiel #2
0
        public Expresiones ParExpr()
        {
            if (currentToken.Tipo == TipoToken.TK_INT_LIT)
            {
                LiteralEntero LE = new LiteralEntero(Convert.ToInt32(currentToken.Lexema));
                currentToken = lex.NextToken();
                return LE;
            }
            else if (currentToken.Tipo == TipoToken.TK_FLOAT_LIT)
            {
                LiteralFlotante LF = new LiteralFlotante(float.Parse(currentToken.Lexema));
                currentToken = lex.NextToken();
                return LF;
            }
            else if (currentToken.Tipo == TipoToken.TK_STRING_LIT)
            {
                LitString LS = new LitString(currentToken.Lexema);
                currentToken = lex.NextToken();
                return LS;
            }
            else if (currentToken.Tipo == TipoToken.TK_CHAR_LIT)
            {
                LitChar LC = new LitChar(currentToken.Lexema);
                currentToken = lex.NextToken();
                return LC;
            }
            else if (currentToken.Tipo == TipoToken.TK_TRUE)
            {
                LitBool LB = new LitBool(true);
                currentToken = lex.NextToken();
                return LB;
            }
            else if (currentToken.Tipo == TipoToken.TK_FALSE)
            {
                LitBool LB = new LitBool(false);
                currentToken = lex.NextToken();
                return LB;
            }
            else if (currentToken.Tipo == TipoToken.TK_ID)
            {

                ExprFuncion V = new ExprFuncion();
                V.ID = new Variable(currentToken.Lexema, null);
                currentToken = lex.NextToken();
                if (currentToken.Tipo == TipoToken.TK_MASMAS)
                {
                    currentToken = lex.NextToken();
                    ExpMasMas expMasMas = new ExpMasMas();
                    expMasMas.ID = V.ID;
                    return expMasMas;
                }
                else if (currentToken.Tipo == TipoToken.TK_MENOSMENOS)
                {
                    currentToken = lex.NextToken();
                    ExpMasMas expMasMas = new ExpMasMas();
                    expMasMas.ID = V.ID;
                    return expMasMas;
                }
                else if (currentToken.Tipo == TipoToken.TK_PUNTO || currentToken.Tipo == TipoToken.TK_ID || currentToken.Tipo == TipoToken.TK_OPENPAR || currentToken.Tipo == 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;
        }
Beispiel #3
0
        public Expresiones Parexp()
        {
            if (currentToken.Tipo == Lexico.TipoToken.TK_OPENPAR)
            {
                currentToken = lex.NextToken();
                Expression();
                if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSEPAR)
                    throw new Exception("Se esperaba un )");

                currentToken = lex.NextToken();
            }
            else 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_ID)
            {
                Variable v = new Variable();
                v.id = currentToken.Lexema;
                currentToken = lex.NextToken();
                StatementP(v);
                return v;

            }
            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_MASMAS)
            {
                currentToken = lex.NextToken();
            }
            else if (currentToken.Tipo == Lexico.TipoToken.TK_MENOSMENOS)
            {
                currentToken = lex.NextToken();
            }
            return null;
        }
Beispiel #4
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;
            }
        }