public void Start(CsReader inFile) { m_state = "YYINITIAL"; // 4.3e inFile = new CsReader(inFile, m_tokens.m_encoding); m_LineManager = inFile.lm; if (!inFile.Eof()) { for (m_buf = inFile.ReadLine(); !inFile.Eof(); m_buf += inFile.ReadLine()) { m_buf += "\n"; } } if (m_tokens.toupper) { m_buf = m_buf.ToUpper(); } m_pch = 0; }
public void Start(CsReader inFile) { this.m_state = "YYINITIAL"; inFile = new CsReader(inFile, this.m_tokens.m_encoding); this.m_LineManager = inFile.lm; if (!inFile.Eof()) { this.m_buf = inFile.ReadLine(); while (!inFile.Eof()) { this.m_buf += "\n"; this.m_buf += inFile.ReadLine(); } } if (this.m_tokens.toupper) { this.m_buf = this.m_buf.ToUpper(); } this.m_pch = 0; }
protected string ToBraceIfFound(ref string buf,ref int p,ref int max,CsReader inf) { int q = p; int brack = Braces(0,buf,ref p,max); string rv = buf.Substring(q,p-q); while (inf!=null && brack>0) { buf=inf.ReadLine(); max=buf.Length; if (max==0) Error(47,q,"EOF in action or class def??"); p=0; rv += '\n'; brack = Braces(brack,buf,ref p,max); rv += buf.Substring(0,p); } return rv; }
protected string ToBraceIfFound(ref string buf, ref int p, ref int max, CsReader inf) { int num = p; int a = this.Braces(0, buf, ref p, max); string str1 = buf.Substring(num, p - num); while (inf != null && a > 0) { buf = inf.ReadLine(); if (buf == null || p == 0) { this.Error(47, num, "EOF in action or class def??"); } max = buf.Length; p = 0; string str2 = str1 + (object)'\n'; a = this.Braces(a, buf, ref p, max); str1 = str2 + buf.Substring(0, p); } return(str1); }
protected string ToBraceIfFound(ref string buf, ref int p, ref int max, CsReader inf) { int q = p; int brack = Braces(0, buf, ref p, max); string rv = buf.Substring(q, p - q); while (inf != null && brack > 0) { buf = inf.ReadLine(); max = buf.Length; if (max == 0) { Error(47, q, "EOF in action or class def??"); } p = 0; rv += '\n'; brack = Braces(brack, buf, ref p, max); rv += buf.Substring(0, p); } return(rv); }
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); }
/// <exclude/> public void Start(CsReader inFile) { m_state="YYINITIAL"; // 4.3e inFile = new CsReader(inFile,m_tokens.m_encoding); m_LineManager = inFile.lm; if (!inFile.Eof()) for (m_buf = inFile.ReadLine(); !inFile.Eof(); m_buf += inFile.ReadLine()) m_buf+="\n"; if (m_tokens.toupper) m_buf = m_buf.ToUpper(); m_pch = 0; }
/// <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("}"); }
public int 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]; 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]; } int num = new TokClassDef(this,name,bas).m_yynum; m_outFile.WriteLine("//%+{0}+{1}",name,num); m_outFile.Write("public class "); m_outFile.Write(name); 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 = null; try // 4.7c { s = (TOKEN)syms.Parse(str); } catch (Exception) {} if (s==null) { Error(48,p,"Bad class definition for "+name); return -1; } 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("public override string yyname { get { return \""+name+"\"; }}"); m_outFile.WriteLine("public override int yynum { get { return "+num+"; }}"); if (!defconseen) { if (lx) m_outFile.Write("public "+name+"(Lexer yyl):base(yyl){}"); else m_outFile.Write("public "+name+"(Parser yyp):base(yyp){}"); } m_outFile.WriteLine("}"); return num; }