//判断当前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;

ListListstring back;:创建一个二维字符串列表back用于存储归约项的FOLLOW集。Liststring put;:创建一个字符串列表put用于存储移进项的FIRST集。back = new ListListstring; put = new Liststring;:将back和put列表初始化为空。遍历项目集所有产生式。如果当前产生式的点号位置等于右部的长度。如果当前产生式的

原文地址: https://www.cveoy.top/t/topic/hrsG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录