private void compileTask_OnComplete(bool cancelled, Exception error)
 {
     setState(true);
     progress.Visibility = Visibility.Hidden;
     //
     if (!cancelled)
     {
         if (error != null)
         {
             status.Content = "Error!";
             MessageBox.Show("Failed to compile AI scripts! " + error.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
         }
         else
         {
             status.Content = "Compiled at " + DateTime.Now.ToShortTimeString();
             //
             CompilerParser r = compileTask.CompilerResult;
             if (r != null && !r.IsSuccess)
             {
                 CompilerOutputWindow window = new CompilerOutputWindow();
                 window.Owner  = this;
                 window.Result = r;
                 window.Show();
             }
             else
             {
                 scriptMgr.HasChanges = false;
             }
         }
     }
     else
     {
         status.Content = null;
     }
 }
 protected override void Process()
 {
     if (NpcMgr.HasChanges)
     {
         string npc_filename = Paths.GetNPCData();
         setStatus("Saving NPC Data...", false);
         BackupHelper.Create(npc_filename);
         NpcMgr.Save(npc_filename, npc_Progress);
     }
     //
     if (ItemMgr.HasChanges)
     {
         string item_filename = Paths.GetItemData();
         setStatus("Saving Item Data...", false);
         BackupHelper.Create(item_filename);
         ItemMgr.Save(item_filename, item_Progress);
     }
     //
     if (ScriptMgr.HasChanges)
     {
         string ai_filename = Paths.GetAIData();
         setStatus("Compiling AI Scripts...", true);
         BackupHelper.Create(ai_filename);
         is_compiled    = false;
         CompilerResult = ScriptMgr.Compile(ai_Progress);
     }
 }
示例#3
0
 static void Main()
 {
     try
     {
         // В качестве входного потока символов устанавливаем консольный ввод или содержимое файла
         // AntlrInputStream input = new AntlrInputStream(Console.In);
         AntlrFileStream input = new AntlrFileStream("Source.txt");
         // Настраиваем лексер на этот поток
         CompilerLexer lexer = new CompilerLexer(input);
         // Создаем поток токенов на основе лексера
         tokens = new CommonTokenStream(lexer);
         // Создаем парсер
         CompilerParser parser = new CompilerParser(tokens);
         IParseTree     tree   = parser.compiler();
         // Запускаем первое правило грамматики
         MyVisitor visitor = new MyVisitor();
         // Запускаем обход дерева
         visitor.Visit(tree);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
     Console.ReadKey();
 }
        //=========================

        public void Run(ProgressEvent on_progress)
        {
            ScriptCompiler compiler = new ScriptCompiler();

            compiler.ScriptMgr = ScriptMgr;
            compiler.Run();
            //
            CompilerResult = compiler.Result;
            if (!compiler.Result.IsSuccess)
            {
                return;
            }
            //
            ScriptMgr.Items.SortByLevel();
            int total = ScriptMgr.Count;
            //
            string filename = Paths.GetAIData();

            using (FileStream stream = File.Open(filename, FileMode.Create, FileAccess.Write))
                using (StreamWriter writer = new StreamWriter(stream, Encoding.Unicode)) {
                    int c = ScriptMgr.Header.Count;
                    for (int i = 0; i < c; i++)
                    {
                        if (i > 0)
                        {
                            writer.WriteLine();
                        }
                        writer.Write(ScriptMgr.Header[i].ToString(' '));
                    }
                    //
                    writer.WriteLine();
                    writer.WriteLine();
                    writer.WriteLine();
                    //
                    int index = 0;
                    foreach (ScriptItem script in ScriptMgr.Items)
                    {
                        script.IsModified = false;
                        //
                        if (index > 0)
                        {
                            writer.WriteLine();
                            writer.WriteLine();
                        }
                        //
                        writer.Write(script.Source);
                        //
                        index++;
                        int p = (int)(index / (float)total * 100f);
                        if (OnProgress != null)
                        {
                            OnProgress.Invoke(p);
                        }
                    }
                }
        }
 protected override void Process()
 {
     if (ScriptMgr.HasChanges)
     {
         setStatus("Compiling AI Scripts...", true);
         BackupHelper.Create(Paths.GetAIData());
         is_compiled    = false;
         CompilerResult = ScriptMgr.Compile(ai_Progress);
     }
 }
示例#6
0
 public static String compile()
 {
     var fileName = "C:\\temp\\code.txt";
     StreamReader inputStream = new StreamReader(fileName);
     AntlrInputStream input = new AntlrInputStream(inputStream.ReadToEnd());
     CompilerLexer lexer = new CompilerLexer(input);
     CommonTokenStream tokens = new CommonTokenStream(lexer);
     CompilerParser parser = new CompilerParser(tokens);
     IParseTree tree = parser.program();
     Console.WriteLine(tree.ToStringTree(parser));
     var visitor = new MyVisitor();
     return createJasminFile(visitor.Visit(tree));
 }