Exemplo n.º 1
0
        public LRItemSet SelectByLookahead(Terminal lookahead)
        {
            var result = new LRItemSet();

            foreach (var item in this)
            {
                if (item.Lookaheads.Contains(lookahead))
                {
                    result.Add(item);
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public LRItemSet SelectByCurrent(BnfTerm current)
        {
            var result = new LRItemSet();

            foreach (var item in this)
            {
                if (item.Core.Current == current)
                {
                    result.Add(item);
                }
            }
            return(result);
        }
        public LRItemSet SelectItemsWithNullableTails()
        {
            var result = new LRItemSet();

            foreach (var item in this)
            {
                if (item.Core.TailIsNullable)
                {
                    result.Add(item);
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        public void AddItem(LR0Item core)
        {
            //Check if a core had been already added. If yes, simply return
            if (!AllCores.Add(core))
            {
                return;
            }
            //Create new item, add it to AllItems, InitialItems, ReduceItems or ShiftItems
            var item = new LRItem(State, core);

            AllItems.Add(item);
            if (item.Core.IsFinal)
            {
                ReduceItems.Add(item);
            }
            else
            {
                ShiftItems.Add(item);
            }
            if (item.Core.IsInitial)
            {
                InitialItems.Add(item);
            }
            if (core.IsFinal)
            {
                return;
            }
            //Add current term to ShiftTerms
            if (!ShiftTerms.Add(core.Current))
            {
                return;
            }
            if (core.Current is Terminal)
            {
                ShiftTerminals.Add(core.Current as Terminal);
            }
            //If current term (core.Current) is a new non-terminal, expand it
            var currNt = core.Current as NonTerminal;

            if (currNt == null)
            {
                return;
            }
            foreach (var prod in currNt.Productions)
            {
                AddItem(prod.LR0Items[0]);
            }
        }//method
Exemplo n.º 5
0
        private LRItemSet SelectNewItemsThatNeedLookback(TransitionList transitions)
        {
            //Select items with nullable tails that don't have lookbacks yet
            var items = new LRItemSet();

            foreach (var trans in transitions)
            {
                foreach (var item in trans.Items)
                {
                    if (item.Core.TailIsNullable && item.Lookbacks.Count == 0) //only if it does not have lookbacks yet
                    {
                        items.Add(item);
                    }
                }
            }
            return(items);
        }