Exemplo n.º 1
0
        public void Identifiers()
        {
            var inp   = new StringAsFileBuffer("exe > x program >= 1488;x54");
            var lexer = new LexAn();

            lexer.Scan(inp);
            CollectionAssert.AreEqual(lexer.Output, new List <int> {
                500, 13, 501, 300, 11, 400, 3, 502
            });
        }
Exemplo n.º 2
0
        public void DelimiterHell()
        {
            var inp   = new StringAsFileBuffer("<= +- > <>> <=>");
            var lexer = new LexAn();

            lexer.Scan(inp);
            CollectionAssert.AreEqual(lexer.Output, new List <int> {
                12, 4, 5, 13, 15, 13, 12, 13
            });
        }
Exemplo n.º 3
0
        private async void CompileButton_Click(object sender, RoutedEventArgs e)
        {
            var str = EditField.Text;
            var inp = new StringAsFileBuffer(str);

            _lexer = new LexAn();

            try {
                _lexer.Scan(inp);
            }
            catch (FormatException ex)
            {
                MessageBox.Show(ex.Message, "Lexical error");
                Log = "Error: " + ex.Message;
                return;
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, "Compilation error");
                Log = "Error: " + ex.Message;
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Inner compiler error");
                Log = "Please contact the developer " + ex.ToString();
                return;
            }

            var result = "";

            foreach (var s in _lexer.Output)
            {
                result += s + " ";
            }

            Log = "Lexical output: " + result;

            Binding b = new Binding();

            b.Source = Identifiers;
            b.Mode   = BindingMode.OneWay;
            BindingOperations.ClearBinding(IdentifiersTable, DataGrid.ItemsSourceProperty);
            IdentifiersTable.SetBinding(DataGrid.ItemsSourceProperty, b);

            Binding bs = new Binding();

            bs.Source = Constants;
            bs.Mode   = BindingMode.OneWay;
            BindingOperations.ClearBinding(ConstTable, DataGrid.ItemsSourceProperty);
            ConstTable.SetBinding(DataGrid.ItemsSourceProperty, bs);

            var syntax  = new SyntaxAnalyser(_lexer);
            var loading = new Loading();

            loading.Show();
            loading.progress.Maximum = _lexer.Output.Count - 1;
            syntax.LexIndexChanged  += (i) => ProgressUpdate(loading, i);
            await Task.Run(() => syntax.BuildAST());

            loading.Close();
            Log = syntax.IsValid ? "Valid" : "Invalid";
            if (!syntax.IsValid)
            {
                Log = syntax.ErrorMessage;
            }
            else
            {
                var root = treeView.Items[0];
                DrawTree((TreeViewItem)root, syntax.Tree.Root);

                tabs.SelectedIndex = 1;
            }
        }