Пример #1
0
        //private void cm_showGram(cParserException _ex)
        //{
        //    f_rtbGram.Document.Blocks.Clear();
        //    foreach (cToken _token in _ex.cf_Tokens)
        //    {
        //        switch (_token.cf_Type)
        //        {
        //            case eTokenType.перевод_строки:
        //                f_rtbGram.AppendText(Environment.NewLine);
        //                break;
        //            case eTokenType.стрелка:
        //                f_rtbGram.AppendText(" -> ");
        //                break;
        //            case eTokenType.Null:
        //                f_rtbGram.AppendText(" -> ");
        //                break;
        //            default:
        //                cm_addLexemToRichText(_token.cf_Value as cLexem, f_rtbGram);
        //                break;
        //        }
        //    }
        //}

        private void cm_addLexemToRichText(cLexem a_lexem, RichTextBox a_rtb)
        {
            if (a_lexem.cp_Type == eLexType.NonTerminal)
            {
                a_rtb.AppendText("<");
            }
            else if (a_lexem.cp_Type == eLexType.Action)
            {
                a_rtb.AppendText("{");
            }
            //a_rtb.SelectionFont = new Font(a_rtb.SelectionFont, FontStyle.Bold);
            //a_rtb.AppendText(a_lexem.ToString());
            TextRange _tr = new TextRange(a_rtb.Document.ContentEnd, a_rtb.Document.ContentEnd);

            _tr.Text = a_lexem.ToString();
            _tr.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
            _tr = new TextRange(a_rtb.Document.ContentEnd, a_rtb.Document.ContentEnd);
            _tr.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Regular);
            //a_rtb.SelectionFont = new Font(a_rtb.SelectionFont, FontStyle.Regular);
            if (a_lexem.cp_Type == eLexType.NonTerminal)
            {
                a_rtb.AppendText(">");
            }
            else if (a_lexem.cp_Type == eLexType.Action)
            {
                a_rtb.AppendText("}");
            }
            a_rtb.AppendText(" ");
        }
Пример #2
0
 private void cm_addLexemToRichText(cLexem a_lexem, RichTextBox a_rtb)
 {
     if (a_lexem.cp_Type == eLexType.NonTerminal)
         a_rtb.AppendText("<");
     else if (a_lexem.cp_Type == eLexType.Action)
         a_rtb.AppendText("{");
     a_rtb.SelectionFont = new Font(a_rtb.SelectionFont, FontStyle.Bold);
     a_rtb.AppendText(a_lexem.ToString());
     a_rtb.SelectionFont = new Font(a_rtb.SelectionFont, FontStyle.Regular);
     if (a_lexem.cp_Type == eLexType.NonTerminal)
         a_rtb.AppendText(">");
     else if (a_lexem.cp_Type == eLexType.Action)
         a_rtb.AppendText("}");
     a_rtb.AppendText(" ");
 }
Пример #3
0
 private void cm_addLexemToRichText(cLexem a_lexem, RichTextBox a_rtb)
 {
     if (a_lexem.cp_Type == eLexType.NonTerminal)
     {
         a_rtb.AppendText("<");
     }
     else if (a_lexem.cp_Type == eLexType.Action)
     {
         a_rtb.AppendText("{");
     }
     a_rtb.SelectionFont = new Font(a_rtb.SelectionFont, FontStyle.Bold);
     a_rtb.AppendText(a_lexem.ToString());
     a_rtb.SelectionFont = new Font(a_rtb.SelectionFont, FontStyle.Regular);
     if (a_lexem.cp_Type == eLexType.NonTerminal)
     {
         a_rtb.AppendText(">");
     }
     else if (a_lexem.cp_Type == eLexType.Action)
     {
         a_rtb.AppendText("}");
     }
     a_rtb.AppendText(" ");
 }
Пример #4
0
 //private void cm_showGram(cParserException _ex)
 //{
 //    f_rtbGram.Document.Blocks.Clear();
 //    foreach (cToken _token in _ex.cf_Tokens)
 //    {
 //        switch (_token.cf_Type)
 //        {
 //            case eTokenType.перевод_строки:
 //                f_rtbGram.AppendText(Environment.NewLine);
 //                break;
 //            case eTokenType.стрелка:
 //                f_rtbGram.AppendText(" -> ");
 //                break;
 //            case eTokenType.Null:
 //                f_rtbGram.AppendText(" -> ");
 //                break;
 //            default:
 //                cm_addLexemToRichText(_token.cf_Value as cLexem, f_rtbGram);
 //                break;
 //        }
 //    }
 //}
 private void cm_addLexemToRichText(cLexem a_lexem, RichTextBox a_rtb)
 {
     if (a_lexem.cp_Type == eLexType.NonTerminal)
         a_rtb.AppendText("<");
     else if (a_lexem.cp_Type == eLexType.Action)
         a_rtb.AppendText("{");
     //a_rtb.SelectionFont = new Font(a_rtb.SelectionFont, FontStyle.Bold);
     //a_rtb.AppendText(a_lexem.ToString());
     TextRange _tr = new TextRange(a_rtb.Document.ContentEnd,a_rtb.Document.ContentEnd);
     _tr.Text = a_lexem.ToString();
     _tr.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
     _tr = new TextRange(a_rtb.Document.ContentEnd, a_rtb.Document.ContentEnd);
     _tr.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Regular);
     //a_rtb.SelectionFont = new Font(a_rtb.SelectionFont, FontStyle.Regular);
     if (a_lexem.cp_Type == eLexType.NonTerminal)
         a_rtb.AppendText(">");
     else if (a_lexem.cp_Type == eLexType.Action)
         a_rtb.AppendText("}");
     a_rtb.AppendText(" ");
 }
Пример #5
0
        void cm_checkProducts(cProductInfo[] a_data)
        {
            int _count = a_data.Length;
            Dictionary <cLexem, cLexem> _dic = new Dictionary <cLexem, cLexem>();

            for (int k = 0; k < _count; k++)
            {
                cProductInfo _info = a_data[k];
                KeyValuePair <cLexem, int>[] _arrLexems = _info.cp_ArrLexems;
                int  _lexCount = _arrLexems.Length;
                bool _clearDic = true;
                for (int j = 0; j < _lexCount; j++)
                {
                    if (_clearDic)
                    {
                        _dic.Clear();
                    }
                    _clearDic = true;
                    cLexem _lexem = _arrLexems[j].Key;

                    switch (_lexem.cp_Type)
                    {
                    case eLexType.Terminal:
                        if (_dic.ContainsKey(_lexem))
                        {
                            throw new cNotLL1Exception(cLexem.cc_EpsilonLexem, cLexem.cc_EpsilonLexem, "Невозможно однозначно определить продукцию для символа " + _lexem.ToString() + " правой части " + _info.cp_Root.Key.ToString() + " из-за " + cLexem.cc_Epsilon + "-порождающих нетерминалов.");
                        }
                        _dic.Add(_lexem, _lexem);
                        break;

                    case eLexType.NonTerminal:
                        foreach (cLexem _lex in _lexem.cp_LeadLexems)
                        {
                            if (_lex.cp_Type == eLexType.Terminal)
                            {
                                if (_dic.ContainsKey(_lex))
                                {
                                    throw new cNotLL1Exception(cLexem.cc_EpsilonLexem, cLexem.cc_EpsilonLexem, "Невозможно однозначно определить продукцию для символа " + _lex.ToString() + " правой части " + _info.cp_Root.Key.ToString() + " из-за " + cLexem.cc_Epsilon + "-порождающих нетерминалов.");
                                }
                                _dic.Add(_lex, _lex);
                            }
                            else if (_lex.cp_Type == eLexType.Epsilon)
                            {
                                _clearDic = false;
                            }
                        }
                        break;

                    case eLexType.Epsilon:
                        _clearDic = true;
                        break;
                    }
                }
            }
        }