コード例 #1
0
        public override object VisitVariableExpression([NotNull] TinyScriptParser.VariableExpressionContext context)
        {
            var c    = context.GetChild(0);
            var text = c.GetText();

            switch (text)
            {
            case "true": _builder.LoadInt(1); return(typeof(bool));

            case "false": _builder.LoadInt(0); return(typeof(bool));
            }
            if (text.StartsWith("\""))
            {
                var str = text.Substring(1, text.Length - 2);
                _builder.LoadString(str);
                return(typeof(string));
            }
            Variable variable;

            if (_variables.TryGetValue(text, out variable))
            {
                _builder.LoadLocal(variable.Value);
                return(variable.Type);
            }
            throw context.Exception("Use of undeclared identifier [{0}].", text);
        }