Пример #1
0
        private void View_SourceCodeAnalyzeRequired(string source)
        {
            view.EnableRunButton();
            view.HideConsole();
            _lexicalAnalyzer = new LexicalAnalyzer();
            _syntaxAnalyzer  = new PDASyntaxAnalyzer(view.SetPDAOutput);
            _polizGenerator  = new PolizGenerator(_lexicalAnalyzer);

            var lexemes = _lexicalAnalyzer.Analyze(source);

            view.HighlightSourceCode(lexemes);

            view.DisplayConstants(_lexicalAnalyzer.Constants.Select(x => new { Code = x.ConstCode, Body = x.Body, Type = x.Type }));
            view.DisplayIdentificators(_lexicalAnalyzer.Identificators.Select(x => new { Code = x.ConstCode, Body = x.Body, Type = x.Type }));
            view.DisplayLexemes(lexemes.Select(x => new { Body = x.Body, Type = x.Flags, Line = x.Line, Code = x.Code, ConstCode = x.ConstCode }));

            if (_lexicalAnalyzer.HasErrors)
            {
                ShowErrors(_lexicalAnalyzer.Errors.Select(x => $"Lexical error: {x}"));
                view.DisableRunButton();
                _polizGenerator.Clear();
            }
            else
            {
                view.EnableRunButton();
                _syntaxAnalyzer.Analyze(lexemes);

                if (_syntaxAnalyzer.HasErrors)
                {
                    ShowErrors(_syntaxAnalyzer.Errors.Select(x => $"Syntax error: {x}"));
                    view.DisableRunButton();
                    _polizGenerator.Clear();
                }
                else
                {
                    _polizGenerator.MakePoliz();
                }
            }
            view.SetPoliz(_polizGenerator.Poliz);
        }