/// <summary> /// 添加一个候选式函数对象的所有委托到本对象 /// </summary> /// <param name="function"></param> public void Add(CandidateFunction <TEnumTokenType, TEnumVType, TTreeNodeValue> function) { if (function != null) { this.m_CandidateFunc += function.m_CandidateFunc; } }
/// <summary> /// 设置给定语法类型、单词类型所对应的分析函数 /// </summary> /// <param name="leftNode"></param> /// <param name="nextLeave"></param> /// <param name="function"></param> public void SetCell(TEnumVType leftNode, TEnumTokenType nextLeave, CandidateFunction <TEnumTokenType, TEnumVType, TTreeNodeValue> function) { //SetCell(this.m_LeftNodes[leftNode], this.m_NextLeaves[nextLeave], function); string key = leftNode.ToString() + "+" + nextLeave.ToString(); m_ParserMap.Add(key, function); }
/// <summary> /// 设置给定行、列位置的分析函数 /// </summary> /// <param name="line"></param> /// <param name="column"></param> /// <param name="function"></param> public void SetCell(int line, int column, CandidateFunction <TEnumTokenType, TEnumVType, TTreeNodeValue> function) { //if (0 <= line && line < this.m_LineCount) //{ // if (0 <= column && column < this.m_ColumnCount) // this.m_ParserMap[line, column] = function; // else // throw new ArgumentOutOfRangeException("column", column, "LL1分析表列数设置错误!"); //} //else // throw new ArgumentOutOfRangeException("line", line, "LL1分析表行数设置错误!"); }
/// <summary> /// 获取处理函数 /// </summary> /// <param name="leftNode">当前结非终点类型</param> /// <param name="nextLeave">要处理的终结点类型</param> /// <returns></returns> public CandidateFunction <TEnumTokenType, TEnumVType, TTreeNodeValue> GetFunction(TEnumVType leftNode, TEnumTokenType nextLeave) { //#if DEBUG // if (this.m_LeftNodes.ContainsKey(leftNode) // && this.m_NextLeaves.ContainsKey(nextLeave)) //#endif // return this.GetFunction(this.m_LeftNodes[leftNode], this.m_NextLeaves[nextLeave]); //#if DEBUG // else // return null; //#endif string key = leftNode.ToString() + "+" + nextLeave.ToString(); CandidateFunction <TEnumTokenType, TEnumVType, TTreeNodeValue> value = null; if (m_ParserMap.TryGetValue(key, out value)) { return(value); } else { return(new CandidateFunction <TEnumTokenType, TEnumVType, TTreeNodeValue>(null));// TODO:将来这里可以放对语法错误进行分析的函数 } }