编译原理:从语法分析到编译器生成
1. 上下文无关语言识别算法
1.1 Cocke–Younger–Kasami 算法
Cocke–Younger–Kasami 算法用于识别任意上下文无关语言。以下是该算法的代码实现:
static void Main(string[] args)
{
ReadGrammar();
string input = Console.ReadLine(); // input string
int N = input.Length;
List<char>[,] V = new List<char>[N + 1, N + 1]; // table V
for(int i = 1; i <= N; i++) // fill the leftmost column
V[i, 1] = FindNonterminalsFor(input[i - 1]);
for(int j = 2; j <= N; j++) // main section
for(int i = 1; i <= N - j + 1; i++)
{
V[i, j] = new List<char>(); // V[i, j] = {}
for(int k = 1; k <= j - 1; k++)
V[
超级会员免费看
订阅专栏 解锁全文
6269

被折叠的 条评论
为什么被折叠?



