Inheritance: ParserEntry
Exemple #1
0
        public static void BuildParseTable(Transition t)
        {
            YyParser     symbols       = t.m_ps.m_sgen.m_symbols;
            ParsingInfo  parsingInfo   = t.ParsingInfo;
            ParserReduce parserReduce1 = (ParserReduce)null;

            foreach (ParserReduce parserReduce2 in (IEnumerable)t.m_reduce.Values)
            {
                if ((!t.m_ps.m_sgen.m_lalrParser ? (parserReduce2.m_prod.m_lhs.m_follow.Contains(t.m_A) ? 1 : 0) : (parserReduce2.m_lookAhead.Contains(t.m_A) ? 1 : 0)) != 0)
                {
                    if (parserReduce1 != null)
                    {
                        symbols.erh.Error(new CSToolsException(12, string.Format("reduce/reduce conflict {0} vs {1}", (object)parserReduce1.m_prod.m_pno, (object)parserReduce2.m_prod.m_pno) + string.Format(" state {0} on {1}", (object)t.m_ps.m_state, (object)t.m_A.yytext)));
                    }
                    parserReduce1 = parserReduce2;
                }
            }
            if (t.m_next != null && t.m_A != symbols.EOFSymbol)
            {
                if (parserReduce1 == null)
                {
                    parsingInfo.m_parsetable[(object)t.m_ps.m_state] = (object)t.m_next;
                }
                else
                {
                    switch (t.m_A.ShiftPrecedence(parserReduce1.m_prod, t.m_ps))
                    {
                    case Precedence.PrecType.left:
                        parsingInfo.m_parsetable[(object)t.m_ps.m_state] = (object)t.m_next;
                        break;

                    case Precedence.PrecType.right:
                        parsingInfo.m_parsetable[(object)t.m_ps.m_state] = (object)parserReduce1;
                        break;
                    }
                }
            }
            else
            {
                if (parserReduce1 == null)
                {
                    return;
                }
                parsingInfo.m_parsetable[(object)t.m_ps.m_state] = (object)parserReduce1;
            }
        }
Exemple #2
0
        public new static object Serialise(object o, Serialiser s)
        {
            if (s == null)
            {
                return((object)new ParserReduce());
            }
            ParserReduce parserReduce = (ParserReduce)o;

            if (s.Encode)
            {
                ParserEntry.Serialise((object)parserReduce, s);
                s.Serialise((object)parserReduce.m_depth);
                s.Serialise((object)parserReduce.m_prod);
                return((object)null);
            }
            ParserEntry.Serialise((object)parserReduce, s);
            parserReduce.m_depth = (int)s.Deserialise();
            parserReduce.m_prod  = (Production)s.Deserialise();
            return((object)parserReduce);
        }
Exemple #3
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;
                 }
             }
         }
     }
 }
Exemple #4
0
		public void ReduceStates() 
		{
			ProdItemList pil;
			for (pil=m_items; pil.m_pi!=null; pil=pil.m_next) 
			{
				ProdItem item = pil.m_pi;
				CSymbol s = item.Next();
				if (s==null) 
				{ // item is a reducing item
					Production rp = item.m_prod;
					if (rp.m_pno==0) // except for production 0: S'->S-|
						continue;
					// reduce item: deal with it 
					int n = rp.m_rhs.Count;
					CSymbol a;
					ParserReduce pr;
					if (n>0 && (a=(CSymbol)rp.m_rhs[n-1])!=null && a.IsAction()) 
					{
						ParserAction pa = (ParserAction)a;
						pa.m_len = n;
						pr = new ParserReduce(pa,n-1,rp);
					} 
					else 
					{
						m_sgen.m_lexer.yytext = "%"+rp.m_lhs.yytext;
						m_sgen.m_prod = rp;
						ParserSimpleAction sa = new ParserSimpleAction(m_sgen);
						sa.m_sym = (CSymbol)rp.m_lhs;
						sa.m_len = n;
						pr = new ParserReduce(sa,n,rp);
					}
					foreach (CSymbol ss in item.m_prod.m_lhs.m_follow.Keys)
						GetTransition(ss).m_reduce[rp]=pr;
				}
			}
		}