Example #1
0
        public void WeirdChamp(string varName, string type)
        {
            bool contains = false;
            Dictionary <string, string> table = new Dictionary <string, string>();

            if (Variables.ContainsKey(varName) || VariablesInt.ContainsKey(varName) || VariablesFloat.ContainsKey(varName))
            {
                contains = true;
            }
            switch (type)
            {
            case "string":
                table = Variables;
                break;

            case "int":
                table = VariablesInt;
                break;

            case "float":
                table = VariablesFloat;
                break;

            default:
                p.ExceptionHandler(11, LineN, Line);
                break;
            }
            if (contains)
            {
                if (!table.ContainsKey(varName))
                {
                    p.ExceptionHandler(6, LineN, Line);
                }
                else
                {
                    try
                    {
                        table[varName] = Console.ReadLine();
                    }
                    catch
                    {
                        p.ExceptionHandler(10, LineN, Line);
                    }
                }
            }
            else
            {
                try
                {
                    table.Add(varName, Console.ReadLine());
                    AllVars.Add(varName, table);
                }
                catch
                {
                    p.ExceptionHandler(10, LineN, Line);
                }
            }
        }
    /// <summary>
    /// Obtenemos todas las variables que se encuentran dentro de la sección de VARS
    /// </summary>
    void GetVars()
    {
        ///Se crea una lista de ids para que así se puedan crear nodos dependiendo del nombre y tipo
        List <string> ids = new List <string>();

        ///Avanzamos hasta que dejen de haber variables en esta línea del texto
        while (tokenList[index].tokenType == TokenType.ID)
        {
            ids.Add(tokenList[index].lexeme); ///Se añaden a la lista de strings
            Advance();                        //Avanza uno el index
        }

        ///Si el elemento actual dentro de la lista de tokens es igual a un entero, entra aquí
        if (tokenList[index].tokenType.Equals(TokenType.INTEGER))
        {
            ///Por cada uno de los strings dentro de la lista de strings, avanza
            foreach (string id in ids)
            {
                ///Crea una variable de entero con el nombre de este string y con tipo entero
                VariablesInt vI = new VariablesInt(id, TokenType.INTEGER);

                ///Cre un nuevo nodo con esta variable
                NodeLR nodo = new NodeLR(vI);

                ///Añade este nodo a las variables globales
                VARIABLES.Add(vI);
            }
        }
        else if (tokenList[index].tokenType.Equals(TokenType.REAL))
        { ///El elemento actual es un número real
            ///Por cada uno de los strings, avanza
            foreach (string id in ids)
            {
                ///Crea una variable flotante con este string
                VariablesFloat vI = new VariablesFloat(id, TokenType.REAL);

                ///Crea un nodo con esta variable
                NodeLR nodo = new NodeLR(vI);

                VARIABLES.Add(vI); ///Añade esta variable a las variables globales
            }
        }
        ids.Clear(); ///Libera la lista de strings

        Advance();
    }
Example #3
0
        public void PogU(string varName, string type, string value)
        {
            bool contains = false;
            Dictionary <string, string> table = new Dictionary <string, string>();

            if (Variables.ContainsKey(varName) || VariablesInt.ContainsKey(varName) || VariablesFloat.ContainsKey(varName))
            {
                contains = true;
            }
            switch (type)
            {
            case "string":
                table = Variables;
                break;

            case "int":
                table = VariablesInt;
                break;

            case "float":
                table = VariablesFloat;
                break;

            case "default":
                p.ExceptionHandler(11, LineN, Line);
                break;
            }
            if (contains)
            {
                if (!table.ContainsKey(varName))
                {
                    p.ExceptionHandler(6, LineN, Line);
                }
                else
                {
                    table[varName] = value;
                }
            }
            else
            {
                table.Add(varName, value);
                AllVars.Add(varName, table);
            }
        }