public override Double VisitSetVariable(CalculatorParser.SetVariableContext ctx)
    {
        Double value = Visit(ctx.plusOrMinus());

        variables.Add(ctx.ID().GetText(), value);
        return(value);
    }
Example #2
0
        /// <summary>
        /// Visita el nodo correspondiente a la asignaciĆ³n de variables
        /// </summary>
        /// <param name="context">Variable de contexto</param>
        /// <returns>Devuelve el valor de la variable tras ser asignada</returns>
        public override double VisitSetVariable(CalculatorParser.SetVariableContext context)
        {
            string id  = context.ID().GetText();
            double val = Visit(context.setVar());

            if (memory.FirstOrDefault(m => m.Key == id).Key == null)
            {
                memory.Add(id, val);
            }
            else
            {
                memory[id] = val;
            }
            return(val);
        }