示例#1
0
 public void MaybeAdd(ProdItem item)
 {
     if (!this.m_items.Add(item))
     {
         return;
     }
     this.m_changed = true;
 }
示例#2
0
        public void CheckClosure(ProdItem item)
        {
            CSymbol csymbol = item.Next();

            if (csymbol == null)
            {
                return;
            }
            csymbol.AddStartItems(this, item.FirstOfRest(csymbol.m_parser));
            if (!item.IsReducingAction())
            {
                return;
            }
            this.MaybeAdd(new ProdItem(item.m_prod, item.m_pos + 1));
        }
示例#3
0
 public void AddEntries()
 {
     for (ProdItemList prodItemList = this.m_items; prodItemList.m_pi != null; prodItemList = prodItemList.m_next)
     {
         ProdItem pi1 = prodItemList.m_pi;
         if (!pi1.m_done)
         {
             CSymbol csymbol = pi1.Next();
             if (csymbol != null && !pi1.IsReducingAction())
             {
                 ParseState parseState = new ParseState(this.m_sgen, csymbol);
                 parseState.MaybeAdd(new ProdItem(pi1.m_prod, pi1.m_pos + 1));
                 for (ProdItemList next = prodItemList.m_next; next != null && next.m_pi != null; next = next.m_next)
                 {
                     ProdItem pi2 = next.m_pi;
                     if (csymbol == pi2.Next())
                     {
                         parseState.MaybeAdd(new ProdItem(pi2.m_prod, pi2.m_pos + 1));
                         pi2.m_done = true;
                     }
                 }
                 if (!this.m_items.AtEnd)
                 {
                     if (csymbol.IsAction())
                     {
                         ParseState next = parseState.CheckExists();
                         foreach (CSymbol key in (IEnumerable)csymbol.m_follow.Keys)
                         {
                             if (key != this.m_sgen.m_symbols.EOFSymbol)
                             {
                                 this.GetTransition(key).m_next = new ParserShift((ParserAction)csymbol, next);
                             }
                         }
                     }
                     else
                     {
                         this.GetTransition(csymbol).m_next = new ParserShift((ParserAction)null, parseState.CheckExists());
                     }
                 }
             }
         }
     }
 }
示例#4
0
 public void ReduceStates()
 {
     for (ProdItemList prodItemList = this.m_items; prodItemList.m_pi != null; prodItemList = prodItemList.m_next)
     {
         ProdItem pi = prodItemList.m_pi;
         if (pi.Next() == null)
         {
             Production prod = pi.m_prod;
             if (prod.m_pno != 0)
             {
                 int          count = prod.m_rhs.Count;
                 CSymbol      rh;
                 ParserReduce parserReduce;
                 if (count > 0 && (rh = (CSymbol)prod.m_rhs[count - 1]) != null && rh.IsAction())
                 {
                     ParserAction action = (ParserAction)rh;
                     action.m_len = count;
                     parserReduce = new ParserReduce(action, count - 1, prod);
                 }
                 else
                 {
                     this.m_sgen.m_lexer.yytext = "%" + prod.m_lhs.yytext;
                     this.m_sgen.m_prod         = prod;
                     ParserSimpleAction parserSimpleAction = new ParserSimpleAction(this.m_sgen);
                     parserSimpleAction.m_sym = prod.m_lhs;
                     parserSimpleAction.m_len = count;
                     parserReduce             = new ParserReduce((ParserAction)parserSimpleAction, count, prod);
                 }
                 foreach (CSymbol key in (IEnumerable)pi.m_prod.m_lhs.m_follow.Keys)
                 {
                     this.GetTransition(key).m_reduce[(object)prod] = (object)parserReduce;
                 }
             }
         }
     }
 }
示例#5
0
		public void CheckClosure(ProdItem item) 
		{
			CSymbol ss = item.Next();
			if (ss!=null) 
			{
				ss.AddStartItems(this,item.FirstOfRest(ss.m_parser));
				if (item.IsReducingAction())
					MaybeAdd(new ProdItem(item.m_prod, item.m_pos+1));
			}
		}
示例#6
0
		public void MaybeAdd(ProdItem item) 
		{ // called by CSymbol.AddStartItems
			if (!m_items.Add(item))
				return;
			m_changed = true;
		}
示例#7
0
		public ProdItemList() { m_pi=null; m_next=null; } // sentinel only
		public bool Add(ProdItem pi) 
		{
			if (m_pi==null) 
			{  // m_pi==null iff m_next==null
				m_next = new ProdItemList();
				m_pi = pi; 
			} 
			else if (m_pi.m_prod.m_pno < pi.m_prod.m_pno ||
				(m_pi.m_prod.m_pno==pi.m_prod.m_pno && m_pi.m_pos<pi.m_pos)) 
			{
				m_next = new ProdItemList(m_pi,m_next);
				m_pi = pi;
			} 
			else if (m_pi.m_prod.m_pno == pi.m_prod.m_pno && m_pi.m_pos==pi.m_pos) 
				return false;
			else
				return m_next.Add(pi);
			return true; // was added
		}
示例#8
0
		public ProdItemList() { m_pi=null; m_next=null; } // sentinel only
示例#9
0
		public ProdItemList (ProdItem pi,ProdItemList n) { m_pi=pi; m_next=n; }
示例#10
0
文件: parser.cs 项目: hdinh/OmahaBot
 public ProdItemList()
 {
     m_pi=null; m_next=null;
 }