예제 #1
0
        /*Lista de Parametros*/
        public Declaracion FuncionesParams()
        {
            try
            {
                Declaracion decl = new Declaracion();
                Tipo tipo = Tipo();
                if (tipo == null)
                    return decl;
                if (currentToken.Tipo != Lexico.TipoToken.TK_ID)
                    throw new Exception("Se esperaba el token ID");

                Variable nombre = new Variable(currentToken.Lexema, null);
                nombre.flag = 'F';
                currentToken = lex.NextToken();
                decl.Tip = tipo;
                decl.Var = nombre;
                decl.Sig = FParams();
                return decl;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        public Sentencia SentenciaAssign_LlamaFun()
        {
            try
            {
                if (currentToken.Tipo == Lexico.TipoToken.TK_ID)
                {
                    Variable var = new Variable(currentToken.Lexema, null);
                    currentToken = lex.NextToken();
                    if (currentToken.Tipo == Lexico.TipoToken.TK_PUNTO || currentToken.Tipo == Lexico.TipoToken.TK_OPENCOR || currentToken.Tipo == Lexico.TipoToken.TK_OPENPAR)
                    {
                        Access a = Accesories(var.accesor);
                        var.accesor = a;
                    }

                    if (currentToken.Tipo == Lexico.TipoToken.TK_ASSIGN || currentToken.Tipo == Lexico.TipoToken.TK_MASIGUAL || currentToken.Tipo == Lexico.TipoToken.TK_MENORIGUAL || currentToken.Tipo == Lexico.TipoToken.TK_PORIGUAL ||
                        currentToken.Tipo == Lexico.TipoToken.TK_ENTREIGUAL)
                    {
                        S_Asignacion sAsignacion = new S_Asignacion();
                        if (currentToken.Tipo == Lexico.TipoToken.TK_ASSIGN)
                            sAsignacion.Op = new Igual();
                        else if (currentToken.Tipo == Lexico.TipoToken.TK_MASIGUAL)
                            sAsignacion.Op = new MasIgual();
                        else if (currentToken.Tipo == Lexico.TipoToken.TK_MENOSIGUAL)
                            sAsignacion.Op = new MenosIgual();
                        else if (currentToken.Tipo == Lexico.TipoToken.TK_PORIGUAL)
                            sAsignacion.Op = new PorIgual();
                        else if (currentToken.Tipo == Lexico.TipoToken.TK_ENTREIGUAL)
                            sAsignacion.Op = new EntreIgual();

                        currentToken = lex.NextToken();
                        sAsignacion.id = var;
                        sAsignacion.Valor = Expression();
                        return sAsignacion;
                    }
                    else if (currentToken.Tipo == Lexico.TipoToken.TK_ID)
                    {
                        Declaracion decl = new Declaracion();
                        Struct str = new Struct();
                        str.nombre = var.id;

                        Variable vVar = new Variable(currentToken.Lexema, null);
                        decl.Var = vVar;
                        decl.Tip = str;
                        currentToken = lex.NextToken();
                        if (currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA)
                            throw new Exception("Error Sintactico --Se esperaba ;");

                        return decl;
                    }

                    else
                    {
                        if (currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA)
                            throw new Exception("Error Sintactico --Se esperaba ;");

                        //if (var.accesor.Last() is AccessFunc)
                        //{
                        S_LlamadaFunc sllamadafunc = new S_LlamadaFunc();
                        sllamadafunc.Var = var;
                        return sllamadafunc;
                        //}
                    }
                }
                return null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        /*Aqui se efectua la recursividad del ,id,id,id*/
        public Declaracion DeclCPrima(Declaracion decl)
        {
            try
            {
                if (currentToken.Tipo == Lexico.TipoToken.TK_COMA)
                {
                    currentToken = lex.NextToken();
                    if (currentToken.Tipo != Lexico.TipoToken.TK_ID)
                        throw new Exception("Se esperaba un token ID");

                    Variable nombre = new Variable(currentToken.Lexema, null);
                    decl.Sig.Tip = decl.Tip;
                    decl.Sig.Var = nombre;
                    currentToken = lex.NextToken();
                    DeclCPrima(decl.Sig);
                    return decl;
                }
                return decl;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #4
0
        public Declaracion FParams()
        {
            try
            {
                Declaracion d = new Declaracion();
                if (currentToken.Tipo == Lexico.TipoToken.TK_COMA)
                {
                    currentToken = lex.NextToken();
                    //Declaracion decl = new Declaracion();
                    Tipo tipo = Tipo();
                    if (tipo == null)
                        return d;
                    if (currentToken.Tipo != Lexico.TipoToken.TK_ID)
                        throw new Exception("Se esperaba el token ID");

                    Variable nombre = new Variable(currentToken.Lexema, null);
                    currentToken = lex.NextToken();
                    d.Tip = tipo;
                    d.Var = nombre;
                    d.Sig = FParams();
                    return d;
                }
                return null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #5
0
        public Declaracion DeclarsCstruct(Declaracion decl)
        {
            try
            {
                if (currentToken.Tipo == Lexico.TipoToken.TK_COMA)
                {
                    currentToken = lex.NextToken();
                    if (currentToken.Tipo != Lexico.TipoToken.TK_ID)
                        throw new Exception("Se esperaba un token ID");

                    Variable nombre = new Variable(currentToken.Lexema, null);
                    decl.Sig.Var = nombre;
                    decl.Sig.Tip = decl.Tip;
                    DeclarsCstruct(decl.Sig);
                    return decl;
                }
                else if (currentToken.Tipo == Lexico.TipoToken.TK_OPENCOR)
                {
                    currentToken = lex.NextToken();
                    Expresiones E1 = Expression();
                    if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSECOR)
                        throw new Exception("Se esperaba el token ] ");
                    currentToken = lex.NextToken();
                    Arreglo tipoArreglo = new Arreglo();
                    tipoArreglo.Rangos.Add(E1);
                    tipoArreglo.Contenido = decl.Tip;
                    decl.Tip = tipoArreglo;
                    DeclarsCstruct(decl.Sig);
                    return decl;
                }
                return decl;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #6
0
        public Sentencia DeclaracionesCPrima(Declaracion decl)
        {
            try
            {
                /*Cuando se declaran varias variables seguidas int x,t,y  */
                #region
                if (currentToken.Tipo == Lexico.TipoToken.TK_COMA)
                {
                    currentToken = lex.NextToken();
                    if (currentToken.Tipo != Lexico.TipoToken.TK_ID)
                        throw new Exception("Se esperaba un token ID");

                    Variable nombre = new Variable(currentToken.Lexema, null);
                    decl.Sig.Tip = decl.Tip;
                    decl.Sig.Var = nombre;
                    currentToken = lex.NextToken();
                    DeclCPrima(decl.Sig);
                    return decl;
                }
                #endregion
                /*Declaracion de arreglos */
                #region
                else if (currentToken.Tipo == Lexico.TipoToken.TK_OPENCOR)
                {
                    currentToken = lex.NextToken();
                    Expresiones E1 = Expression();
                    if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSECOR)
                        throw new Exception("Se esperaba el token ] ");
                    currentToken = lex.NextToken();
                    Arreglo tipoArreglo = new Arreglo();
                    tipoArreglo.Contenido = decl.Tip;
                    tipoArreglo.Rangos.Add(E1);
                    DeclArreglo(tipoArreglo);
                    tipoArreglo.Dimensiones = tipoArreglo.Rangos.Count;
                    decl.Tip = tipoArreglo;
                    return decl;
                }
                #endregion
                /*Declaracion de funciones */
                #region
                else if (currentToken.Tipo == Lexico.TipoToken.TK_OPENPAR)
                {
                    currentToken = lex.NextToken();
                    Declaracion listaParams = FuncionesParams();
                    if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSEPAR)
                        throw new Exception("Se esperaba el token )");
                    currentToken = lex.NextToken();

                    S_Functions declFuncion = new S_Functions();
                    declFuncion.Retorno = decl.Tip;
                    declFuncion.Var = decl.Var.id;
                    declFuncion.S = CompoundStatement();
                    if (listaParams != null)
                        declFuncion.Campo = listaParams;
                    return declFuncion;
                }
                #endregion
                /*Declaracion de Structs */
                #region
                else if (currentToken.Tipo == Lexico.TipoToken.TK_OPENLLAVE)
                {
                    currentToken = lex.NextToken();
                    Declaracion strDec = StructDeclaration();
                    Declaracion tmp = StructDeclaration();
                    while (tmp != null)
                    {
                        strDec.Sig = tmp;
                        tmp = StructDeclaration();
                    }

                    Structs s = new Structs();
                    s.nombre = decl.Var.id;
                    s.campos = strDec;
                    if (currentToken.Tipo != Lexico.TipoToken.TK_CLOSELLAVE)
                        throw new Exception("Error sintactico se esperaba }");
                    currentToken = lex.NextToken();

                    if (currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA)
                        throw new Exception("Error sintactico se esperaba ;");
                    currentToken = lex.NextToken();

                    return s;
                }
                #endregion
                return decl;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #7
0
        public Sentencia DeclaracionesC()
        {
            try
            {
                Tipo tipo = Tipo();
                if (currentToken.Tipo != Lexico.TipoToken.TK_ID)
                    throw new Exception("Se esperaba un token ID");

                Variable nombre = new Variable(currentToken.Lexema, null);
                Declaracion decl = new Declaracion();
                decl.Tip = tipo;
                decl.Var = nombre;

                currentToken = lex.NextToken();
                Sentencia s = DeclaracionesCPrima(decl);
                DeclOption(decl);
                if (s is Structs)
                    return ((Structs)s);
                else if (s is S_Functions)
                    return ((S_Functions)s);
                else
                    return decl;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #8
0
        public Declaracion StructDeclaration()
        {
            try
            {
                if (currentToken.Tipo == Lexico.TipoToken.TK_ID)
                {
                    Struct t = new Struct();
                    t.nombre = currentToken.Lexema;
                    currentToken = lex.NextToken();
                    if (currentToken.Tipo != Lexico.TipoToken.TK_ID)
                        throw new Exception("Se esperaba el token Id");
                    Variable nombre = new Variable(currentToken.Lexema, null);
                    Declaracion decl = new Declaracion();
                    decl.Tip = t;
                    decl.Var = nombre;
                    currentToken = lex.NextToken();
                    DeclarsCstruct(decl);
                    if (currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA)
                        throw new Exception("Se esperaba el token ;");
                    currentToken = lex.NextToken();
                    return decl;
                }
                else if (currentToken.Tipo == Lexico.TipoToken.TK_INT || currentToken.Tipo == Lexico.TipoToken.TK_FLOAT || currentToken.Tipo == Lexico.TipoToken.TK_CHAR)
                {
                    Tipo t = Tipo();
                    if (currentToken.Tipo != Lexico.TipoToken.TK_ID)
                        throw new Exception("Se esperaba el token Id");
                    Variable name = new Variable(currentToken.Lexema, null);
                    currentToken = lex.NextToken();

                    Declaracion decl = new Declaracion();
                    decl.Tip = t;
                    decl.Var = name;
                    DeclarsCstruct(decl);
                    if (currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA)
                        throw new Exception("Se esperaba el token ;");
                    currentToken = lex.NextToken();
                    return decl;

                }

                return null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #9
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;
        }