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); }
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; }
public void Print(SymbolSet x,string s) { Console.Write("Transition ("+m_ps.m_state+","+m_A.yytext+") "+s+" "); x.Print(); }
public SymbolSet(SymbolSet s):this(s.m_symbols) { Add(s); }
public static void AddToRead(Transition a,SymbolSet s) { a.m_Read.Add(s); }
public static void AddToFollow(Transition a, SymbolSet s) { a.m_Follow.Add(s); }
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; }
public static void AddToRead(Transition a, SymbolSet s) { a.m_Read.Add(s); }
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; }
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)); } }
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); }
public SymbolSet(SymbolSet s) : this(s.m_symbols) { this.Add(s); }
public void Add (SymbolSet s) { if (s==this) return; foreach (CSymbol k in s.Keys) AddIn(k); }
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; } }
public static SymbolSet operator+ (SymbolSet s,SymbolSet t) { SymbolSet r = new SymbolSet(s); r.Add(t); return r.Resolve(); }
public void Print(SymbolSet x, string s) { Console.Write("Transition (" + (object)this.m_ps.m_state + "," + this.m_A.yytext + ") " + s + " "); x.Print(); }