Exemple #1
0
        private void PresentDescriptorsPresentation(DescriptorsPresentation dp)
        {
            PresentDescriptorsTable(dp.KeywordsList, KeywordsList);
            PresentDescriptorsTable(dp.OperatorsList, OperatorsList);
            PresentDescriptorsTable(dp.FunctionsList, FunctionsList);
            PresentDescriptorsTable(dp.IdentifiersList, IdentifiersList);
            PresentDescriptorsTable(dp.ConstantsList, ConstantsList);

            var sb = new StringBuilder();

            foreach (Token token in dp.Tokens)
            {
                if (token.HasType(TokenType.Delimiter))
                {
                    sb.Append(token.Value);
                }
                else if (!token.HasOneOfTypes(TokenType.Commentary, TokenType.Unknown, TokenType.EndOfText))
                {
                    StringList table = dp.GetTableFor(token);
                    string     desc  = string.Format("({0} {1})", table.Description, table.Find(token.Value.Escape()) + 1);

                    sb.Append(desc);
                }
            }

            DescriptorsRichTextBox.Document = new FlowDocument(new Paragraph(new Run(sb.ToString())));
        }
Exemple #2
0
        private void Update()
        {
            try
            {
                string text = "";

                Invoke(() => { text = SourceTextBox.Text; });

                List <Error> errors = new List <Error>();

                #region Lexical analysis
                IEnumerable <Error> lexicalErrors = null;
                IEnumerable <Token> tokens        = _translator.Scaner.GetTokens(text, out lexicalErrors);
                errors.AddRange(lexicalErrors);
                #endregion

                #region Syntax analysis
                if (_translator.Parser != null && errors.Count == 0)
                {
                    IEnumerable <Error> syntaxErrors = null;
                    _syntaxTree = _translator.Parser.Parse(tokens, out syntaxErrors);
                    errors.AddRange(syntaxErrors);
                }
                #endregion

                #region Semantic analysis
                if (_translator.SemanticChecker != null && errors.Count == 0)
                {
                    IEnumerable <Error> semanticErrors = _translator.SemanticChecker.GetSemanticErrors(_syntaxTree);
                    errors.AddRange(semanticErrors);
                }
                #endregion

                #region Codegeneration
                if (_translator.Generator != null && errors.Count == 0)
                {
                    _code = _translator.Generator.GenerateIntermediateCode(_syntaxTree);
                }
                #endregion

                var descriptorsPresentation = new DescriptorsPresentation(tokens);

                Invoke(() =>
                {
                    Errors.Clear();
                    errors.ForEach((e) => Errors.Add(e));

                    PresentColoredTokens(tokens, Errors);
                    PresentDescriptorsPresentation(descriptorsPresentation);
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
        }