// --------------------using命名空间 using System.Collections.Generic;

// --------------------变量声明和初始化 Dictionary<char, int> VT = new Dictionary<char, int>(); // 终结符 Dictionary<char, int> VN = new Dictionary<char, int>(); // 非终结符 Dictionary<char, List> LR = new Dictionary<char, List>(); // 文法分开存储 Dictionary<char, int> record = new Dictionary<char, int>(); // 记录左侧相同的产生式数量 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; if (!LR.ContainsKey(s[0])) { LR.Add(s[0], new List()); } LR[s[0]].Add(s.Substring(3)); // A->BC,key:A,value:BC if (!record.ContainsKey(s[0])) { record.Add(s[0], 0); } record[s[0]]++; // 记录右侧为此非终结符的产生式的数量,用于ComputeEpsilon for (int j = 0; j < s.Length; j++) { if ((s[j] == '-' && s[j + 1] == '>')) { // 碰到箭头直接跳过 j += 1; continue; } if (!VT.ContainsKey(s[j]) && !VN.ContainsKey(s[j])) { // 判断是否已经存储 int num = (int)s[j]; if (num >= 65 && num <= 90) { VN.Add(s[j], 1); } else { VT.Add(s[j], 1); } } }

将以下c++代码转成对应的c#代码--------------------预处理unordered_mapcharintVT;终结符unordered_mapcharintVN;非终结符unordered_mapchar vectorstringLR;文法分开存储unordered_mapchar intrecord;记录左侧相同的产生式数量vectorstringstr;存储输入的产生式	str

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

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