Beispiel #1
0
 /// <summary>
 /// 取得节点的处理函数
 /// </summary>
 /// <param name="left">语法类型</param>
 /// <param name="leave">Token类型</param>
 /// <param name="nilserver">空节点展开式处理函数</param>
 /// <returns>候选式实例</returns>
 public CandidateFunction GetCFunction(SyntaxType left, TokenType leave, iHandle nilserver)
 {
     try
     {
         if (left == SyntaxType.epsilonLeave)
         {
             return(new CandidateFunction(nilserver, CFunctionType.umi_epsilon));
         }
         CandidateFunction candidator = this.GetCFunction(this.leftNodesDict[left], this.nextLeavesDict[leave]);
         return(candidator ?? new CandidateFunction(null, CFunctionType.umi_errorEnd));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         Console.WriteLine(String.Format("{0} --> {1}", left.ToString(), leave.ToString()));
         throw;
     }
 }
Beispiel #2
0
 /// <summary>
 /// 通用产生式处理函数
 /// </summary>
 /// <param name="myNode">产生式节点</param>
 /// <param name="myType">候选式类型</param>
 /// <param name="mySyntax">节点语法类型</param>
 /// <param name="myToken">命中单词</param>
 /// <returns>下一个展开节点的指针</returns>
 private SyntaxTreeNode Derivate(SyntaxTreeNode myNode, CFunctionType myType, SyntaxType mySyntax, Token myToken)
 {
     // 更新节点信息
     if (myNode != null)
     {
         myNode.NodeType = myType;
         myNode.NodeValue = myToken.OriginalCodeStr;
         myNode.NodeSyntaxType = mySyntax;
         myNode.NodeName = mySyntax.ToString();
         myNode.Line = myToken.Line;
         myNode.Column = myToken.Column;
         if (myToken.IsVar)
         {
             myNode.NodeVarType = myToken.IsGlobal ? VarScopeType.GLOBAL : VarScopeType.LOCAL;
         }
     }
     // 取候选向量
     List<SyntaxType> iSvec = this.derivatorTypeDict[Convert.ToInt32(myType)];
     // 左边出栈
     this.parseStack.Pop();
     // 如果她是一个非终结符
     if (myType < CFunctionType.DERI_UMI_BOUNDARY)
     {
         // 自右向左压匹配栈
         for (int i = iSvec.Count - 1; i >= 0; i--)
         {
             this.parseStack.Push(iSvec[i]);
         }
         // 自左向右构造子节点
         bool flag = false;
         SyntaxTreeNode successor = null;
         myNode.Children = new List<SyntaxTreeNode>();
         for (int i = 0; i < iSvec.Count; i++)
         {
             SyntaxTreeNode newNode = new SyntaxTreeNode();
             newNode.Parent = myNode;
             myNode.Children.Add(newNode);
             if (flag == false)
             {
                 successor = newNode;
                 flag = true;
             }
         }
         // 返回第一个产生式
         return successor;
     }
     // 如果她是一个终结符
     else
     {
         // 递增token指针
         if (myType != CFunctionType.umi_epsilon)
         {
             this.nextTokenPointer++;
         }
         // 返回她的后继
         return this.RecursiveDescent(myNode);
     }
 }
Beispiel #3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="type">节点类型</param>
 /// <param name="parent">节点的双亲</param>
 public SyntaxTreeNode(SyntaxType type = SyntaxType.Unknown, SyntaxTreeNode parent = null)
 {
     this.NodeName = type.ToString();
     this.NodeSyntaxType = type;
     this.Parent = parent;
 }
Beispiel #4
0
 /// <summary>
 /// 取得节点的处理函数
 /// </summary>
 /// <param name="left">语法类型</param>
 /// <param name="leave">Token类型</param>
 /// <param name="nilserver">空节点展开式处理函数</param>
 /// <returns>候选式实例</returns>
 public CandidateFunction GetCFunction(SyntaxType left, TokenType leave, iHandle nilserver)
 {
     try
     {
         if (left == SyntaxType.epsilonLeave)
         {
             return new CandidateFunction(nilserver, CFunctionType.umi_epsilon);
         }
         CandidateFunction candidator = this.GetCFunction(this.leftNodesDict[left], this.nextLeavesDict[leave]);
         return candidator == null ? new CandidateFunction(null, CFunctionType.umi_errorEnd) : candidator;
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         Console.WriteLine(String.Format("{0} --> {1}", left.ToString(), leave.ToString()));
         throw;
     }
 }
Beispiel #5
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="type">节点类型</param>
 /// <param name="parent">节点的双亲</param>
 public SyntaxTreeNode(SyntaxType type = SyntaxType.Unknown, SyntaxTreeNode parent = null)
 {
     this.NodeName       = type.ToString();
     this.NodeSyntaxType = type;
     this.Parent         = parent;
 }