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

        variables.Add(ctx.ID().GetText(), value);
        return(value);
    }
Beispiel #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);
        }
 /// <summary>
 /// Visit a parse tree produced by the <c>SetVariable</c>
 /// labeled alternative in <see cref="CalculatorParser.setVar"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitSetVariable([NotNull] CalculatorParser.SetVariableContext context)
 {
     return(VisitChildren(context));
 }