Example #1
0
File: SLR.cs Project: gu0o00/gSQL
        public List <string> GetFollow(string x)
        {
            if (zhongjiefu.Contains(x) == true)                 //如果x是终结符
            {
                return(follow);
            }
            GrammarList allGarmmar = garmmarList.GetYoubuHad(x);

            foreach (TuidaoShi i in allGarmmar)
            {
                int index = GetIndexFromArry(i.ElementAt(0).Value, x);
                if (index >= i.ElementAt(0).Value.Length - 1 &&
                    i.ElementAt(0).Key.Equals(i.ElementAt(0).Value[i.ElementAt(0).Value.Length - 1]) == false &&
                    jilu.Contains(i.ElementAt(0).Key) == false)                          //x的后面没有东西了
                {
                    if (jilu.Contains(i.ElementAt(0).Key))
                    {
                        continue;
                    }
                    jilu.Add(i.ElementAt(0).Key);
                    List <string> res = GetFollow(i.ElementAt(0).Key);
                    foreach (string t in res)
                    {
                        if (follow.Contains(t) == false)
                        {
                            follow.Add(t);
                        }
                    }
                }
                else if (index < i.ElementAt(0).Value.Length - 1)                   //x的后面还有符号
                {
                    string        nextFuhao = i.ElementAt(0).Value[index + 1];
                    List <string> res       = new List <string>();
                    if (Nzhongjiefu.Contains(nextFuhao) == true)
                    {
                        firstList.TryGetValue(nextFuhao, out res);
                    }
                    else
                    {
                        res.Add(nextFuhao);
                    }
                    if (res != null)
                    {
                        foreach (string t in res)
                        {
                            if (follow.Contains(t) == false)
                            {
                                follow.Add(t);
                            }
                        }
                    }
                }
            }
            return(follow);
        }
Example #2
0
File: SLR.cs Project: gu0o00/gSQL
 public void GetZhongjiefu()
 {
     foreach (string fuhao in allFuhao)
     {
         foreach (Dictionary <string, string[]> i in garmmarList)
         {
             if (i.Keys.Contains(fuhao) == true && Nzhongjiefu.Contains(fuhao) == false)
             {
                 Nzhongjiefu.Add(fuhao);
             }
         }
     }
     foreach (string fuhao in allFuhao)
     {
         if (Nzhongjiefu.Contains(fuhao) == false && zhongjiefu.Contains(fuhao) == false)
         {
             zhongjiefu.Add(fuhao);
         }
     }
 }