public static void Main(string[] args) { bool mergeErrors = false; string inputName = null; // ------------------------ you may need to process command line parameters: for (int i = 0; i < args.Length; i++) { if (args[i].ToLower() == "-l") { mergeErrors = true; } else { inputName = args[i]; } } if (inputName == null) { Console.WriteLine("No input file specified"); System.Environment.Exit(1); } int pos = inputName.LastIndexOf('/'); if (pos < 0) { pos = inputName.LastIndexOf('\\'); } string dir = inputName.Substring(0, pos + 1); Scanner.Init(inputName); Errors.Init(inputName, dir, mergeErrors); // ----------------------- add other initialization if required: Parser.Parse(); Errors.Summarize(); // ----------------------- add other finalization if required: }
public static void Main(string[] args) { bool mergeErrors = false, execution = true, immediate = false; string inputName = null; // ------------------------ process command line parameters: Console.WriteLine("Parva compiler 2.2017 October"); for (int i = 0; i < args.Length; i++) { if (args[i].ToLower().Equals("-l")) { mergeErrors = true; } else if (args[i].ToLower().Equals("-d")) { Parser.debug = true; } else if (args[i].ToLower().Equals("-n")) { execution = false; } else if (args[i].ToLower().Equals("-g")) { immediate = true; } else { inputName = args[i]; } } if (inputName == null) { Console.WriteLine("No input file specified"); Console.WriteLine("Usage: Parva [-l] [-d] [-n] [-g] source.pav"); Console.WriteLine("-l directs source listing to listing.txt"); Console.WriteLine("-d turns on debug mode"); Console.WriteLine("-n no execution after compilation"); Console.WriteLine("-g execute immediately after compilation (StdIn/StdOut)"); System.Environment.Exit(1); } // ------------------------ parser and scanner initialization int pos = inputName.LastIndexOf('/'); if (pos < 0) { pos = inputName.LastIndexOf('\\'); } string dir = inputName.Substring(0, pos + 1); Scanner.Init(inputName); Errors.Init(inputName, dir, mergeErrors); PVM.Init(); Table.Init(); // ------------------------ compilation Parser.Parse(); Errors.Summarize(); // ------------------------ interpretation bool assembledOK = Parser.Successful(); int initSP = CodeGen.GetInitSP(); string codeName = newFileName(inputName, ".cod"); int codeLength = CodeGen.GetCodeLength(); PVM.ListCode(codeName, codeLength); if (!assembledOK || codeLength == 0) { Console.WriteLine("Unable to interpret code"); System.Environment.Exit(1); } else if (!execution) { Console.WriteLine("\nCompiled: exiting with no execution requested"); System.Environment.Exit(1); } else { if (immediate) { PVM.QuickInterpret(codeLength, initSP); } char reply = 'n'; do { Console.Write("\n\nInterpret [y/N]? "); reply = (Console.ReadLine() + " ").ToUpper()[0]; if (reply == 'Y') { PVM.Interpret(codeLength, initSP); } } while (reply == 'Y'); } } // Main
public static void Main(string[] args) { bool mergeErrors = false; string inputName = null; // ------------------------ you may need to process command line parameters: for (int i = 0; i < args.Length; i++) { if (args[i].ToLower().Equals("-l")) { mergeErrors = true; } else { inputName = args[i]; } } if (inputName == null) { Console.WriteLine("No input file specified"); System.Environment.Exit(1); } int pos = inputName.LastIndexOf('/'); if (pos < 0) { pos = inputName.LastIndexOf('\\'); } string dir = inputName.Substring(0, pos + 1); /*++++ If the parser needs an output file, include a section like the following * and add a line * * public static OutFile output; * * to your ATG file. * * string outputName = null; * pos = inputName.LastIndexOf('.'); * if (pos < 0) outputName = inputName + ".out"; * else outputName = inputName.Substring(0, pos) + ".out"; * Parser.output = new OutFile(outputName); * if (Parser.output.OpenError()) { * Console.WriteLine("cannot open " + outputName); * System.Environment.Exit(1); * } * ++++++ */ Scanner.Init(inputName); Errors.Init(inputName, dir, mergeErrors); // ----------------------- add other initialization if required: Parser.Parse(); Errors.Summarize(); // ----------------------- add other finalization if required: /*++++ If the parser needs an output file, uncomment this section * Parser.output.Close(); ++++++ */ }