While.CommandLineOptions.Print C# (CSharp) Method

Print() public static method

public static Print ( ) : void
return void
        public static void Print()
        {
            Console.Error.WriteLine(@"
            Compiler Options:

            /? or /help            Print this help message

            /out:<filename>        Specify the name of the compiled executable. If
            /o:<filename>          this is not specified the name of the input file
                       plus .exe will be used.

            /debug                 Include debug information in compiled file
            /d

            /plugins:<p1>[,p2...]  Load the given plugins and let them process the
            /p:<p1>[,p2]           abstract syntax tree before compilation. Plugins
                       implement the ICompilerPlugin interface and are
                       stored in a plugins folder in the folder where
                       wc.exe resides.

            /coursesyntax          Use the modified syntax as I learned it in the
            /c                     Program Analysis course taught at DTU. This means
                       that () are not used for if and while blocks,
                       instead if and while blocks end with fi and od
                       respectively. This switch also means that all
                       variables must be declared before use inside of
                       begin-end blocks.

                       Example:

                       begin
                           var x;
                           x := 3;
                           if x < 4 then
                               write 1
                           else
                               write 2
                           fi;
                           begin
                               var y;
                               y := x;
                               while x < 20 do
                                   x := x +1;
                                   skip
                               od
                           end;
                           skip
                       end

            ");
        }

Usage Example

コード例 #1
0
        public static int Main(string[] args)
        {
            try {
                Version v       = Assembly.GetExecutingAssembly().GetName().Version;
                string  version = v.Major + "." + v.Minor + "." + v.Build;
                Console.WriteLine("While.NET Compiler v" + version);
                Console.WriteLine("Copyright (C) Einar Egilsson 2009. All rights reserved.");
                Console.WriteLine();

                CommandLineOptions options = new CommandLineOptions(args);
                if (options.Empty)
                {
                    System.Console.Error.WriteLine("ERROR: No inputs specified");
                    return(1);
                }
                else if (options.Help)
                {
                    System.Console.Error.WriteLine("Usage: wc.exe [options] filename");
                    CommandLineOptions.Print();
                    return(2);
                }
                else if (!options.ReadStdIn && !File.Exists(options.InputFilename))
                {
                    System.Console.Error.WriteLine("ERROR: File '{0}' does not exist", options.InputFilename);
                    return(3);
                }

                Parser parser;
                if (options.ReadStdIn)
                {
                    //Passing the StdIn stream directly to the scanner doesn't work well
                    //so we do it this way instead
                    string       source = Console.In.ReadToEnd();
                    StreamWriter writer = new StreamWriter(new MemoryStream());
                    writer.Write(source);
                    writer.Flush();
                    writer.BaseStream.Seek(0, SeekOrigin.Begin);
                    parser = new Parser(new Scanner(writer.BaseStream), options);
                }
                else
                {
                    parser = new Parser(new Scanner(new FileStream(options.InputFilename, FileMode.Open)), options);
                }
                parser.Parse();
                if (parser.errors.count > 0)
                {
                    return(1);
                }
                WhileProgram.SymbolTable.Clear();
                PluginLoader pluginLoader = new PluginLoader();
                pluginLoader.Load(options.Plugins);

                foreach (ICompilerPlugin plugin in pluginLoader.LoadedPlugins)
                {
                    Console.WriteLine("Executing the '{0}' plugin...", plugin.Name);
                    plugin.ProcessSyntaxTree(WhileProgram.Instance);
                }

                WhileProgram.Instance.Compile(options.OutputFilename);
                Console.WriteLine();
                Console.WriteLine("Compiled program to '{0}'", options.OutputFilename);
                return(0);
            } catch (Exception ex) {
                Console.Error.WriteLine("ERROR: " + ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
                return(1);
            }
        }