Example #1
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;
            }
        }
Example #2
0
 //Asume que no se ha consumido el ID
 Sentencia parseAssignOrCall()
 {
     string tmp = currentToken.Lexema;
     currentToken = lex.NextToken();
     switch (currentToken.Tipo)
     {
         case TipoToken.TK_PUNTO:
         case TipoToken.TK_OPENCOR:
             {
                 S_Asignacion ret = new S_Asignacion();
                 try
                 {
                     ret.id = new Variable(tmp, AccessList(tmp));
                 }
                 catch (Exception ex) { throw ex; }
                 if (currentToken.Tipo != TipoToken.TK_ASSIGN)
                     throw new Exception("Se esperaba Asignacion.");
                 else
                 {
                     currentToken = lex.NextToken();
                     try
                     {
                         ret.Valor = Expr();
                     }
                     catch (Exception ex) { throw ex; }
                     return ret;
                 }
             }
         case TipoToken.TK_OPENPAR:
             {
                 currentToken = lex.NextToken();
                 S_LlamadaFunc ret = new S_LlamadaFunc();
                 ret.Var = new Variable(tmp, null);
                 ret.Variables = new ListaExpre();
                 try
                 {
                     ret.Variables.Ex = ExprList();
                 }
                 catch (Exception ex) { throw ex; }
                 if (currentToken.Tipo != TipoToken.TK_CLOSEPAR)
                     throw new Exception("Se esperaba ).");
                 else
                 {
                     currentToken = lex.NextToken();
                     return ret;
                 }
             }
         default:
             throw new Exception("Sentencia no reconocida.");
     }
 }
Example #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;
        }