Example #1
0
        private void AnalyzeButton_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                ViewModel.Reset();
                _variables.Clear();
                outputTextBox.Text = null;

                _lexer.ParseTokens(new StringReader(sourceTextBox.Text));
                ViewModel.AllTokens   = _lexer.Parsed;
                ViewModel.Identifiers = _lexer.Identifiers;
                ViewModel.Constants   = _lexer.Constants;
                ViewModel.Labels      = _lexer.Labels.Distinct();
                _lexer.Validate(ViewModel.AllTokens.ToList());

                var valid = !ViewModel.LogMessages.Any(x => x.Type >= LogEventLevel.Error);

                valid = valid && _parser.CheckSyntax(_lexer.Parsed);
                if (!valid)
                {
                    throw new Exception();
                }

                var labels  = ViewModel.Labels.ToList();
                var context = new Context(ViewModel.AllTokens.ToList(), _variables, labels);
                _executor.Execute(context, inputTextBox.Text);

                ViewModel.UpdateIdValues();

                MessageBox.Show("Program is valid");
            }
            catch (Exception)
            {
                MessageBox.Show("Program contains errors");
                //Ignore exceptions - all errors will be in log
            }
        }