private void f_btnLoadGram_Click(object sender, EventArgs e)
        {
            if (File.Exists(f_txtFileGram.Text))
            {
                try
                {
                    cScanner _scanner = null;
                    if (f_txtFileGram.Text.EndsWith(".xml"))
                    {
                        _scanner = new cXMLScanner(f_txtFileGram.Text);
                    }
                    else if (f_txtFileGram.Text.EndsWith(".txt"))
                    {
                        _scanner = new cTextScanner(f_txtFileGram.Text);
                    }

                    if (_scanner != null)
                    {
                        f_gbStep3.Enabled      = false;
                        f_btnViewTable.Enabled = false;
                        f_gbStep4.Enabled      = false;
                        f_rtbGram.Clear();

                        cf_parser = new cParser(_scanner, Application.StartupPath + @"\metagram.xml");
                        cf_parser.cm_Parse();
                        cf_generator.cm_Init(cf_parser);
                        _scanner.Dispose();

                        // Вывод текста грамматики
                        cm_showGram(null as cNotLL1Exception);
                        f_gbStep3.Enabled      = true;
                        f_btnViewTable.Enabled = false;
                        f_gbStep4.Enabled      = false;
                        cm_showStatus("Загрузка грамматики завершена.", false);
                    }
                    else
                    {
                        cm_showStatus("Неподдерживаемый формат файла.", true);
                    }
                }
                catch (cNotLL1Exception _ex)
                {
                    cm_showGram(_ex);
                    cm_showStatus(_ex.Message, true);
                }
                catch (cParserException _ex)
                {
                    cm_showGram(_ex);
                    cm_showStatus(_ex.Message, true);
                }
                catch (Exception _ex)
                {
                    cm_showStatus(_ex.Message, true);
                }
            }
            else
            {
                cm_showStatus("Выбранного файла не существует.", true);
            }
        }
Beispiel #2
0
        public void cm_Init(cParser a_parser)
        {
            cf_valid = false;
            cf_root  = cLexem.cm_ExtendGrammatic(a_parser.cp_Root);

            // Заполнение множества FOLLOW
            cf_follow = cm_Follow();

            //cLexem _lexem = cLexem.cm_GetLexem("Es");
            //cLexem _lexem2 = cLexem.cm_GetLexem("E");
            //cLexem _lexem3 = cLexem.cm_GetLexem("+");
            //cSet<cConfiguration> _test = cConfiguration.cm_Goto(new cSet<cConfiguration>() { cConfiguration.cm_GetConfiguration(_lexem.cp_ListProducts[0], 1), cConfiguration.cm_GetConfiguration(_lexem2.cp_ListProducts[0], 1) }, _lexem3);
            //int i;
            //i = 1;
            KeyValuePair <List <cSet <cConfiguration> >, Dictionary <cSet <cConfiguration>, Dictionary <cLexem, cSet <cConfiguration> > > > _pair = cm_Items(cf_root);

            cf_listItems   = _pair.Key;
            cf_gotoResults = _pair.Value;

            cf_valid = true;
        }
        public void cm_Init(cParser a_parser)
        {
            cf_valid = false;
            cf_root = a_parser.cp_Root;

            // Заполнение множества FOLLOW
            cf_follow = new Dictionary<cLexem,cSet<cLexem>>();
            foreach (cLexem _nonTerminal in cp_Lexems)
            {
                if (_nonTerminal.cp_Type == eLexType.NonTerminal)
                {
                    cf_follow[_nonTerminal] = new cSet<cLexem>();
                }
            }

            // 2
            cSet<cLexem> _first = new cSet<cLexem>();
            foreach (cLexem _nonTerminal in cp_Lexems)
            {
                if (_nonTerminal.cp_Type == eLexType.NonTerminal)
                {
                    foreach (List<cLexem> _lstLex in _nonTerminal.cp_ListProducts.Values)
                    {
                        int _count = _lstLex.Count;
                        _first.Clear();
                        for (int i = _lstLex.Count - 1; i >= 0; i--)
                        {
                            cLexem _lex = _lstLex[i];
                            switch (_lex.cp_Type)
                            {
                                case eLexType.NonTerminal:
                                    cf_follow[_lex].AddRange(_first);
                                    if (!_lex.cm_IsLeadingLexem(cLexem.cc_EpsilonLexem))
                                    {
                                        _first.Clear();
                                    }
                                    _first.AddRange(_lex.cp_LeadLexems);
                                    break;
                                case eLexType.Terminal:
                                    _first.Clear();
                                    _first.Add(_lex);
                                    break;
                                case eLexType.Epsilon:
                                    _first.Clear();
                                    break;
                            }
                        }
                    }
                }
            }

            // 3
            bool _added = true;
            while (_added)
            {
                _added = false;
                foreach (cLexem _nonTerminal in cp_Lexems)
                {
                    if (_nonTerminal.cp_Type == eLexType.NonTerminal)
                    {
                        foreach (List<cLexem> _lstLex in _nonTerminal.cp_ListProducts.Values)
                        {
                            int _count = _lstLex.Count;
                            _first.Clear();
                            bool _break = false;
                            for (int i = _lstLex.Count - 1; i >= 0; i--)
                            {
                                cLexem _lex = _lstLex[i];
                                switch (_lex.cp_Type)
                                {
                                    case eLexType.NonTerminal:
                                        cf_follow[_lex].AddRange(_first);
                                        if (!_lex.cm_IsLeadingLexem(cLexem.cc_EpsilonLexem))
                                        {
                                            _break = true;
                                        }
                                        //else
                                            _added = cf_follow[_lex].AddRange(cf_follow[_nonTerminal]) | _added;
                                        break;
                                    case eLexType.Action:
                                        break;
                                    default:
                                        _break = true;
                                        break;
                                }
                                if (_break) break;
                            }
                        }
                    }
                }
            }
            cf_valid = true;
        }
Beispiel #4
0
        private void f_btnLoadGram_Click(object sender, EventArgs e)
        {
            if (File.Exists(f_txtFileGram.Text))
            {
                try
                {
                    cScanner _scanner = null;
                    if (f_txtFileGram.Text.EndsWith(".xml"))
                    {
                        _scanner = new cXMLScanner(f_txtFileGram.Text);
                    }
                    else if (f_txtFileGram.Text.EndsWith(".txt"))
                    {
                        _scanner = new cTextScanner(f_txtFileGram.Text);
                    }

                    if (_scanner != null)
                    {
                        f_gbStep3.Enabled = false;
                        f_btnViewTable.Enabled = false;
                        f_gbStep4.Enabled = false;
                        f_rtbGram.Clear();

                        cf_parser = new cParser(_scanner, Application.StartupPath + @"\metagram.xml");
                        cf_parser.cm_Parse();
                        cf_generator.cm_Init(cf_parser);
                        _scanner.Dispose();

                        // Вывод текста грамматики
                        cm_showGram(null as cNotLL1Exception);
                        f_gbStep3.Enabled = true;
                        f_btnViewTable.Enabled = false;
                        f_gbStep4.Enabled = false;
                        cm_showStatus("Загрузка грамматики завершена.", false);
                    }
                    else
                    {
                        cm_showStatus("Неподдерживаемый формат файла.", true);
                    }
                }
                catch (cNotLL1Exception _ex)
                {
                    cm_showGram(_ex);
                    cm_showStatus(_ex.Message, true);
                }
                catch (cParserException _ex)
                {
                    cm_showGram(_ex);
                    cm_showStatus(_ex.Message, true);
                }
                catch (Exception _ex)
                {
                    cm_showStatus(_ex.Message, true);
                }
            }
            else
            {
                cm_showStatus("Выбранного файла не существует.", true);
            }
        }
        private void f_btnLoadGramLR_Click(object sender, RoutedEventArgs e)
        {
            if (File.Exists(f_txtFileGram.Text))
            {
                #if DEBUG
                #else
                try
                #endif
                {
                    cScanner _scanner = null;
                    if (f_txtFileGram.Text.EndsWith(".xml"))
                    {
                        _scanner = new cXMLScanner(f_txtFileGram.Text);
                    }
                    else if (f_txtFileGram.Text.EndsWith(".txt"))
                    {
                        _scanner = new cTextScanner(f_txtFileGram.Text);
                    }

                    if (_scanner != null)
                    {
                        f_gbStep3.IsEnabled = false;
                        f_btnViewTable.IsEnabled = false;
                        f_gbStep4.IsEnabled = false;
                        f_rtbGram.Document.Blocks.Clear();

                        cf_parser = new cLRParser(_scanner, System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\metagram.LR.xml");
                        cf_parser.cm_Parse();
                        cf_generator.cm_Init(cf_parser);
                        _scanner.Dispose();

                        // Вывод текста грамматики
                        cm_showGram(null as cNotLL1Exception);
                        f_gbStep3.IsEnabled = true;
                        f_btnViewTable.IsEnabled = false;
                        f_gbStep4.IsEnabled = false;
                        cm_showStatus("Загрузка грамматики завершена.", false);
                    }
                    else
                    {
                        cm_showStatus("Неподдерживаемый формат файла.", true);
                    }
                }
            #if DEBUG
            #else
                catch (cNotLL1Exception _ex)
                {
                    cm_showGram(_ex);
                    cm_showStatus(_ex.Message, true);
                }
                catch (cParserException _ex)
                {
                    cm_showGram(_ex);
                    cm_showStatus(_ex.Message, true);
                }
                catch (Exception _ex)
                {
                    cm_showStatus(_ex.Message, true);
                }
            #endif
            }
            else
            {
                cm_showStatus("Выбранного файла не существует.", true);
            }
        }
Beispiel #6
0
        public void cm_Init(cParser a_parser)
        {
            cf_valid = false;
            cf_root  = a_parser.cp_Root;

            // Заполнение множества FOLLOW
            cf_follow = new Dictionary <cLexem, cSet <cLexem> >();
            foreach (cLexem _nonTerminal in cp_Lexems)
            {
                if (_nonTerminal.cp_Type == eLexType.NonTerminal)
                {
                    cf_follow[_nonTerminal] = new cSet <cLexem>();
                }
            }

            // 2
            cSet <cLexem> _first = new cSet <cLexem>();

            foreach (cLexem _nonTerminal in cp_Lexems)
            {
                if (_nonTerminal.cp_Type == eLexType.NonTerminal)
                {
                    foreach (List <cLexem> _lstLex in _nonTerminal.cp_ListProducts.Values)
                    {
                        int _count = _lstLex.Count;
                        _first.Clear();
                        for (int i = _lstLex.Count - 1; i >= 0; i--)
                        {
                            cLexem _lex = _lstLex[i];
                            switch (_lex.cp_Type)
                            {
                            case eLexType.NonTerminal:
                                cf_follow[_lex].AddRange(_first);
                                if (!_lex.cm_IsLeadingLexem(cLexem.cc_EpsilonLexem))
                                {
                                    _first.Clear();
                                }
                                _first.AddRange(_lex.cp_LeadLexems);
                                break;

                            case eLexType.Terminal:
                                _first.Clear();
                                _first.Add(_lex);
                                break;

                            case eLexType.Epsilon:
                                _first.Clear();
                                break;
                            }
                        }
                    }
                }
            }

            // 3
            bool _added = true;

            while (_added)
            {
                _added = false;
                foreach (cLexem _nonTerminal in cp_Lexems)
                {
                    if (_nonTerminal.cp_Type == eLexType.NonTerminal)
                    {
                        foreach (List <cLexem> _lstLex in _nonTerminal.cp_ListProducts.Values)
                        {
                            int _count = _lstLex.Count;
                            _first.Clear();
                            bool _break = false;
                            for (int i = _lstLex.Count - 1; i >= 0; i--)
                            {
                                cLexem _lex = _lstLex[i];
                                switch (_lex.cp_Type)
                                {
                                case eLexType.NonTerminal:
                                    cf_follow[_lex].AddRange(_first);
                                    if (!_lex.cm_IsLeadingLexem(cLexem.cc_EpsilonLexem))
                                    {
                                        _break = true;
                                    }
                                    //else
                                    _added = cf_follow[_lex].AddRange(cf_follow[_nonTerminal]) | _added;
                                    break;

                                case eLexType.Action:
                                    break;

                                default:
                                    _break = true;
                                    break;
                                }
                                if (_break)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            cf_valid = true;
        }
        private void f_btnLoadGramLL_Click(object sender, RoutedEventArgs e)
        {
            if (File.Exists(f_txtFileGram.Text))
            {
#if DEBUG
#else
                try
#endif
                {
                    cScanner _scanner = null;
                    if (f_txtFileGram.Text.EndsWith(".xml"))
                    {
                        _scanner = new cXMLScanner(f_txtFileGram.Text);
                    }
                    else if (f_txtFileGram.Text.EndsWith(".txt"))
                    {
                        _scanner = new cTextScanner(f_txtFileGram.Text);
                    }

                    if (_scanner != null)
                    {
                        f_gbStep3.IsEnabled      = false;
                        f_btnViewTable.IsEnabled = false;
                        f_gbStep4.IsEnabled      = false;
                        f_rtbGram.Document.Blocks.Clear();

                        cf_parser = new cLLParser(_scanner, System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\metagram.LL.xml");
                        cf_parser.cm_Parse();
                        cf_generator.cm_Init(cf_parser);
                        _scanner.Dispose();

                        // Вывод текста грамматики
                        cm_showGram(null as cNotLL1Exception);
                        f_gbStep3.IsEnabled      = true;
                        f_btnViewTable.IsEnabled = false;
                        f_gbStep4.IsEnabled      = false;
                        cm_showStatus("Загрузка грамматики завершена.", false);
                    }
                    else
                    {
                        cm_showStatus("Неподдерживаемый формат файла.", true);
                    }
                }
#if DEBUG
#else
                catch (cNotLL1Exception _ex)
                {
                    cm_showGram(_ex);
                    cm_showStatus(_ex.Message, true);
                }
                catch (cParserException _ex)
                {
                    cm_showGram(_ex);
                    cm_showStatus(_ex.Message, true);
                }
                catch (Exception _ex)
                {
                    cm_showStatus(_ex.Message, true);
                }
#endif
            }
            else
            {
                cm_showStatus("Выбранного файла не существует.", true);
            }
        }
        public void cm_Init(cParser a_parser)
        {
            cf_valid = false;
            cf_root = cLexem.cm_ExtendGrammatic(a_parser.cp_Root);

            // Заполнение множества FOLLOW
            cf_follow = cm_Follow();

            //cLexem _lexem = cLexem.cm_GetLexem("Es");
            //cLexem _lexem2 = cLexem.cm_GetLexem("E");
            //cLexem _lexem3 = cLexem.cm_GetLexem("+");
            //cSet<cConfiguration> _test = cConfiguration.cm_Goto(new cSet<cConfiguration>() { cConfiguration.cm_GetConfiguration(_lexem.cp_ListProducts[0], 1), cConfiguration.cm_GetConfiguration(_lexem2.cp_ListProducts[0], 1) }, _lexem3);
            //int i;
            //i = 1;
            KeyValuePair<List<cSet<cConfiguration>>, Dictionary<cSet<cConfiguration>, Dictionary<cLexem, cSet<cConfiguration>>>> _pair = cm_Items(cf_root);
            cf_listItems = _pair.Key;
            cf_gotoResults = _pair.Value;

            cf_valid = true;
        }