List str = new List(); //存储输入的产生式 string curr = Console.ReadLine(); while (curr != '.') { str.Add(curr); curr = Console.ReadLine(); } foreach (string s in str) { int len = s.Length; LR[s[0]].Add(s.Substring(3)); //A->BC,key:A,value:BC record[s[0]]++; //记录右侧为此非终结符的产生式的数量,用于ComputeEpsilon foreach (char c in s) { if ((c == '-' && s[s.IndexOf(c) + 1] == '>')) //碰到箭头直接跳过 { continue; } if (!VT.Contains(c) && !VN.Contains(c)) //判断是否已经存储 { int s = c - 'A'; if (s >= 0 && s <= 25) { VN.Add(c); } else { VT.Add(c); } } } }

C++ 到 C# 代码转换:产生式解析示例

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

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