public static int Main(string[] args) { DateTime ldt = DateTime.Now; PascalABCCompiler.StringResourcesLanguage.LoadDefaultConfig(); Compiler = new PascalABCCompiler.Compiler(null, null); StringResourcesLanguage.CurrentLanguageName = StringResourcesLanguage.AccessibleLanguages[0]; //Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds); ldt = DateTime.Now; //ShowConnectedParsers(); if (args.Length == 0) { Console.WriteLine(StringResourcesGet("COMMANDLINEISABSENT")); return 2; } FileName = args[0]; if (!File.Exists(FileName)) { Console.WriteLine(StringResourcesGet("FILEISABSENT{0}"),FileName); return 3; } outputType = CompilerOptions.OutputType.ConsoleApplicaton; CompilerOptions co = new CompilerOptions(FileName, outputType); if (args.Length==1) co.OutputDirectory = ""; else co.OutputDirectory = args[1]; co.Rebuild = false; co.Debug = true; co.UseDllForSystemUnits = false; bool success = true; if (Compiler.Compile(co) != null) Console.WriteLine("OK"); else { Console.WriteLine(StringResourcesGet("COMPILEERRORS")); success = false; } // Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds); ///// for (int i = 0; i < Compiler.ErrorsList.Count; i++) { if (Compiler.ErrorsList[i] is LocatedError) { SourceLocation sl; if ((sl = (Compiler.ErrorsList[i] as LocatedError).SourceLocation) != null) Console.WriteLine(string.Format("[{0},{1}] {2}: {3}", sl.BeginPosition.Line, sl.BeginPosition.Column, Path.GetFileName(sl.FileName), Compiler.ErrorsList[i].Message)); else Console.WriteLine(Compiler.ErrorsList[i]); } break; // выйти после первой же ошибки } if (success) return 0; else return 1; }
// PascalABCSaushkinParser reference needed!!! DO NOT REMOVE!!! static syntax_tree_node ParseFile(string fname) { Compiler c = new Compiler(); // c.SyntaxTreeChanger = new YieldDesugarSyntaxTreeConverter(); var opts = new CompilerOptions(fname, CompilerOptions.OutputType.ConsoleApplicaton); var res = c.Compile(opts); var err = new List<Error>(); var txt = System.IO.File.ReadAllText(fname); var cu = c.ParsersController.Compile(fname, txt, err, PascalABCCompiler.Parsers.ParseMode.Normal); if (cu == null) { Console.WriteLine("Не распарсилось"); } return cu; }
public static int CompileAssembly(string FileName, CompilerOptions.OutputType outputType, bool PauseIfError) { if (RestartOnNewCompile) Reset(); StartTime = DateTime.Now; Console.ForegroundColor = ConsoleColor.White; string msg = string.Format(StringResourcesGet("COMPILING_ASSEMBLY{0}"), System.IO.Path.GetFileName(FileName)); if (short_output) { ClearLine(); Console.Write(msg); } else Console.WriteLine(msg); DateTime ldt = DateTime.Now; CompilerOptions co = new CompilerOptions(FileName, outputType); if (OutputDirectory != "") co.OutputDirectory=OutputDirectory; co.Rebuild = Rebuild; co.Debug = Debug; co.UseDllForSystemUnits = UseDll; AllFilesCount++; if (Compiler.Compile(co) != null) SuccessFilesCount++; if (IgnoreNotSupportedError) if ((Compiler.ErrorsList.Count == 1) && (Compiler.ErrorsList[0] is Errors.SemanticNonSupportedError)) { Compiler.ErrorsList.Clear(); SuccessFilesCount++; } if (Compiler.ErrorsList.Count > 0) { //Console.Beep(); if (short_output) Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Gray; for (int i = 0; i < Compiler.ErrorsList.Count; i++) { WriteErrorText("[" + i + "]"); if (Compiler.ErrorsList[i] is LocatedError) { SourceLocation sl; if ((sl = (Compiler.ErrorsList[i] as LocatedError).SourceLocation) != null) Console.WriteLine(string.Format("[{0},{1}] {2}: {3}", sl.BeginPosition.Line, sl.BeginPosition.Column, Path.GetFileName(sl.FileName), Compiler.ErrorsList[i].Message)); else Console.WriteLine(Compiler.ErrorsList[i]); } else { if (Compiler.ErrorsList[i] is CompilerInternalError) Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(Compiler.ErrorsList[i]); } } GlobalErrorsList.AddRange(Compiler.ErrorsList); if (PauseIfError) Console.ReadKey(); } else { if (!short_output) { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(string.Format(StringResourcesGet("OK_{0}MS_{1}LINES"), (DateTime.Now - ldt).TotalMilliseconds, Compiler.LinesCompiled)); } } Console.ForegroundColor = ConsoleColor.Gray; return Compiler.ErrorsList.Count; }