Пример #1
0
 public BuildProduction(BuildSymbol head, params BuildSymbol[] handles)
 {
     m_head    = head;
     m_handles = handles;
 }
Пример #2
0
 public LookaheadSymbol(LookaheadSymbol look)
 {
     m_parent = look.m_parent;
     m_configs.UnionWith(look.m_configs);
 }
Пример #3
0
 public LookaheadSymbol(BuildSymbol sym)
 {
     m_parent = sym;
 }
Пример #4
0
        private HashSet <LRConfig> GetClosureConfigSet(BuildSymbol symbol)
        {
            var set = new HashSet <LRConfig>();

            foreach (var production in m_grammar.BuildProductions)
            {
                if (production.Head == symbol)
                {
                    set.Add(new LRConfig
                    {
                        Position         = 0,
                        Modified         = true,
                        LookaheadSet     = new HashSet <LookaheadSymbol>(),
                        Parent           = production,
                        InheritLookahead = true
                    });
                }
            }

            bool anyAdded;

            do
            {
                var setB = new HashSet <LRConfig>();
                foreach (LRConfig config in set)
                {
                    if (!config.IsComplete() & config.Modified)
                    {
                        BuildSymbol build = config.NextSymbol(0);
                        if (build.Symbol.Type == ESymbolType.NonTerminal)
                        {
                            foreach (var production in m_grammar.BuildProductions)
                            {
                                if (production.Head == build)
                                {
                                    setB.Add(new LRConfig(production, 0, TotalLookahead(config)));
                                }
                            }
                        }

                        config.Modified = false;
                    }
                }

                anyAdded = setB.Aggregate(false, (current, i) => current | set.Add(i));
            }while (anyAdded);

            bool flag;

            do
            {
                flag = false;
                foreach (LRConfig config in set)
                {
                    BuildSymbol build = config.NextSymbol(0);
                    if ((build != null) && config.InheritLookahead && PopulateLookahead(config) && (build.Symbol.Type == ESymbolType.NonTerminal))
                    {
                        foreach (LRConfig config2 in set)
                        {
                            if ((config2.Position == 0) && (config2.Parent.Head == build) && !config2.InheritLookahead)
                            {
                                config2.InheritLookahead = true;
                                flag = true;
                            }
                        }
                    }
                }
            }while (flag);

            return(set);
        }