static void Main(string[] args) { int count = 100; Console.WriteLine("[usage]RichTextParser textfile count"); Console.WriteLine(); Console.WriteLine("Now run {0} parses with preset text ...", count); string text = ParserValue.c_TestText; if (args.Length > 0) { string file = args[0]; if (File.Exists(file)) { text = File.ReadAllText(file); } else { Console.WriteLine("Can't read file '{0}'", file); return; } if (args.Length > 1) { try { count = int.Parse(args[1]); } catch { Console.WriteLine("arg '{0}' error", args[1]); return; } } } var parser = new Parser2(); Stopwatch w = new Stopwatch(); w.Start(); for (int i = 0; i < count; ++i) { var result = parser.Parse(text); } double t = w.ElapsedTicks * 1000.0 / Stopwatch.Frequency; Console.WriteLine("elapsed {0}ms for {1} parses, {2}ms/parse", t, count, t / count); }
public static void Main(string[] args) { //try to grab the file out of args[0] try{ string contents = File.ReadAllText(args[0]); string output = Scanner.Dispatcher(contents); Scanner.PrintTokies(); ArrayList outies = Scanner.GetTokenArray(); Console.WriteLine(output); Parser2 parser = new Parser2(output, outies, args[0]); parser.Parse(); } catch (IOException) { Console.WriteLine("Couldn't open file."); } catch (IndexOutOfRangeException) { Console.WriteLine("Expecting a file argument."); } }