Пример #1
0
        // ----------------------------------------------------------
        // private
        // ----------------------------------------------------------
        private void Verify(XTFormulaParser parser, XTFormulaToken token)
        {
            XTOperatorToken optToken = token as XTOperatorToken;

            if (this.m_currIsOpt == null)                                                                       // 第一个元素
            {
                this.m_currIsOpt = false;
                if (optToken == null)
                {
                    return;                                                                                     // 不是运算符
                }
                this.m_currIsOpt = true;
                if (optToken.AllowEmptyLToken)
                {
                    return;                                                                             // 允许空左子树的运算符
                }
                parser.RaiseFormulaException();                                                         // 以双目运算符开头(语法错误)
            }
            else if (this.m_currIsOpt == true)                                                          // 前一个元素是运算符
            {
                if (optToken != null)                                                                   // 紧接着又是一个运算符
                {
                    parser.RaiseFormulaException();                                                     // 两个双目运算符连一起(语法错误)
                }
                this.m_currIsOpt = false;
            }
            else                                                                                                        // 前一个元素是值元素
            {
                if (optToken == null)                                                                                   // 紧接着又一个值元素(语法错误)
                {
                    parser.RaiseFormulaException();
                }
                this.m_currIsOpt = true;
            }
        }
Пример #2
0
        // 整型
        private static XTFormulaToken ParseInt(XTFormulaParser parser, HashSet <string> argNames)
        {
            Match m = parser.NextRegx(sm_reInt);

            if (m == null)
            {
                return(null);
            }
            return(new XTLongToken(long.Parse(m.Groups[0].Value)));
        }
Пример #3
0
        public override XTFormulaToken Parse(XTFormulaParser parser, HashSet <string> argNames)
        {
            Match m = parser.NextRegx(this.m_re);

            if (m == null)
            {
                return(null);
            }
            argNames.Add(this.m_name);
            return(new XTArgToken(this.m_name));
        }
Пример #4
0
 // 解释表达式
 override public XTFormulaToken Parse(XTFormulaParser parser, HashSet <string> argNames)
 {
     foreach (OptItem item in sm_opts)
     {
         if (parser.NextString(item.Value))
         {
             return(new XTOperatorToken(item.Key));
         }
     }
     return(null);
 }
Пример #5
0
        // 浮点型
        private static XTFormulaToken ParseFloat(XTFormulaParser parser, HashSet <string> argNames)
        {
            Match m = parser.NextRegx(sm_reFloat);

            if (m == null)
            {
                return(null);
            }
            double value = double.Parse(m.Groups[0].Value);

            return(new XTDoubleToken(value));
        }
Пример #6
0
 public override XTFormulaToken Parse(XTFormulaParser parser, HashSet <string> argNames)
 {
     foreach (NumericParser func in sm_parsers)
     {
         XTFormulaToken token = func(parser, argNames);
         if (token == null)
         {
             continue;
         }
         return(token);
     }
     return(null);
 }
Пример #7
0
        // 十六进制整型
        private static XTFormulaToken ParseHInt(XTFormulaParser parser, HashSet <string> argNames)
        {
            Match m = parser.NextRegx(sm_reHInt);

            if (m == null)
            {
                return(null);
            }
            long value = long.Parse(m.Groups[0].Value.Substring(2),
                                    System.Globalization.NumberStyles.HexNumber);

            return(new XTLongToken(value));
        }
Пример #8
0
        public override XTFormulaToken Parse(XTFormulaParser parser, HashSet <string> argNames)
        {
            XTFormulaToken token;

            foreach (BaseFuncInfo info in sm_funcInfos)
            {
                token = this.CreateToken(parser, argNames, info);
                if (token == null)
                {
                    continue;
                }
                return(token);
            }
            return(null);
        }
Пример #9
0
        public override XTFormulaToken Parse(XTFormulaParser parser, HashSet <string> argNames)
        {
            if (parser.CurrChar() != '(')
            {
                return(null);
            }
            parser.NextChar();
            XTFormula formula = parser.InnerParse(argNames);
            int       end     = parser.NextChar();

            if (end != ')')
            {
                parser.RaiseFormulaException();
            }
            return(new XTScopeToken(formula));
        }
Пример #10
0
        private XTFormulaToken CreateToken(XTFormulaParser parser, HashSet <string> argNames, BaseFuncInfo funcInfo)
        {
            // 函数开始
            if (parser.NextRegx(funcInfo.ReStart) == null)
            {
                return(null);
            }

            // 函数参数
            XTFormula formula;

            XTFormula[] formulas = new XTFormula[funcInfo.ArgCount];
            for (int i = 0; i < funcInfo.ArgCount; ++i)
            {
                if (i > 0)
                {
                    if (parser.NextRegx(sm_reSplit) == null)
                    {
                        parser.RaiseFormulaException();
                    }
                }
                formula = parser.InnerParse(argNames);
                if (formula == null)
                {
                    parser.RaiseFormulaException();
                }
                formulas[i] = formula;
            }

            // 函数结束
            if (parser.NextRegx(sm_reEnd) == null)
            {
                parser.RaiseFormulaException();
            }
            return(funcInfo.CreateToken(formulas));
        }
Пример #11
0
        // ----------------------------------------------------------
        // internal
        // ----------------------------------------------------------
        internal virtual void AddToken(XTFormulaParser parser, XTFormulaToken token)
        {
            this.Verify(parser, token);

            XTOperatorToken optToken = token as XTOperatorToken;

            if (this.m_root == null)
            {
                this.m_root = token;
            }
            else if (this.m_root is XTOperatorToken)                                                            // 重新调整语法树
            {
                this.m_root = ((XTOperatorToken)this.m_root).AddToken(token);
            }
            else if (optToken != null)
            {
                optToken.SetLToken(this.m_root);
                this.m_root = optToken;
            }
            else
            {
                parser.RaiseFormulaException();
            }
        }
Пример #12
0
 public virtual XTFormulaToken Parse(XTFormulaParser parser, HashSet <string> argNames)
 {
     return(null);
 }