//判断当前FOLLOW集是否包含当前FIRST集中的元素
public bool IsContain(List follow, List first)
{
foreach (string str in first)
{
if (!follow.Contains(str))
{
return false;
}
}
return true;
}
//构造归约项的FOLLOW集和移进项的FIRST集
public void ConstructFollowAndFirst()
{
back = new List<List>();
put = new List();
for (int i = 0; i < proitemset.Count; i++)
{
for (int j = 0; j < SLRproNum.Count; j++)
{
int index = -1;
for (int k = 0; k < proitemset[i].Container.Count; k++)
{
if (SLRobjNum[proitemset[i].Container[k]].Left == SLRproNum[j].Left && SLRobjNum[proitemset[i].Container[k]].Right == SLRproNum[j].Right)
{
index = k;
break;
}
}
if (index != -1 && SLRobjNum[proitemset[i].Container[index]].Right.IndexOf('.') == SLRobjNum[proitemset[i].Container[index]].Right.Length - 1)
{
if (SLRproNum[j].Left != "S'")
{
if (!Gy_obj.Contains(index))
{
List follow = GetFollow(SLRproNum[j].Left);
if (!back.Contains(follow))
{
back.Add(follow);
}
}
}
}
else if (index != -1 && SLRobjNum[proitemset[i].Container[index]].Right.IndexOf('.') < SLRobjNum[proitemset[i].Container[index]].Right.Length - 1)
{
string str = SLRobjNum[proitemset[i].Container[index]].Right[SLRobjNum[proitemset[i].Container[index]].Right.IndexOf('.') + 1].ToString();
if (isFinalsymbol(str[0]) && !put.Contains(str))
{
put.Add(str);
}
}
}
}
}
//判断两个集合是否有交集
public bool IsIntersect(List a, List b)
{
foreach (string str in a)
{
if (b.Contains(str))
{
return true;
}
}
return false;
}
//判断back和put列表中的元素是否有冲突
public bool IsConflict()
{
ConstructFollowAndFirst();
for (int i = 0; i < back.Count; i++)
{
for (int j = 0; j < put.Count; j++)
{
if (IsIntersect(back[i], put[j]))
{
return true;
}
}
}
if (back.Count >= 2)
{
for (int i = 0; i < back.Count - 1; i++)
{
for (int j = i + 1; j < back.Count; j++)
{
for (int k = 0; k < back[i].Count; k++)
{
if (back[j].Contains(back[i][k]))
{
return true;
}
}
}
}
}
return false;