// ---------------------------------------------------------- // 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; } }
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)); }
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)); }
// ---------------------------------------------------------- // 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(); } }