예제 #1
0
        public static cSet <cConfiguration> cm_Goto(cSet <cConfiguration> a_listConfiguration, cLexem a_lexem)
        {
            cSet <cConfiguration> _validConfigurations = new cSet <cConfiguration>();

            foreach (cConfiguration _configuration in a_listConfiguration)
            {
                if (_configuration.cf_Production.cp_RightPart.Count > _configuration.cf_Position)
                {
                    if (_configuration.cf_Production.cp_RightPart[_configuration.cf_Position] == a_lexem)
                    {
                        cConfiguration _newConfiguration = cConfiguration.cm_GetConfiguration(_configuration.cf_Production, _configuration.cf_Position + 1, _configuration.cf_Terminal);
                        _validConfigurations.Add(_newConfiguration);
                    }
                }
            }
            return(cm_Closure(_validConfigurations));
        }
예제 #2
0
        public static cSet <cConfiguration> cm_Closure(cSet <cConfiguration> a_listConfiguration)
        {
            bool _added = false;

            if (a_listConfiguration != null)
            {
                cSet <cConfiguration> _retList    = a_listConfiguration.Clone() as cSet <cConfiguration>;
                cSet <cConfiguration> _addRetList = new cSet <cConfiguration>();
                do
                {
                    _addRetList.Clear();
                    foreach (cConfiguration _configuration in _retList)
                    {
                        if (_configuration.cf_Production.cp_RightPart.Count > _configuration.cf_Position)
                        {
                            cLexem _lexem = _configuration.cf_Production.cp_RightPart[_configuration.cf_Position];
                            if (_lexem.cp_Type == eLexType.NonTerminal)
                            {
                                List <cLexem> _listTerminals = new List <cLexem>();
                                _listTerminals.AddRange(_configuration.cf_Production.cp_RightPart.GetRange(_configuration.cf_Position + 1, _configuration.cf_Production.cp_RightPart.Count - _configuration.cf_Position - 1));
                                _listTerminals.Add(_configuration.cf_Terminal);
                                cSet <cLexem> _firstTerminals = cm_FirstTerminals(_listTerminals);
                                foreach (cProduction _production in _lexem.cp_ListProducts)
                                {
                                    foreach (cLexem _terminal in _firstTerminals)
                                    {
                                        cConfiguration _newConfiguration = cConfiguration.cm_GetConfiguration(_production, 0, _terminal);
                                        _addRetList.Add(_newConfiguration);
                                    }
                                }
                            }
                        }
                    }
                    _added = _retList.AddRange(_addRetList);
                } while (_added == true);
                return(_retList);
            }
            else
            {
                return(new cSet <cConfiguration>());
            }
        }
예제 #3
0
        private KeyValuePair <List <cSet <cConfiguration> >, Dictionary <cSet <cConfiguration>, Dictionary <cLexem, cSet <cConfiguration> > > > cm_Items(cLexem a_root)
        {
            List <cSet <cConfiguration> > _retList = new List <cSet <cConfiguration> >();

            cConfiguration        _rootConfiguration = cConfiguration.cm_GetConfiguration(a_root.cp_ListProducts[0], 0, cLexem.cc_StopLexem);
            cSet <cConfiguration> _rootClosure       = cConfiguration.cm_Closure(new cSet <cConfiguration>()
            {
                _rootConfiguration
            });

            Dictionary <cSet <cConfiguration>, Dictionary <cLexem, cSet <cConfiguration> > > _gotoResults = new Dictionary <cSet <cConfiguration>, Dictionary <cLexem, cSet <cConfiguration> > >();

            _retList.Add(_rootClosure);

            bool _added       = false;
            int  _lastChecked = 0;

            do
            {
                _added = false;
                for (; _lastChecked < _retList.Count; _lastChecked++)
                {
                    cSet <cConfiguration> _currentItem    = _retList[_lastChecked];
                    cSet <cLexem>         _currentChecked = cm_getAllPossibleGotoLexems(_currentItem);
                    foreach (cLexem _lexem in _currentChecked)
                    {
                        cSet <cConfiguration> _possibleItem = cConfiguration.cm_Goto(_currentItem, _lexem);
                        if (cm_addItemGroup(_retList, _currentItem, _lexem, _possibleItem, _gotoResults))
                        {
                            _added = true;
                        }
                    }
                }
            } while (_added);

            return(new KeyValuePair <List <cSet <cConfiguration> >, Dictionary <cSet <cConfiguration>, Dictionary <cLexem, cSet <cConfiguration> > > >(_retList, _gotoResults));
        }