Пример #1
0
        /// <summary>
        /// Adds to <see cref="Utilities.linesOfCode"/> the code generated by this block.
        /// Called by blocks that contain this UserControl.
        /// </summary>
        public void PrintCode()
        {
            CleanPossibleError();
            string funcType = ((ComboBoxItem)(functionType.SelectedItem)).Content.ToString();

            if (funcType == "boolean")
            {
                funcType = "bool";
            }

            Utilities.linesOfCode.Add(new CodeLine("function " + funcType + " " + functionID.Text + "(", this, Utilities.linesOfCodeCount + 1));
            Utilities.linesOfCodeCount++;
            bool firstParam = true;

            foreach (var item in Parameters.Items)
            {
                if (item.GetType() == typeof(ComboBox))
                {
                    if (firstParam)
                    {
                        firstParam = false;
                    }
                    else
                    {
                        ((CodeLine)Utilities.linesOfCode[Utilities.linesOfCodeCount - 1]).content += ", ";
                    }

                    string dataTypeSelected = ((ComboBoxItem)(((ComboBox)item).SelectedItem)).Content.ToString();

                    if (dataTypeSelected == "boolean")
                    {
                        dataTypeSelected = "bool";
                    }

                    ((CodeLine)Utilities.linesOfCode[Utilities.linesOfCodeCount - 1]).content += dataTypeSelected + " ";
                }
                else
                {
                    ((CodeLine)Utilities.linesOfCode[Utilities.linesOfCodeCount - 1]).content += ((TextBox)item).Text;
                }
            }

            ((CodeLine)Utilities.linesOfCode[Utilities.linesOfCodeCount - 1]).content += ") {";
            VariableListViewContainer.PrintCode();
            InstructionListViewContainer.PrintCode();
            Utilities.linesOfCode.Add(new CodeLine("}", this, Utilities.linesOfCodeCount + 1));
            Utilities.linesOfCodeCount++;
        }
Пример #2
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;
            }
        }