//Parser states are distinguished by the subset of kernel LR0 items.
        // So when we derive new LR0-item list by shift operation,
        // we need to find out if we have already a state with the same LR0Item list.
        // We do it by looking up in a state hash by a key - [LR0 item list key].
        // Each list's key is a concatenation of items' IDs separated by ','.
        // Before producing the key for a list, the list must be sorted;
        //   thus we garantee one-to-one correspondence between LR0Item sets and keys.
        // And of course, we count only kernel items (with dot NOT in the first position).
        #endregion
        public static string ComputeLR0ItemSetKey(LR0ItemSet items)
        {
            if (items.Count == 0)
            {
                return("");
            }
            //Copy non-initial items to separate list, and then sort it
            LR0ItemList itemList = new LR0ItemList();

            foreach (var item in items)
            {
                itemList.Add(item);
            }
            //quick shortcut
            if (itemList.Count == 1)
            {
                return(itemList[0].ID.ToString());
            }
            itemList.Sort(CompareLR0Items); //Sort by ID
            //now build the key
            StringBuilder sb = new StringBuilder(255);

            foreach (LR0Item item in itemList)
            {
                sb.Append(item.ID);
                sb.Append(",");
            }//foreach
            return(sb.ToString());
        }
Пример #2
0
        private string CalcItemListKey(LR0ItemList items)
        {
            items.Sort((x, y) => x.ID - y.ID); //Sort by ID
            if (items.Count == 0)
            {
                return("");
            }

            if (items.Count == 1 && items[0].IsKernel)
            {
                return(items[0].ID.ToString());
            }

            StringBuilder sb = new StringBuilder(1024);

            foreach (LR0Item item in items)
            {
                if (item.IsKernel)
                {
                    sb.Append(item.ID);
                    sb.Append(",");
                }
            }
            return(sb.ToString());
        }
Пример #3
0
 //Parser states are distinguished by the subset of kernel LR0 items.
 // So when we derive new LR0-item list by shift operation,
 // we need to find out if we have already a state with the same LR0Item list.
 // We do it by looking up in a state hash by a key - [LR0 item list key].
 // Each list's key is a concatenation of items' IDs separated by ','.
 // Before producing the key for a list, the list must be sorted;
 //   thus we garantee one-to-one correspondence between LR0Item sets and keys.
 // And of course, we count only kernel items (with dot NOT in the first position).
 public static string ComputeLR0ItemSetKey(LR0ItemSet items)
 {
     if (items.Count == 0) return string.Empty;
       //Copy non-initial items to separate list, and then sort it
       LR0ItemList itemList = new LR0ItemList();
       itemList.AddRange(items);
       //quick shortcut
       if (itemList.Count == 1)
     return itemList[0].ID.ToString();
       itemList.Sort(CompareLR0Items); //Sort by ID
       //now build the key
       StringBuilder sb = new StringBuilder(100);
       foreach (LR0Item item in itemList) {
     sb.Append(item.ID);
     sb.Append(",");
       }//foreach
       return sb.ToString();
 }
        //Parser states are distinguished by the subset of kernel LR0 items.
        // So when we derive new LR0-item list by shift operation,
        // we need to find out if we have already a state with the same LR0Item list.
        // We do it by looking up in a state hash by a key - [LR0 item list key].
        // Each list's key is a concatenation of items' IDs separated by ','.
        // Before producing the key for a list, the list must be sorted;
        //   thus we garantee one-to-one correspondence between LR0Item sets and keys.
        // And of course, we count only kernel items (with dot NOT in the first position).
        #endregion
        private string CalcItemListKey(LR0ItemList items)
        {
            items.Sort(ById); //Sort by ID
            if (items.Count == 0)
            {
                return("");
            }
            //quick shortcut
            if (items.Count == 1 && items[0].IsKernel)
            {
                return(items[0].ID.ToString());
            }
            StringBuilder sb = new StringBuilder(1024);

            foreach (LR0Item item in items)
            {
                if (item.IsKernel)
                {
                    sb.Append(item.ID);
                    sb.Append(",");
                }
            }//foreach
            return(sb.ToString());
        }
Пример #5
0
    private string CalcItemListKey(LR0ItemList items)
    {
      items.Sort((x, y) => x.ID - y.ID); //Sort by ID
      if (items.Count == 0) return "";

      if (items.Count == 1 && items[0].IsKernel)
        return items[0].ID.ToString();

      StringBuilder sb = new StringBuilder(1024);
      foreach (LR0Item item in items)
      {
        if (item.IsKernel)
        {
          sb.Append(item.ID);
          sb.Append(",");
        }
      }
      return sb.ToString();
    }