提交 dd2e895a 创建 作者: 宋海霞's avatar 宋海霞

modify main.c

上级 c868e3aa
...@@ -197,10 +197,69 @@ void PickupLeftFactor(Rule* pHead) ...@@ -197,10 +197,69 @@ void PickupLeftFactor(Rule* pHead)
Rule* pNewRule; // Rule 指针 Rule* pNewRule; // Rule 指针
RuleSymbol* pSelect; // Select 游标 RuleSymbol* pSelect; // Select 游标
// do
// TODO: 在此添加代码 {
// isChange = 0;
for(pRule = pHead; pRule != NULL; pRule = pRule->pNextRule)
{
// 取 Rule 中的一个 Select 作为模板,调用 LeftFactorMaxLength 函数确定左因子的最大长度
int Count = 0;
for(pSelectTemplate = pRule->pFirstSymbol; pSelectTemplate != NULL; pSelectTemplate = pSelectTemplate->pOther)
{
if((Count = LeftFactorMaxLength(pSelectTemplate)) > 0)
break;
}
// 忽略没用左因子的 Rule
if(Count == 0)
continue;
pNewRule = CreateRule(pRule->RuleName); // 创建新 Rule
GetUniqueRuleName(pRule, pNewRule->RuleName);
isChange = 1; // 设置标志
// 调用 AddSelectToRule 函数把模板左因子之后的部分加到新 Rule 的末尾
// 将模板左因子之后的部分替换为指向新 Rule 的非终结符
//
// TODO: 在此添加代码
//
// 从模板之后的位置循环查找包含左因子的 Select,并提取左因子
pSelect = pSelectTemplate->pOther;
RuleSymbol **pSelectPtr = &pSelectTemplate->pOther;
while(pSelect != NULL)
{
if(NeedPickup(pSelectTemplate, Count, pSelect)) // Select 包含左因子
{
// 调用 AddSelectToRule 函数把左因子之后的部分加到新 Rule 的末尾
// 将该 Select 从 Rule 中移除,释放内存,并移动游标
//
// TODO: 在此添加代码
//
}
else // Select 不包含左因子
{
// 移动游标
//
// TODO: 在此添加代码
//
}
}
// 将新 Rule 加入到文法链表
//
// TODO: 在此添加代码
//
}
} while (isChange == 1);
} }
/* /*
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论