public override object VisitAssign([NotNull] TinyScriptParser.AssignContext context)
        {
            var      type = (Type)VisitExpression(context.expression());
            var      name = context.Identifier().GetText();
            Variable value;

            if (_variables.TryGetValue(name, out value))
            {
                if (value.Value == null)
                {
                    LocalBuilder variable;
                    if (value.Type == null)
                    {
                        variable   = _builder.DeclareLocal(type);
                        value.Type = type;
                    }
                    else if (value.Type != type)
                    {
                        throw context.Exception("Cannot convert type [{0}] to [{1}].", type.Name, value.Type.Name);
                    }
                    else
                    {
                        variable = _builder.DeclareLocal(type);
                    }
                    value.Value = variable;
                }
                _builder.SetLocal(value.Value);
                return(null);
            }
            throw context.Exception("Variable [{0}] not defined.", name);
        }
        public override object VisitAssign([NotNull] TinyScriptParser.AssignContext context)
        {
            var      name = context.Identifier().GetText();
            VarValue obj;

            if (!Variables.TryGetValue(name, out obj))
            {
                throw context.Exception("Variable [{0}] not defined.", name);
            }
            var r = base.VisitAssign(context);

            if (obj != null && obj.Value != null)
            {
                if (obj.Value.GetType() != r.GetType())
                {
                    throw context.Exception("Cannot convert type [{1}] to [{0}].", obj.Value.GetType().Name, r.GetType().Name);
                }
            }
            Variables[name] = new VarValue(obj.StartIndex, r);
            return(null);
        }
 /// <summary>
 /// Visit a parse tree produced by <see cref="TinyScriptParser.assign"/>.
 /// <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 VisitAssign([NotNull] TinyScriptParser.AssignContext context)
 {
     return(VisitChildren(context));
 }