コード例 #1
0
ファイル: pascalParser.cs プロジェクト: DiegoTc/compiladoresI
 Declaracion VariableDeclaration()
 {
     if (currentToken.Tipo != TipoToken.TK_ID)
         throw new Exception("Se esperaba identificador.");
     else
     {
         Declaracion ret = new Declaracion();
         ret.Var = new Variable(currentToken.Lexema, null);
         currentToken = lex.NextToken();
         if (currentToken.Tipo != TipoToken.TK_DOSPUNTOS)
             throw new Exception("Se esperaba :.");
         else
         {
             currentToken = lex.NextToken();
             try
             {
                 ret.Tip = ParseType();
             }
             catch (Exception ex) { throw ex; }
             return ret;
         }
     }
 }
コード例 #2
0
ファイル: javaParser.cs プロジェクト: DiegoTc/compiladoresI
        public Declaracion ParameterList()
        {
            if (currentToken.Tipo == TipoToken.TK_CHAR || currentToken.Tipo == TipoToken.TK_BOOL || currentToken.Tipo == TipoToken.TK_STRING || currentToken.Tipo == TipoToken.TK_FLOAT || currentToken.Tipo == TipoToken.TK_INT)
            {
                Declaracion C = new Declaracion();
                try
                {
                    C.Tip = Type();
                }
                catch (Exception ex)
                {

                    throw ex;
                }
                if (currentToken.Tipo == TipoToken.TK_OPENCOR) //ARREGLO
                {
                    int dim = arrayDimensions(1);
                    Arreglo ArrTip = new Arreglo();
                    ArrTip.Contenido = C.Tip;
                    ArrTip.Dimensiones = dim;
                    C.Tip = ArrTip;
                    if (currentToken.Tipo == TipoToken.TK_ID)
                    {
                        C.Var.id = currentToken.Lexema;
                        currentToken = lex.NextToken();
                        //C = DeclOption(C); /////PORQUE NO DEVUELVO NADA ACA??????????????????????????????
                        try
                        {
                            C.Sig = ParameterListP();
                        }
                        catch (Exception ex)
                        {

                            throw ex;
                        }

                        return C;
                    }
                    else
                    {
                        throw new Exception("Error Sintactico - Se esperaba un ID");
                    }
                }
                else if (currentToken.Tipo == TipoToken.TK_ID)
                {
                    C.Var.id = currentToken.Lexema;
                    currentToken = lex.NextToken();
                    try
                    {
                        C.Sig = ParameterListP();
                    }
                    catch (Exception ex)
                    {

                        throw ex;
                    }

                    return C;
                }
                else
                {
                    throw new Exception("Error Sintactico - Se esperaba un identificador");
                }
            }
            else
            {
                return null;
            }
        }
コード例 #3
0
ファイル: javaParser.cs プロジェクト: DiegoTc/compiladoresI
        public Declaracion ParameterListP()
        {
            if (currentToken.Tipo == TipoToken.TK_COMA)
            {
                Declaracion C1 = new Declaracion();
                currentToken = lex.NextToken();
                try
                {
                    C1.Tip = Type();
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                if (currentToken.Tipo == TipoToken.TK_ID)
                {
                    C1.Var.id = currentToken.Lexema;
                    currentToken = lex.NextToken();
                    try
                    {
                        C1.Sig = ParameterListP();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    return C1;
                }
                else
                {
                    throw new Exception("Error Sintactico - Se esperaba un identificador");
                }
            }
            else
            {
                return null;
            }
        }
コード例 #4
0
ファイル: javaParser.cs プロジェクト: DiegoTc/compiladoresI
        public Sentencia DeclaracionesVarias(Declaracion De)
        {
            if (currentToken.Tipo == TipoToken.TK_COMA)
            {
                currentToken = lex.NextToken();
                if (currentToken.Tipo != TipoToken.TK_ID)
                    throw new Exception("Error Sintactico - Se esperaba un Id");
                De.Sig = new Declaracion();
                De.Sig.Var.id = currentToken.Lexema;
                De.Sig.Tip = De.Tip;
                currentToken = lex.NextToken();
                try
                {
                    DeclaracionesVarias(De);
                }
                catch (Exception ex)
                {

                    throw ex;
                }

                return De;
            }
            else
            {
                return De;
            }
        }
コード例 #5
0
ファイル: javaParser.cs プロジェクト: DiegoTc/compiladoresI
        public Declaracion DeclOption(Declaracion De)
        {
            if (currentToken.Tipo == TipoToken.TK_ASSIGN)
            {
                currentToken = lex.NextToken();
                try
                {
                    De.Valor = Expr();
                }
                catch (Exception ex)
                {

                    throw ex;
                }

                if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA)
                {
                    currentToken = lex.NextToken();
                }
                else
                {
                    throw new Exception("Error Sintactico - Se esperaba Fin Sentencia");
                }

            }
            else if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA)
            {
                currentToken = lex.NextToken();
            }
            else
            {
                throw new Exception("Error Sintactico - Se esperaba Fin Sentencia");
            }
            return De;
        }
コード例 #6
0
ファイル: javaParser.cs プロジェクト: DiegoTc/compiladoresI
        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;
        }
コード例 #7
0
ファイル: javaParser.cs プロジェクト: DiegoTc/compiladoresI
        public Sentencia DeclaracionesClase()
        {
            Declaracion Decl = new Declaracion();

            VARTYPE();
            try
            {
                Class c = new Class();
                c.Nombre = currentToken.Lexema;
                c.Campos=new T_Campos();
                Decl.Tip =c;
                currentToken = lex.NextToken();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (currentToken.Tipo == TipoToken.TK_OPENCOR) //ARREGLO
            {
                int dim = arrayDimensions(1);
                Arreglo ArrTip = new Arreglo();
                ArrTip.Contenido = Decl.Tip;
                ArrTip.Dimensiones = dim;
                Decl.Tip = ArrTip;
                if (currentToken.Tipo == TipoToken.TK_ID)
                {
                    Decl.Var.id = currentToken.Lexema;
                    currentToken = lex.NextToken();
                    if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA)
                    {
                        currentToken = lex.NextToken();
                        return Decl;
                    }
                    try
                    {
                        Decl = DeclOption(Decl);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    if (currentToken.Tipo != TipoToken.TK_FINSENTENCIA)
                    {
                        currentToken = lex.NextToken();
                        return Decl;
                    }
                    else
                    {
                        throw new Exception("Error Sintactico - Se esperaba Fin Sentencia");
                    }
                }
                else
                {
                    throw new Exception("Error Sintactico - Se esperaba un ID");
                }

            }
            else if (currentToken.Tipo == TipoToken.TK_ID)
            {
                Decl.Var.id = currentToken.Lexema;
                currentToken = lex.NextToken();
                if (currentToken.Tipo == TipoToken.TK_COMA || currentToken.Tipo == TipoToken.TK_ASSIGN)
                {
                    try
                    {
                        DeclaracionesVarias(Decl);
                        DeclOption(Decl);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                else if (currentToken.Tipo == TipoToken.TK_OPENPAR)
                {
                    currentToken = lex.NextToken();
                    S_Functions sFunctions = new S_Functions();
                    sFunctions.Retorno = Decl.Tip;
                    sFunctions.Var = Decl.Var.id;
                    try
                    {
                        sFunctions.Campo = ParameterList();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    if (currentToken.Tipo == TipoToken.TK_CLOSEPAR)
                    {
                        currentToken = lex.NextToken();
                        try
                        {
                            sFunctions.S = CompoundStatement();
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }

                        return sFunctions;
                    }
                    else
                    {
                        throw new Exception("Error Sintactico - Se esperaba simbolo )");
                    }
                }
                else if (currentToken.Tipo == TipoToken.TK_OPENLLAVE)
                {
                    currentToken = lex.NextToken();
                    S_Class sClass = new S_Class();
                    sClass.Var.id = Decl.Var.id;

                    try
                    {
                        sClass.CamposClase = ListaDeclaracion(sClass.CamposClase);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    if (currentToken.Tipo != TipoToken.TK_CLOSELLAVE)
                        throw new Exception("Error Sintactico - Se esperaba simbolo }");
                    currentToken = lex.NextToken();
                    return sClass;
                }
                else if (currentToken.Tipo == TipoToken.TK_FINSENTENCIA)
                {
                    currentToken = lex.NextToken();
                    return Decl;
                }
                else
                    throw new Exception("Error Sintactico - Se esperaba simbolo ;");
            }
            return Decl;
        }
コード例 #8
0
ファイル: cParser.cs プロジェクト: DiegoTc/compiladoresI
        /*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;
            }
        }
コード例 #9
0
ファイル: cParser.cs プロジェクト: DiegoTc/compiladoresI
        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;
            }
        }
コード例 #10
0
ファイル: cParser.cs プロジェクト: DiegoTc/compiladoresI
        public Declaracion DeclOption(Declaracion De)
        {
            try
            {
                if (currentToken.Tipo == Lexico.TipoToken.TK_FINSENTENCIA)
                {
                    currentToken = lex.NextToken();
                }
                else if (currentToken.Tipo == Lexico.TipoToken.TK_ASSIGN)
                {
                    currentToken = lex.NextToken();
                    De.Valor = Expression();
                    if (currentToken.Tipo != Lexico.TipoToken.TK_FINSENTENCIA)
                        throw new Exception("Se esperaba ;");

                    currentToken = lex.NextToken();
                }
                //else
                //throw new Exception("Se esperaba ;");
                return De;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #11
0
ファイル: cParser.cs プロジェクト: DiegoTc/compiladoresI
        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;
            }
        }
コード例 #12
0
ファイル: cParser.cs プロジェクト: DiegoTc/compiladoresI
        /*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;
            }
        }
コード例 #13
0
ファイル: cParser.cs プロジェクト: DiegoTc/compiladoresI
        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;
            }
        }
コード例 #14
0
ファイル: cParser.cs プロジェクト: DiegoTc/compiladoresI
        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;
            }
        }
コード例 #15
0
ファイル: cParser.cs プロジェクト: DiegoTc/compiladoresI
        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;
            }
        }
コード例 #16
0
ファイル: cParser.cs プロジェクト: DiegoTc/compiladoresI
        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;
            }
        }