Exemplo n.º 1
0
        //        /// <summary>
        //        /// 获取推导式
        //        /// </summary>
        //        /// <param name="line">行数</param>
        //        /// <param name="column">列数</param>
        //        /// <returns></returns>
        //        public DerivationList GetDerivationList(int line, int column)
        //        {
        //#if DEBUG
        //            if (0 <= line && line < this.m_LineCount
        //                && 0 <= column && column < this.m_ColumnCount)
        //#endif
        //                return this.m_ParserMap[line, column];
        //#if DEBUG
        //            else
        //                return null;
        //#endif
        //        }
        /// <summary>
        /// 分析表
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            foreach (var item in this.m_ParserMap)
            {
                builder.Append(item.Key);
                DerivationList derivationList = item.Value;
                if (derivationList.Count == 0)
                {
                    builder.AppendLine("    no derivation");
                }
                else
                {
                    builder.AppendLine();
                    foreach (var derivation in derivationList)
                    {
                        builder.AppendLine("    " + derivation.ToString());
                    }
                }
            }

            return(builder.ToString());
            //return base.ToString();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取此推导式的复制品
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            var result = new DerivationList();

            foreach (var item in this)
            {
                var derivation = item.Clone() as Derivation;
                result.Add(derivation);
            }
            //if (this.Left != null)
            //    result.Left = this.Left.Clone() as ProductionNode;
            //if (this.Right != null)
            //    result.Right = this.Right.Clone() as ProductionNodeList;
            return(result);
        }
Exemplo n.º 3
0
        ///// <summary>
        ///// 设置给定行、列位置的推导式
        ///// </summary>
        ///// <param name="line"></param>
        ///// <param name="column"></param>
        ///// <param name="derivation"></param>
        //public void SetCell(int line, int column, Derivation derivation)
        //{
        //    if (0 <= line && line < this.m_LineCount
        //        && 0 <= column && column < this.m_ColumnCount)
        //    {
        //        //this.m_ParserMap[line, column].Add(derivation);
        //        string key = string.Format("{0}-{1}",)
        //    }
        //}
        /// <summary>
        /// 设置给定语法类型、单词类型所对应的推导式
        /// </summary>
        /// <param name="leftNode"></param>
        /// <param name="nextLeave"></param>
        /// <param name="function"></param>
        public void SetCell(ProductionNode leftNode, ProductionNode nextLeave, Derivation function)
        {
            //SetCell(this.m_LeftNodes[leftNode], this.m_NextLeaves[nextLeave], function);
            string         key  = string.Format("Left:{0} Terminal:{1}", leftNode, nextLeave);
            DerivationList list = null;

            if (this.m_ParserMap.TryGetValue(key, out list))
            {
                list.Add(function);
            }
            else
            {
                list = new DerivationList();
                list.Add(function);
                this.m_ParserMap.Add(key, list);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// From
        /// </summary>
        /// <param name="xDerivationList"></param>
        /// <returns></returns>
        public static DerivationList From(XElement xDerivationList)
        {
            if (xDerivationList == null)
            {
                return(null);
            }
            if (xDerivationList.Name != strDerivationList)
            {
                return(null);
            }
            var result = new DerivationList();

            result.AddRange(
                from item in xDerivationList.Elements(Derivation.strDerivation)
                select Derivation.From(item)
                );
            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取推导式列表
        /// </summary>
        /// <param name="leftNode">当前结非终点类型</param>
        /// <param name="nextLeave">要处理的终结点类型</param>
        /// <returns></returns>
        public DerivationList GetDerivationList(ProductionNode leftNode, ProductionNode nextLeave)
        {
            //#if DEBUG
            //            if (this.m_LeftNodes.ContainsKey(leftNode)
            //                && this.m_NextLeaves.ContainsKey(nextLeave))
            //#endif
            //                return this.GetDerivationList(this.m_LeftNodes[leftNode], this.m_NextLeaves[nextLeave]);
            //#if DEBUG
            //            else
            //                return null;
            //#endif
            //                return this.GetDerivationList(this.m_LeftNodes[leftNode], this.m_NextLeaves[nextLeave]);
            string         key  = string.Format("Left:{0} Terminal:{1}", leftNode, nextLeave);
            DerivationList list = null;

            if (this.m_ParserMap.TryGetValue(key, out list))
            {
                return(this.m_ParserMap[key]);
            }
            else
            {
                return(new DerivationList());
            }
        }