public void WriteParser() { Generator g = new Generator(tab); int oldPos = buffer.Pos; // Pos is modified by CopySourcePart symSet.Add(tab.allSyncSets); fram = g.OpenFrame("Parser.frame"); gen = g.OpenGen("Parser.cs"); err = new StringWriter(); foreach (Symbol sym in tab.terminals) GenErrorMsg(tErr, sym); g.GenCopyright(); g.SkipFramePart("-->begin"); if (usingPos != null) { CopySourcePart(usingPos, 0); gen.WriteLine(); } g.CopyFramePart("-->namespace"); /* AW open namespace, if it exists */ if (tab.nsName != null && tab.nsName.Length > 0) { gen.WriteLine("namespace {0} {{", tab.nsName); gen.WriteLine(); } g.CopyFramePart("-->constants"); GenTokens(); /* ML 2002/09/07 write the token kinds */ gen.WriteLine("\tpublic const int maxT = {0};", tab.terminals.Count-1); GenPragmas(); /* ML 2005/09/23 write the pragma kinds */ g.CopyFramePart("-->declarations"); CopySourcePart(tab.semDeclPos, 0); g.CopyFramePart("-->pragmas"); GenCodePragmas(); g.CopyFramePart("-->productions"); GenProductions(); g.CopyFramePart("-->parseRoot"); gen.WriteLine("\t\t{0}();", tab.gramSy.name); if (tab.checkEOF) gen.WriteLine("\t\tExpect(0);"); g.CopyFramePart("-->initialization"); InitSets(); g.CopyFramePart("-->errors"); gen.Write(err.ToString()); g.CopyFramePart(null); /* AW 2002-12-20 close namespace, if it exists */ if (tab.nsName != null && tab.nsName.Length > 0) gen.Write("}"); gen.Close(); buffer.Pos = oldPos; }
public void WriteScanner() { Generator g = new Generator(tab); fram = g.OpenFrame("Scanner.frame"); gen = g.OpenGen("Scanner.cs"); if (dirtyDFA) MakeDeterministic(); g.GenCopyright(); g.SkipFramePart("-->begin"); g.CopyFramePart("-->namespace"); if (tab.nsName != null && tab.nsName.Length > 0) { gen.Write("namespace "); gen.Write(tab.nsName); gen.Write(" {"); } g.CopyFramePart("-->declarations"); gen.WriteLine("\tconst int maxT = {0};", tab.terminals.Count - 1); gen.WriteLine("\tconst int noSym = {0};", tab.noSym.n); if (ignoreCase) gen.Write("\tchar valCh; // current input character (for token.val)"); g.CopyFramePart("-->initialization"); WriteStartTab(); g.CopyFramePart("-->casing1"); if (ignoreCase) { gen.WriteLine("\t\tif (ch != Buffer.EOF) {"); gen.WriteLine("\t\t\tvalCh = (char) ch;"); gen.WriteLine("\t\t\tch = char.ToLower((char) ch);"); gen.WriteLine("\t\t}"); } g.CopyFramePart("-->casing2"); gen.Write("\t\t\ttval[tlen++] = "); if (ignoreCase) gen.Write("valCh;"); else gen.Write("(char) ch;"); g.CopyFramePart("-->comments"); Comment com = firstComment; int comIdx = 0; while (com != null) { GenComment(com, comIdx); com = com.next; comIdx++; } g.CopyFramePart("-->literals"); GenLiterals(); g.CopyFramePart("-->scan1"); gen.Write("\t\t\t"); if (tab.ignored.Elements() > 0) { PutRange(tab.ignored); } else { gen.Write("false"); } g.CopyFramePart("-->scan2"); if (firstComment != null) { gen.Write("\t\tif ("); com = firstComment; comIdx = 0; while (com != null) { gen.Write(ChCond(com.start[0])); gen.Write(" && Comment{0}()", comIdx); if (com.next != null) gen.Write(" ||"); com = com.next; comIdx++; } gen.Write(") return NextToken();"); } if (hasCtxMoves) { gen.WriteLine(); gen.Write("\t\tint apx = 0;"); } /* pdt */ g.CopyFramePart("-->scan3"); for (State state = firstState.next; state != null; state = state.next) WriteState(state); g.CopyFramePart(null); if (tab.nsName != null && tab.nsName.Length > 0) gen.Write("}"); gen.Close(); }