コード例 #1
0
        public LR0Closure(Serpen.Uni.Automat.ContextFree.CFGrammer grammar, LR0Closure lr0c, char gotoVar)
        {
            this.Grammar = grammar;

            foreach (var item in lr0c)
            {
                if (item.dottedSymbol == gotoVar)
                {
                    Add(item.Var, item.Prod, item.Position + 1);
                }
            }

            int finishedtill = 0;

            do
            {
                int rulesCount = Count;
                for (int i = finishedtill; i < rulesCount; i++)
                {
                    if (this[i].hasDottedVar(grammar))
                    {
                        foreach (var addr in grammar.Rules)
                        {
                            if (addr.Key == this[i].dottedSymbol)
                            {
                                Add(addr.Key, addr.Value, 0);
                            }
                        }
                    }
                }

                finishedtill = rulesCount;
            } while (finishedtill < Count);
        }
コード例 #2
0
        public LR0Closure(Serpen.Uni.Automat.ContextFree.CFGrammer grammar, char Var)
        {
            if (!grammar.Variables.Contains(Var) | !grammar.Rules.ContainsKey(Var))
            {
                throw new System.Exception();
            }

            this.Grammar = grammar;

            foreach (var r in grammar.Rules)
            {
                if (r.Key == Var)
                {
                    Add(r.Key, r.Value);
                }
            }

            int finishedtill = 0;

            do
            {
                int rulesCount = Count;
                for (int i = finishedtill; i < rulesCount; i++)
                {
                    if (this[i].hasDottedVar(grammar))
                    {
                        foreach (var addr in grammar.Rules)
                        {
                            if (addr.Key == this[i].dottedSymbol)
                            {
                                Add(addr.Key, addr.Value, 0);
                            }
                        }
                    }
                }

                finishedtill = rulesCount;
            } while (finishedtill < Count);
        }