コード例 #1
0
        /// <summary>
        /// This event is invoked when the user clicks the Compile button.
        /// The function prepares to compile by resetting all necessary values back
        /// to default and then begins compilation.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CompileButton_Click(object sender, RoutedEventArgs e)
        {
            Utilities.linesOfCodeCount = 0;
            Utilities.linesOfCode      = new List <CodeLine>();
            ErrorPrinter.errorCount    = 0;
            ErrorPrinter.errorList     = new Dictionary <int, List <string> >();
            FunctionDirectory.Reset();
            MemoryManager.Reset();
            QuadrupleManager.Reset();
            UserControl main = new UserControl();

            ///*
            Utilities.BlockToLineErrors.Clear();
            BlocksWithErrorsInOrder.Clear();
            Utilities.errorsInLines.Clear();

            AssetListViewContainer.PrintCode();
            VariableListViewContainer.PrintCode();
            FunctionListViewContainer.PrintCode();

            Utilities.linesOfCode.Add(new CodeLine("instructions {", main, Utilities.linesOfCodeCount + 1));
            Utilities.linesOfCodeCount++;

            InstructionListViewContainer.PrintCode();

            Utilities.linesOfCode.Add(new CodeLine("}", main, Utilities.linesOfCodeCount + 1));
            Utilities.linesOfCodeCount++;

            WriteCodeToFile(out string filePath);
            //*/

            /*
             * string directoryPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "MarblesOutput");
             * Directory.CreateDirectory(directoryPath);
             * string filePath = Path.Combine(directoryPath, "testMarblesCode2.txt");
             */

            AnalyzeCode(filePath);

            MemoryManager.PrintMemory();
            QuadrupleManager.PrintQuadruples();

            Debug.WriteLine(ErrorPrinter.errorCount + " error(s) found.");
            ErrorPrinter.PrintErrors();

            if (ErrorPrinter.errorCount == 0)
            {
                Utilities.GreenCompile();
                Utilities.EnableRunButton();
                CompileButton.Background = Utilities.CompileButtonColor;
                CompileButton.IsEnabled  = Utilities.CompileButtonEnabled;
            }
            else
            {
                Utilities.RedCompile();
                Utilities.DisableRunButton();

                FillErrorsDictionary();
                SetErrorsInUI();

                CompileButton.Background = Utilities.CompileButtonColor;
                CompileButton.IsEnabled  = Utilities.CompileButtonEnabled;
            }
        }