当前位置: 首页>>代码示例>>C#>>正文


C# Grammar.Follow方法代码示例

本文整理汇总了C#中Grammar.Follow方法的典型用法代码示例。如果您正苦于以下问题:C# Grammar.Follow方法的具体用法?C# Grammar.Follow怎么用?C# Grammar.Follow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Grammar的用法示例。


在下文中一共展示了Grammar.Follow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Extract

        public override void Extract(Grammar grammar)
        {
            _Grammar = grammar;
            EntityCol = grammar.Entities;
            TerminalCol = grammar.Terminals;
            NonTerminalCol = grammar.NonTerminals;

            // removing augmented entity
            var augment = EntityCol[0];
            _EntityColO = EntityCol - augment;
            NonTerminalCol.Remove((NonTerminal) augment);

            //Cloure_GoToTable
            _Production = new CLRProduction(grammar[0].Producer, grammar[0].Product,
                                       new EntityCollection<Terminal>(new[] { (Terminal) "$" }));

            _GotoCount = 0;
            _DotCount = 0;

            _ClosureCol =
                new ClosureCollection(new Closure[] { new CLRClosure(GotoTitle(), grammar, new SLRProduction[] { _Production }) });

            ++_GotoCount;
            _GotoEntries = new GotoEntry[0];
            for (var c = 0; c < _ClosureCol.Count; ++c)
            {
                var closure = (SLRClosure) _ClosureCol[c];
                var tmp = _EntityColO - (Terminal) "$";
                for (var e = 0; e < tmp.Count; ++e) //foreach (var entity in _entityColO - (Terminal) "$")
                {
                    var entity = tmp[e];
                    var gotoClosure = closure.GoToEntity(entity);
                    if (!gotoClosure.IsEmpty)
                    {
                        var index =
                            //_closureCol.List.FindIndex((Closure clr) => (clr == gotoClosure));
                            _ClosureCol.Closures.IndexOf(gotoClosure);
                        if (-1 == index)
                        {
                            // add new Goto State
                            gotoClosure.Title = GotoTitle();
                            _ClosureCol += gotoClosure;
                            ++_GotoCount;
                        }
                        else
                        {
                            // error here
                            //CLRClosure closureC = gotoClosure as CLRClosure;
                            //closureC.AddLookAhead(_ClosureCol[ index ].SLRProductions.ToArray());
                            //gotoClosure = closureC;

                            var closureC = gotoClosure as CLRClosure;
                            if (default(Closure) != closureC) closureC.AddLookAhead(_ClosureCol[index].SLRProductions.ToArray());
                            gotoClosure.Title = _ClosureCol[index].Title;
                        }

                        var length = _GotoEntries.Length;
                        var newGotoEntries = new GotoEntry[length + 1];
                        Array.Copy(_GotoEntries, newGotoEntries, length);

                        newGotoEntries[length] = new GotoEntry(closure, entity, gotoClosure);
                        _GotoEntries = newGotoEntries;
                    }
                    ++_DotCount;
                }
            }

            // LR Table
            _GoTotable = new String[EntityCol.Count, _ClosureCol.Count];

            for (var c = 0; c < _ClosureCol.Count; ++c)
            {
                var terminalLength = TerminalCol.Count;

                //Shift
                for (var t = 0; t < terminalLength; ++t)
                    foreach (var gotoEntity in _GotoEntries)
                    {
                        if (gotoEntity.X != TerminalCol[t] || gotoEntity.I != _ClosureCol[c]) continue;

                        _GoTotable[t, c] = "s" + gotoEntity.Goto.Title.Split('[', ']')[1];
                        break;
                    }

                //Reduce
                for (var p = 0; p < _ClosureCol[c].Count; ++p)
                {
                    var production = _ClosureCol[c][p];
                    if (production.DotPosition == (production.Count - 1)
                        && production == _ClosureCol[1][0] // S' --> S .$
                        ) // Accepted
                        _GoTotable[TerminalCol & (Terminal) "$", 1] = "!!";

                    if (production.DotPosition != production.Count) continue;
                    var followCol = grammar.Follow(production.Producer);
                    if (default(EntityCollection<Terminal>) == followCol) continue;
                    //followCol.Remove( (Terminal)"$" );
                    foreach (var follow in followCol) _GoTotable[TerminalCol & follow, c] = "r" + (grammar & production);
                }

//.........这里部分代码省略.........
开发者ID:erashid,项目名称:ParsingTables,代码行数:101,代码来源:Parser.cs


注:本文中的Grammar.Follow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。