public void GetParser(Lexer m_lexer) { Serialiser b = new Serialiser(arr); b.VersionCheck(); m_startSymbol = (CSymbol)b.Deserialise(); m_startSymbol.kids = new ObjectList(); // 4.2a m_accept = (ParseState)b.Deserialise(); m_states = (Hashtable)b.Deserialise(); literals = (Hashtable)b.Deserialise(); symbolInfo = (Hashtable)b.Deserialise(); m_concrete = (bool)b.Deserialise(); GetEOF(m_lexer); }
public int[] arr; // defined in generated subclass public void GetEOF(Lexer yyl) { EOFSymbol = (EOF)symbols["EOF"]; if (EOFSymbol==null) EOFSymbol = new EOF(yyl); }
public bool Contains(CSymbol a) { return m_set.Contains(a); }
public void ClassInit(SymbolsGen yyp) { Special = new CSymbol(yyp); Special.yytext="S'"; EOFSymbol = new EOF(yyp).Resolve(); }
public Hashtable m_transitions = new Hashtable(); // string -> Transition public Transition GetTransition(CSymbol s) { Transition t = (Transition)m_transitions[s.yytext]; if (t!=null) return t; return new Transition(this,s); }
public void AddFirst(CSymbol s, int j) { for (;j<m_rhs.Count;j++) { CSymbol r = (CSymbol)m_rhs[j]; s.AddFollow(r.m_first); if (!r.IsNullable()) return; } }
public CSymbol[] Prefix(int i) { CSymbol[] r = new CSymbol[i]; for (int j=0;j<i;j++) r[j] = (CSymbol)m_rhs[j]; return r; }
public void ClassInit(SymbolsGen yyp) { EmptySequence = new CSymbol(yyp); EmptySequence.yytext="e"; Special = new CSymbol(yyp); Special.yytext="S'"; EOFSymbol = new EOF(yyp).Resolve(); }
public void AddToRhs(CSymbol s) { this.m_rhs.Add((object)s); this.m_actionsOnly = this.m_actionsOnly && s.IsAction(); }
public override void Print(ParseState ps,CSymbol s) { base.Print(ps,s); while (s.m_symtype==CSymbol.SymType.nodesymbol) s = s.m_refSymbol; Transition t = (Transition)ps.m_transitions[s.yytext]; Transition.Follow(t).Print(); }
public override void Print(ParseState ps,CSymbol s) { base.Print(ps,s); Console.Write(" "); m_lookAhead.Print(); }
public virtual void Print(ParseState ps,CSymbol s) { Console.Write(" {0} {1} ",s.yytext,str); if (m_action!=null) m_action.Print(); }
public override void SimpleAction(ParserSimpleAction a) { string str = a.yytext.Substring(1, a.yytext.Length-1); if (str=="null") { m_lexer.yytext = "Null"; a.m_sym = (new CSymbol(this)).Resolve(); NewConstructor(ref a.m_sym,", "+m_prod.m_lhs.m_yynum+"){}"); return; } if (str.Length==0) str = m_prod.m_lhs.yytext; CSymbol s = (CSymbol)m_symbols.symbols[str]; if (s==null) { // not there: define a new node type //Console.WriteLine("Symbol {0} needs defining",str); m_lexer.yytext = str; s = new CSymbol(this); m_symbols.symbols[str] = s; s.m_symtype = CSymbol.SymType.nodesymbol; s.m_refSymbol = (CSymbol)m_prod.m_lhs; s.m_emitted = true; m_outFile.WriteLine("public class "+str+" : "+s.m_refSymbol.yytext+" { "); m_outFile.WriteLine(" public "+str+"(Parser yyq):base(yyq) { }}"); } else if (s.m_refSymbol!=null) // 4.5c { CSymbol t=s; // 4.5d while (t!=null && t!=(CSymbol)m_prod.m_lhs) t=t.m_refSymbol; if (t==null) Error(46,m_lexer.m_pch,"Simple action "+s.yytext+" does not match symbol type "+m_prod.m_lhs.yytext); // 4.5d } // 4.5c else s.m_refSymbol = (CSymbol)m_prod.m_lhs; a.m_sym = s; int ch; str = ")"; NextNonWhite(out ch); if (ch=='(') { ch = m_lexer.GetChar(); str = ","+GetBracketedSeq(ref ch,')').Substring(1); NextNonWhite(out ch); } if (str==",)") // 4.0d str=")"; string init = "{}"; if (ch=='{') { ch = m_lexer.GetChar(); string ts = GetBracketedSeq(ref ch,'}'); // 4.5g init = "{ "+m_outname+" yyp=("+m_outname+")yyq;\n"+ ts.Substring(1); // 4.5g 4.5h NextNonWhite(out ch); } init = str + init; NewConstructor(ref a.m_sym,init); }
public override void ClassDefinition(string bas) { string line, name; int n = m_lexer.yytext.Length; line = m_lexer.yytext; int num = EmitClassDefin(m_lexer.m_buf,ref m_lexer.m_pch,m_lexer.m_buf.Length,null,bas,out bas,out name,false); m_lexer.Advance(); m_lexer.yytext = name; CSymbol s = new CSymbol(this); s.m_yynum = num; s = s.Resolve(); s.m_defined = true; s.m_emitted = true; if (line[1]=='n') { s.m_symtype = CSymbol.SymType.nodesymbol; if (m_symbols.symbols.Contains(bas)) s.m_refSymbol = (CSymbol)m_symbols.symbols[bas]; else m_symbols.erh.Error(new CSToolsFatalException(44,s,"Unknown base type "+bas+": reorder declarations?")); } }
public Path(ParseState q,CSymbol[] x) { m_states = new ParseState[x.Length+1]; ParseState c; c = m_states[0] = q; for (int j=0;j<x.Length;j++) { int k; for (k=j;k<x.Length;k++) if (!x[k].IsAction()) break; if (k>=x.Length) { m_states[j+1] = c; continue; } Transition t = (Transition)c.m_transitions[x[k].yytext]; if (t==null || t.m_next==null) { valid = false; break; } c = m_states[j+1] = t.m_next.m_next; } }
public Transition GetTransition(CSymbol s) { return((Transition)this.m_transitions[(object)s.yytext] ?? new Transition(this, s)); }
public bool Contains(CSymbol a) { return(this.m_set.Contains((object)a)); }
public PrecReference(Lexer lx,TOKEN t) : base(lx) { precref = ((CSymbol)t).Resolve(); new SymbolType(((ptokens)lx).m_sgen,t.yytext,true); }
public SymbolSet lahead = null; // support for lookahead sets public bool Find(CSymbol sym) { if (sym.yytext.Equals("Null")) // special case return true; if (sym.yytext[0]=='\'') return true; if (stypes==null) return false; return stypes._Find(sym.yytext)!=null; }
// proxies for constructors internal void NewConstructor(ref CSymbol s,string str) { // may update s to a new node type // we have just seen a new initialiser for s if (str.Length==0) return; CSymbol bas = s; string newname; for (int variant=1;;variant++) { // get a genuinely new identifier newname = String.Format("{0}_{1}", bas.yytext, variant); s = (CSymbol)m_symbols.symbols[newname]; if (s==null) break; } m_lexer.yytext = newname; s = (new CSymbol(this)).Resolve(); s.m_symtype = CSymbol.SymType.nodesymbol; s.m_refSymbol = bas; s.m_emitted = true; m_outFile.WriteLine(); m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine("public class "+newname+" : "+bas.yytext+" {"); m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine(@"/// <param name='yyq'></param>"); m_outFile.WriteLine(" public "+newname+"(Parser yyq):base(yyq"+str+"}"); }
public SymbolType(SymbolsGen yyp,string name,bool defined) { Lexer yyl = yyp.m_lexer; int p = name.IndexOf("+"); int num = 0; if (p>0) { num = int.Parse(name.Substring(p+1)); if (num> yyp.LastSymbol) yyp.LastSymbol = num; name = name.Substring(0,p); } yyl.yytext = name; CSymbol s = new CSymbol(yyp); if (num>0) s.m_yynum = num; s = s.Resolve(); if (defined) s.m_defined = true; m_name = name; m_next=yyp.stypes; yyp.stypes=this; }
public override void SimpleAction(ParserSimpleAction a) { string str = a.yytext.Substring(1, a.yytext.Length-1); if (str=="null") { m_lexer.yytext = "Null"; a.m_sym = (new CSymbol(this)).Resolve(); NewConstructor(ref a.m_sym,",\""+m_prod.m_lhs.yytext+"\"){}"); return; } if (str.Length==0) str = m_prod.m_lhs.yytext; CSymbol s = (CSymbol)m_symbols.symbols[str]; if (s==null) { // not there: define a new node type //Console.WriteLine("Symbol {0} needs defining",str); m_lexer.yytext = str; s = new CSymbol(this); m_symbols.symbols[str] = s; s.m_symtype = CSymbol.SymType.nodesymbol; s.m_refSymbol = (CSymbol)m_prod.m_lhs; s.m_emitted = true; m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine("public class "+str+" : "+s.m_refSymbol.yytext+" { "); m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine(@"/// <param name='yyq'></param>"); m_outFile.WriteLine(" public "+str+"(Parser yyq):base(yyq) { }}"); } a.m_sym = s; int ch; str = ")"; NextNonWhite(out ch); if (ch=='(') { ch = m_lexer.GetChar(); str = ","+GetBracketedSeq(ref ch,')').Substring(1); NextNonWhite(out ch); } if (str==",)") // 4.0d str=")"; string init = "{}"; if (ch=='{') { ch = m_lexer.GetChar(); init = "yyp=("+m_outname+")yyq;\n"+ GetBracketedSeq(ref ch,'}'); NextNonWhite(out ch); } init = str + init; NewConstructor(ref a.m_sym,init); }
public Transition(ParseState p,CSymbol a) { m_ps = p; m_A = a; m_tno = p.m_sgen.m_trans++; p.m_transitions[a.yytext] = this; }
public static int Check(CSymbol s, Production p, int d) { if (s.m_prec==null) return 0; int a = CheckType(s.m_prec, PrecType.after,d+1); int b = CheckType(s.m_prec, PrecType.left,d+1); if (a>b) return a - p.m_prec; else return b - p.m_prec; }
public bool Accessor(CSymbol[] x) { return new Path(x).Top == this; }
public bool CouldStart(CSymbol nonterm) { return false; }
public ParseState(SymbolsGen syms,CSymbol acc) { m_sgen = syms; m_state=syms.state++; m_accessingSymbol=acc; m_items = new ProdItemList(); }
public Production(SymbolsGen syms) { m_lhs=null; m_prec=0; m_pno=syms.pno++; m_actionsOnly = true; syms.prods.Add(this); }
public bool CheckIn(CSymbol a) { if (Contains(a)) return false; AddIn(a); return true; }
public Production(SymbolsGen syms,CSymbol lhs) { m_lhs=lhs; m_prec=0; m_pno=syms.pno++; m_actionsOnly=true; syms.prods.Add(this); lhs.m_prods.Add(this); }
public void AddIn (CSymbol t) { m_set[t] = true; }
public Hashtable m_alias = new Hashtable(); // string->int public void AddToRhs(CSymbol s) { m_rhs.Add(s); m_actionsOnly = m_actionsOnly && s.IsAction(); }
public Path(CSymbol[] x) : this((ParseState)(x[0].m_parser.m_symbols.m_states[0]),x) {}
public void AddIn(CSymbol t) { this.m_set[(object)t] = (object)true; }