Exemplo n.º 1
0
		SymbolSet find(SymbolSet h) 
		{
			if (h==null) 
			{
				m_next = m_symbols.lahead;
				m_symbols.lahead = this;
				return this;
			}
			if (Equals(h,this))
				return h;
			return find(h.m_next);
		}
Exemplo n.º 2
0
		static bool Equals(SymbolSet s,SymbolSet t) 
		{
			if (s.m_set.Count!=t.m_set.Count)
				return false;
			IDictionaryEnumerator de = s.GetEnumerator();
			IDictionaryEnumerator ee = t.GetEnumerator();
			for (int pos=0; pos<s.Count; pos++) 
			{
				de.MoveNext(); ee.MoveNext();
				if (de.Key != ee.Key)
					return false;
			}
			return true;
		}
Exemplo n.º 3
0
		public void Print(SymbolSet x,string s)
		{
			Console.Write("Transition ("+m_ps.m_state+","+m_A.yytext+") "+s+" ");
			x.Print();
		}
Exemplo n.º 4
0
		public SymbolSet(SymbolSet s):this(s.m_symbols) { Add(s); }
Exemplo n.º 5
0
		public static void AddToRead(Transition a,SymbolSet s) { a.m_Read.Add(s); }
Exemplo n.º 6
0
		public static void AddToFollow(Transition a, SymbolSet s) { a.m_Follow.Add(s); }
Exemplo n.º 7
0
		public SymbolSet FirstOfRest(SymbolsGen syms) 
		{
			if (follow!=null)
				return follow;
			follow = new SymbolSet(syms); 
			bool broke=false;
			int n = m_prod.m_rhs.Count;
			for (int j=m_pos+1;j<n;j++) 
			{
				CSymbol s = (CSymbol)m_prod.m_rhs[j];
				foreach (CSymbol a in s.m_first.Keys)
						follow.CheckIn(a);
				if (!s.IsNullable()) 
				{
					broke = true;
					break;
				}
			}
			if (!broke) 
				follow.Add(m_prod.m_lhs.m_follow);
			follow = follow.Resolve();
			return follow;
		}
Exemplo n.º 8
0
 public static void AddToRead(Transition a, SymbolSet s)
 {
     a.m_Read.Add(s);
 }
Exemplo n.º 9
0
		public SymbolSet m_follow; // for LR(0) phase: allow EOFSymbol
		public bool AddFollow(SymbolSet map) 
		{ // CSymbol->bool : add contents of map to m_follow
			bool r = false;
			foreach(CSymbol a in map.Keys)
				r |= m_follow.CheckIn(a);
			return r;
		}
Exemplo n.º 10
0
		public ObjectList m_prods = new ObjectList(); // Production:  productions with this symbol as left side
		public void AddStartItems(ParseState pstate,SymbolSet follows) 
		{ 
			for (int pos=0;pos<m_prods.Count;pos++)	
			{
				Production p = (Production)m_prods[pos];
				pstate.MaybeAdd(new ProdItem(p, 0));
			}
		}
Exemplo n.º 11
0
		public CSymbol(SymbolsGen yyp) : base(yyp.m_lexer) 
		{ 
			m_parser = yyp;
			m_symtype = SymType.unknown; 
			m_prec = null;
			m_prod = null; 
			m_refSymbol = null;
			m_first = new SymbolSet(yyp);
			m_follow = new SymbolSet(yyp);
		}
Exemplo n.º 12
0
 public SymbolSet(SymbolSet s)
     : this(s.m_symbols)
 {
     this.Add(s);
 }
Exemplo n.º 13
0
 public static void AddToFollow(Transition a, SymbolSet s)
 {
     a.m_Follow.Add(s);
 }
Exemplo n.º 14
0
		public void Add (SymbolSet s) 
		{
			if (s==this)
				return;
			foreach (CSymbol k in s.Keys)
				AddIn(k);
		}
Exemplo n.º 15
0
		public void BuildLookback(Transition a)
		{
			SymbolsGen sg = a.m_ps.m_sgen;
			if (m_lookAhead!=null)
				return;
			m_lookAhead = new SymbolSet(sg);
			foreach (ParseState p in sg.m_symbols.m_states.Values) 
			{
				Transition b = (Transition)p.m_transitions[m_prod.m_lhs.yytext];
				if (b==null)
					continue;
				Path pa = new Path(p,m_prod.Prefix(m_prod.m_rhs.Count));
				if (pa.valid && pa.Top == a.m_ps)
					b.m_lookbackOf[this] = true;
			}
		}
Exemplo n.º 16
0
		public static SymbolSet operator+ (SymbolSet s,SymbolSet t) 
		{
			SymbolSet r = new SymbolSet(s);
			r.Add(t);
			return r.Resolve();
		}
Exemplo n.º 17
0
 public void Print(SymbolSet x, string s)
 {
     Console.Write("Transition (" + (object)this.m_ps.m_state + "," + this.m_A.yytext + ") " + s + " ");
     x.Print();
 }