Пример #1
0
        public TjsNumber SetNumber(string name, double value)
        {
            TjsNumber v = new TjsNumber(value);

            this.val[name] = v;
            return(v);
        }
Пример #2
0
        public double GetNumber(string name)
        {
            TjsValue v = null;

            this.val.TryGetValue(name, out v);

            TjsNumber ret = v as TjsNumber;

            return((ret != null) ? ret.val : double.NaN);
        }
Пример #3
0
            public TjsNumber ToTjsNumber()
            {
                double inner = 0;

                if (double.TryParse(this.val, out inner))
                {
                    TjsNumber val = new TjsNumber(inner);
                    return(val);
                }
                return(null);
            }
Пример #4
0
        public TjsValue Parse(TextReader r)
        {
            TjsParser.Token token = null;
            do
            {
                token = GetNext(r);
                if (token.t == TokenType.Number)
                {
                    // 解析出数字
                    TjsNumber ret = token.ToTjsNumber();
                    if (ret == null)
                    {
                        // 数字格式错误
                        ShowError("Invalid Number");
                        break;
                    }
                    return(ret);
                }
                else if (token.t == TokenType.String)
                {
                    // 解析出字符串
                    TjsString ret = token.ToTjsString();
                    if (ret == null)
                    {
                        // 字符串格式错误
                        ShowError("Invalid String");
                        break;
                    }
                    return(ret);
                }
                else if (token.t == TokenType.Symbol)
                {
                    // 兼容2.28
                    if (token.val == "(const)" || token.val == "int" || token.val == "string")
                    {
                        // 啥也不干
                    }
                    else if (token.val == "void")
                    {
                        // 解析出空值
                        return(new TjsVoid());
                    }
                    else if (token.val == "%[")
                    {
                        // 返回字典
                        TjsDict ret = ParseDict(r);
                        return(ret);
                    }
                    else if (token.val == "[")
                    {
                        // 返回数组
                        TjsArray ret = ParseArray(r);
                        return(ret);
                    }
                    else
                    {
                        // 无效的符号
                        ShowError("Invalid Symbol");
                        break;
                    }
                }
            } while (token.t != TokenType.Unknow);

            if (token.t != TokenType.Unknow)
            {
                ShowError("Value Parsing Failed");
                ShowError(token);
            }

            return(null);
        }