[cp] LR_1 分析表的生成
来源:互联网 发布:超市扫码软件 编辑:程序博客网 时间:2024/05/16 09:22
昨天刚写完 SLR
今天晚上大概改了下就变成 LR1 的了 @_@
改的地方有几个:
1:项目
/*
* [项目]
* */
struct Item
{
Item(int nont,int pro,int dot,int tmnl);
bool operator == (const Item& itm); // [比较项如上 6/20/2005]
Item& operator = (const Item& itm);
operator string()const;
int index_of_nont; // [该项目所在的非终结符位置]
int index_of_pro; // [该项目对应该非终结符的产生式位置]
int index_of_dot; // [记录点的位置]
int index_of_terminal; // [展望字符的下标 6/28/2005] ----相对于 SLR 的改变
};
/*————————————————————————————————————————————/
* Desc: 生成项目
* Parm
/————————————————————————————————————————————*/
void Grammar::gen_item()
{
for(unsigned int i=0; i<m_idx_grammar.size(); i++)
{
for(unsigned int j=0 ; j<m_idx_grammar[i].size(); j++)
{
for(unsigned int x = 0; x<m_idx_grammar[i][j].size()+1; x++)
{
/* —— 2005/06/28 ——
* [如果是第一个项目,则只考虑标记字符]
* */
if(i == 0 && j == 0 && x == 0)
{
m_items.push_back(Item(i,j,x,this->get_index_of_flagletter()));
}
else
{
for(int k = 0; k < (int)m_str_terminals.size(); k++)
{
m_items.push_back(Item(i,j,x,k));
}
}
}
}
}
debug_out("项目:");
debug_out(m_items);
}
/*————————————————————————————————————————————/
* Desc: 获得项目的信息,以及点的下一位置的符号下标 [暂时不做下标越界判断]
* Parm
/————————————————————————————————————————————*/
ItemType Grammar::get_info_of_next_index(const Item& item, Index& out_index,First::TypeFirstCollection& out_first)const
{
/*
* [如果点的位置在最后,则表示规约项目]
* */
if(item.index_of_dot >= (int)m_idx_grammar[item.index_of_nont][item.index_of_pro].size() )
{
// [判断是否为接受项目]
if(m_idx_grammar[item.index_of_nont][item.index_of_pro][ item.index_of_dot - 1] == this->get_pre_idx_start() /*获得开始符号下标,输入时的而不是扩展后的*/)
{
return IT_A;
}
return IT_R;
}
out_index = this->m_idx_grammar[item.index_of_nont][item.index_of_pro][item.index_of_dot];
TypeProductionItem new_pro_item;
new_pro_item.insert(
new_pro_item.begin(),
m_idx_grammar[item.index_of_nont][item.index_of_pro].begin()+item.index_of_dot + 1,
m_idx_grammar[item.index_of_nont][item.index_of_pro].end());
new_pro_item.push_back(Index( item.index_of_terminal, true) );
this->m_first.GetFirst(new_pro_item ,out_first); // [相对于SLR的增加,求 FIRST 集]
return IT_S;
}
…… 等几个地方 :)
- [cp] LR_1 分析表的生成
- [cp] 预测分析表的生成
- [cp] SLR分析表的生成
- [cp] SLR 分析表的生成以及分析程序 (1)
- [cp] SLR分析表的生成 以及分析程序 (2)
- [cp] SLR分析表的生成 以及分析程序(3)
- [cp] 预测分析表的生成 (更新)
- [cp] 词法分析器的自动生成
- linux0.11中*((char **) cp)的分析
- Linux命令分析: cp
- cp -R 和cp -r的区别
- cp -r与cp -R的区别
- cp -r 和 cp -R 的区别
- cp 命令的用法
- java的cp命令
- 对*cp++的理解
- java的cp命令
- LINUX的cp命令
- winxp下不能被ping到问题的解决
- 海豹突击队体能训练手册——前言
- Resin服务器的使用(转)
- 阅读笔记:库绑定 - 我们应该让它更精确一些
- FreeBSD5.4Release X Windows 安装笔记 (Freebsd5.4R+Gnome2.10.0)
- [cp] LR_1 分析表的生成
- UML中扩展和泛化的区别
- 关于Win32/Parite.a病毒
- 病毒爱情后门(lovgate)
- C++笔记
- Web标准的基本概念
- 第二十九期:CSDN论坛秀-Delphi版-本期作秀:qxj(游民)
- 今天做了个导航条(使用外部文件XML)
- I18N&L10N