Ejemplo n.º 1
0
 public LRItem FindByCore(LR0Item core)
 {
     foreach (LRItem item in this)
     {
         if (item.Core == core)
         {
             return(item);
         }
     }
     return(null);
 }
Ejemplo n.º 2
0
 private static int CompareLR0Items(LR0Item x, LR0Item y)
 {
     if (x.ID < y.ID)
     {
         return(-1);
     }
     if (x.ID == y.ID)
     {
         return(0);
     }
     return(1);
 }
Ejemplo n.º 3
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
Ejemplo n.º 4
0
 public LRItem(ParserState state, LR0Item core)
 {
     State     = state;
     Core      = core;
     _hashCode = unchecked (state.GetHashCode() + core.GetHashCode());
 }