public int EmitClassDefin( string b, ref int p, int max, CsReader inf, string defbas, out string bas, out string name, bool lx) { bool flag = false; name = ""; bas = defbas; if (lx) { this.NonWhite(b, ref p, max); } this.White(b, ref p, max); while (p < max && b[p] != '{' && (b[p] != ':' && b[p] != ';') && (b[p] != ' ' && b[p] != '\t' && b[p] != '\n')) { name += (string)(object)b[p]; ++p; } this.White(b, ref p, max); if (b[p] == ':') { ++p; this.White(b, ref p, max); bas = ""; while (p < max && b[p] != ' ' && (b[p] != '{' && b[p] != '\t') && (b[p] != ';' && b[p] != '\n')) { bas += (string)(object)b[p]; ++p; } } int yynum = new TokClassDef(this, name, bas).m_yynum; this.m_outFile.WriteLine("//%+{0}+{1}", (object)name, (object)yynum); this.m_outFile.Write("public class "); this.m_outFile.Write(name); this.m_outFile.Write(" : " + bas); this.m_outFile.WriteLine("{"); do { if (p >= max) { b += inf.ReadLine(); max = b.Length; } this.White(b, ref p, max); }while (p >= max); if (b[p] != ';') { cs0syntax cs0syntax = new cs0syntax((YyParser) new yycs0syntax(), this.erh); ((cs0tokens)cs0syntax.m_lexer).Out = this.m_outname; cs0syntax.Cls = name; cs0syntax.Out = this.m_outname; if (lx) { cs0syntax.Ctx = "Lexer yyl"; cs0syntax.Par = "yym"; } else { cs0syntax.Ctx = "Parser yyp"; cs0syntax.Par = "yyq"; } string braceIfFound = this.ToBraceIfFound(ref b, ref p, ref max, inf); TOKEN token = (TOKEN)null; try { token = (TOKEN)cs0syntax.Parse(braceIfFound); } catch (Exception) { } if (token == null) { this.Error(48, p, "Bad class definition for " + name); return(-1); } token.yytext = token.yytext.Replace("yyq", "((" + this.m_outname + ")yyp)"); token.yytext = token.yytext.Replace("yym", "((" + this.m_outname + ")yyl)"); string yytext = token.yytext; char[] chArray = new char[1] { '\n' }; foreach (string str in yytext.Split(chArray)) { this.m_outFile.WriteLine(str); } flag = cs0syntax.defconseen; } this.m_outFile.WriteLine("public override string yyname { get { return \"" + name + "\"; }}"); this.m_outFile.WriteLine("public override int yynum { get { return " + (object)yynum + "; }}"); if (!flag) { if (lx) { this.m_outFile.Write("public " + name + "(Lexer yyl):base(yyl){}"); } else { this.m_outFile.Write("public " + name + "(Parser yyp):base(yyp){}"); } } this.m_outFile.WriteLine("}"); return(yynum); }
/// <summary/> public void EmitClassDefin(string b, ref int p, int max, CsReader inf, string defbas, out string bas, out string name, bool lx) { bool defconseen = false; name = ""; bas = defbas; if (lx) { NonWhite(b, ref p, max); } White(b, ref p, max); for (; p < max && b[p] != '{' && b[p] != ':' && b[p] != ';' && b[p] != ' ' && b[p] != '\t' && b[p] != '\n'; p++) { name += b[p]; } m_outFile.WriteLine("//%+{0}", name); m_outFile.WriteLine(@"/// <summary/>"); m_outFile.Write("public class "); m_outFile.Write(name); White(b, ref p, max); if (b[p] == ':') { p++; White(b, ref p, max); for (bas = ""; p < max && b[p] != ' ' && b[p] != '{' && b[p] != '\t' && b[p] != ';' && b[p] != '\n'; p++) { bas += b[p]; } } new TokClassDef(this, name, bas); m_outFile.Write(" : " + bas); m_outFile.WriteLine("{"); do { if (p >= max) { b += inf.ReadLine(); max = b.Length; } White(b, ref p, max); } while (p >= max); if (b[p] != ';') { cs0syntax syms = new cs0syntax(new yycs0syntax(), erh); cs0tokens tks = (cs0tokens)syms.m_lexer; tks.Out = m_outname; // syms.m_debug = true; syms.Cls = name; syms.Out = m_outname; if (lx) { syms.Ctx = "Lexer yyl"; syms.Par = "yym"; } else { syms.Ctx = "Parser yyp"; syms.Par = "yyq"; } string str = ToBraceIfFound(ref b, ref p, ref max, inf); TOKEN s = (TOKEN)syms.Parse(str); if (s == null) { Error(48, p, "Bad class definition for " + name); return; } s.yytext = s.yytext.Replace("yyq", "((" + m_outname + ")yyp)"); s.yytext = s.yytext.Replace("yym", "((" + m_outname + ")yyl)"); string[] ss = s.yytext.Split('\n'); for (int j = 0; j < ss.Length; j++) { m_outFile.WriteLine(ss[j]); } defconseen = syms.defconseen; } m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine("public override string yyname() { return \"" + name + "\"; }"); if (!defconseen) { if (lx) { m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine(@"/// <param name='yyl'></param>"); m_outFile.Write("public " + name + "(Lexer yyl):base(yyl){}"); } else { m_outFile.WriteLine(@"/// <summary/>"); m_outFile.WriteLine(@"/// <param name='yyp'></param>"); m_outFile.Write("public " + name + "(Parser yyp):base(yyp){}"); } } m_outFile.WriteLine("}"); }