Пример #1
0
        static void Main(string[] args)
        {
            try {
                Options options = new Options();
                if (Parser.Default.ParseArguments(args, options))
                {
                    if (options.FileName.Count < 1)
                    {
                        Console.WriteLine("No file is selected");
                        return;
                    }

                    string arg = options.FileName[0], path = "", content;
                    try {
                        path = Path.GetFullPath(arg);
                        FileInfo fileInfo = new FileInfo(path);
                        if (!fileInfo.Exists)
                        {
                            return;
                        }
                        using (StreamReader sr = fileInfo.OpenText())
                            content = sr.ReadToEnd();
                    } catch (ArgumentException) {
                        content = arg;
                    }

                    Runner runner = new Runner(content, options.MemorySize, options.MaxStackDepth);

                    if (!string.IsNullOrEmpty(options.OutputFileName))
                    {
                        if (string.IsNullOrEmpty(options.OutputAssemblyName))
                        {
                            options.OutputAssemblyName = Path.GetFileNameWithoutExtension(options.OutputFileName);
                        }
                        Console.WriteLine("Creating assembly {0} to {1}...", options.OutputAssemblyName, options.OutputFileName);
                        BF2Assembly.CompileToFile(runner, options.OutputAssemblyName, options.OutputFileName);
                        return;
                    }

                    if (!options.Interpret)
                    {
                        runner.Compile();
                    }

                    Console.InputEncoding  = Encoding.ASCII;
                    Console.OutputEncoding = Encoding.ASCII;
                    runner.Run(Console.In, Console.Out);

                    Console.ReadKey(true);
                }
            } catch (Exception ex) {
                Console.OutputEncoding = Encoding.Default;
                Console.Write("Error: ");
                while (ex != null)
                {
                    Console.WriteLine("{0}\n{1}", ex.Message, ex.StackTrace);
                    if (ex == ex.InnerException)
                    {
                        break;
                    }
                    ex = ex.InnerException;
                    if (ex != null)
                    {
                        Console.Write("Inner Exception: ");
                    }
                }
            }
        }