public void buildtable for int i = 0; i statesCount; i++ 对每个状态经过终结符的情况进行判断 Liststring strings = new Liststring; foreach var
public void SLRAnaly() { buildtable(); //构建SLR分析表
//初始化分析表
SLRAna = new Table[proitemset.Count][];
for (int i = 0; i < proitemset.Count; i++)
{
SLRAna[i] = new Table[Echar.Count + Nchar.Count];
for (int j = 0; j < Echar.Count + Nchar.Count; j++)
{
SLRAna[i][j] = new Table();
}
}
//填写移进和归约项
for (int i = 0; i < proitemset.Count; i++)
{
for (int j = 0; j < Echar.Count; j++)
{
string s = table[i][j];
if (s.Length > 0)
{
if (s[0] == 'S')
{
int nextState = int.Parse(s.Substring(1));
SLRAna[i][j].type = 's';
SLRAna[i][j].id = nextState;
}
else if (s[0] == 'r')
{
int productionNum = int.Parse(s.Substring(1));
SLRAna[i][j].type = 'r';
SLRAna[i][j].id = productionNum;
}
}
}
}
//填写goto项
for (int i = 0; i < proitemset.Count; i++)
{
for (int j = 0; j < Nchar.Count; j++)
{
string s = table[i][j + Echar.Count];
if (s.Length > 0)
{
int nextState = int.Parse(s);
SLRAna[i][j + Echar.Count].type = 'g';
SLRAna[i][j + Echar.Count].id = nextState;
}
}
}
//填写接受项
int acceptState = proitemset.Count - 1;
int acceptSymbolIndex = Echar.IndexOf('#');
SLRAna[acceptState][acceptSymbolIndex].type = 'a';
}
原文地址: https://www.cveoy.top/t/topic/hrhl 著作权归作者所有。请勿转载和采集!