Example #1
0
 /// <summary>
 ///		Añade una variable a la tabla de símbolos de un programa / función
 /// </summary>
 private void AddVariable(Program program, InstructionVariableIdentifier instruction)
 {
     if (instruction != null && instruction.Value.Count > 0)
     {
         program.SymbolsTable.Variables.Add(instruction.Variable.Name, instruction.Value[0].Token.Value);
     }
 }
Example #2
0
        /// <summary>
        ///		Obtiene una instrucción de asignación de variables
        /// </summary>
        private InstructionBase CreateInstructionVariable()
        {
            InstructionVariableIdentifier instruction = new InstructionVariableIdentifier(GetToken());
            TokenSmallCss tokenValue = GetToken();

            if (tokenValue.Row == instruction.Token.Row &&
                tokenValue.TypeCss == TokenSmallCss.TokenCssType.Literal)
            {
                if (tokenValue.Value.TrimIgnoreNull() == ":")
                {
                    tokenValue = GetToken();
                    if (tokenValue.Row == instruction.Token.Row &&
                        tokenValue.TypeCss == TokenSmallCss.TokenCssType.Literal)
                    {
                        instruction.Value.Add(new ExpressionBase(tokenValue));
                    }
                    else
                    {
                        instruction.Error = ParseError("No se reconoce el valor asignado a la variable");
                    }
                }
                else
                {
                    instruction.Value.Add(new ExpressionBase(tokenValue));
                }
            }
            else
            {
                instruction.Error = ParseError("No se reconoce el valor asignado a la variable");
            }
            // Devuelve la instrucción
            return(instruction);
        }
Example #3
0
        /// <summary>
        ///		Lee una instrucción de un identificador de variable
        /// </summary>
        private InstructionVariableIdentifier ReadVariableIdentifier(Token token)
        {
            InstructionVariableIdentifier instruction = new InstructionVariableIdentifier(token);

            // Lee la expresión
            instruction.Variable = ReadVariableIdentifier(token, out string error);
            if (!string.IsNullOrWhiteSpace(error))
            {
                instruction.Error = error;
            }
            // Devuelve la instrucción
            return(instruction);
        }
Example #4
0
        /// <summary>
        ///		Obtiene el valor de una variable
        /// </summary>
        private string GetVariableValue(InstructionVariableIdentifier instruction)
        {
            ValueBase value = GetVariable(instruction);

            if (value == null)
            {
                return($"##Error al obtener la variable {instruction.Variable.Name}");
            }
            else if (value.Content != null)
            {
                return(value.Content);
            }
            else
            {
                return("");
            }
        }
Example #5
0
        /// <summary>
        ///		Obtiene una variable
        /// </summary>
        private ValueBase GetVariable(InstructionVariableIdentifier instruction)
        {
            Variable variable = ExpressionComputer.Search(instruction.Variable, out string error);

            if (!string.IsNullOrWhiteSpace(error))
            {
                Compiler.LocalErrors.Add(instruction.Token, error);
                return(ValueBase.GetError($"## Error al obtener la variable: {error} ##"));
            }
            else if (variable == null)                     // ... nunca se debería dar
            {
                Compiler.LocalErrors.Add(instruction.Token, $"No se encuentra el valor de la variable {instruction.Variable.Name}");
                return(ValueBase.GetError($"## No se encuentra la variable: {instruction.Variable.Name} ##"));
            }
            else
            {
                return(variable.Value);
            }
        }