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); }
public override object VisitVariableExpression([NotNull] TinyScriptParser.VariableExpressionContext context) { var n = context.GetText(); if (n == "true") { return(true); } else if (n == "false") { return(false); } else if (n.StartsWith("\"")) { return(n.Substring(1, n.Length - 2)); } VarValue obj; if (!Variables.TryGetValue(n, out obj)) { throw context.Exception("Use of undeclared identifier [{0}].", n); } return(obj.Value); }