public bool testToker2(string path) { Toker toker = new Toker(); string fqf = System.IO.Path.GetFullPath(path); if (!toker.open(fqf)) { Console.Write("\n can't open {0}\n", fqf); return(false); } toker.setSpecialSingleChars(new List <string> { "<", ">" }); toker.setSpecialCharPairs(new List <string> { "<<", "==" }); while (!toker.isDone()) { Token tok = toker.getTok(); Console.Write("\n -- line#{0, 4} : {1}", toker.lineCount(), tok); } toker.close(); return(true); }
//----< test for each tokenizer case by index>--- static private bool testTokenizer(int testIndex) { Toker toker = new Toker(); StreamWriter file = new StreamWriter("../../" + testCaseResult + testIndex + ".txt"); // read from the testcase cs file string fqf = System.IO.Path.GetFullPath("../../" + testCaseFileName + testIndex + ".cs"); // open the write to file if (!toker.open(fqf)) { file.Close(); Console.Write("\n can't open {0}\n", fqf); return(false); } else { Console.Write("\n processing file: {0}", fqf); } // write token into the output file untill eof while (!toker.isDone()) { StringBuilder tok = toker.getTok(); file.Write("\n -- line#{0, 4} : {1}", toker.lineCount(), tok); } toker.close(); file.Close(); return(compareTwoFiles("../../" + testCaseResult + testIndex + ".txt", "../../" + testCaseResultStandard + testIndex + ".txt")); }
//----< methods that used to initiate the tokenizer tester>----------- public bool testToken(string path) { string fqf = System.IO.Path.GetFullPath(path); if (!toker.open(fqf)) { Console.Write("\n can't open {0}\n", fqf); return(false); } while (!toker.isDone()) { Token tok = toker.getTok(); Console.Write("\n -- line#{0, 4} : {1}", toker.lineCount(), tok); } toker.close(); return(true); }
//----------------<Analyze dependency>--------------------------------------- public void ConnectNode(TypeAnalysis typea, string fqf) { List <string> namestore = new List <string>(); string filename = fqf.Substring(fqf.LastIndexOf('\\') + 1); CsNode <string, string> node = csgraph.findNode(filename); Toker toker = new Toker(); toker.doReturnComments = false; if (!toker.open(fqf)) { Console.Write("\n can't open {0}\n", fqf); } //else //{ // Console.Write("\n processing file: {0}\n", fqf); //} while (!toker.isDone()) { Token tok = toker.getTok(); if (tok == null) { continue; } if (typea.typetable_.table.ContainsKey(tok))//the key exist in the type table. { if (typea.typetable_.table[tok][0].namesp == "") { namestore.Add(tok); } else { List <TypeItem> list_it = typea.typetable_.table[tok]; foreach (TypeItem it in list_it) { if (namestore.Contains(it.namesp)) { //connect the node node.addChild(csgraph.findNode(it.file), ""); } } } } } toker.close(); }
static bool Requirement4(string file) { Console.Write("\n\n Demonstrate requirement 4: "); Console.Write("\n ============================\n"); Console.Write(" The file content: \n\n"); fs_ = new System.IO.StreamReader("../../" + file, true); int ch; while (!fs_.EndOfStream) { ch = fs_.Read(); Console.Write("{0}", (char)ch); } fs_.Close(); Console.Write("\n ============================\n"); Console.Write("The output: \n"); Toker toker = new Toker(); string fqf = System.IO.Path.GetFullPath("../../" + file); if (!toker.open(fqf)) { Console.Write("\n can't open {0}\n", fqf); return(false); } else { Console.Write("\n processing file: {0}", fqf); } while (!toker.isDone()) { StringBuilder tok = toker.getTok(); Console.Write("\n -- line#{0, 4} : {1}", toker.lineCount(), tok); } toker.close(); return(true); }
//----< close file stream >------------------------------------------ public void close() { toker.close(); }