📄 lrtable.cpp
字号:
#include "StdAfx.h"
#include ".\lrtable.h"
ActionAndGoto::ActionAndGoto()
{
symbol = 0;
status_convert = -1;
type = -1;
}
ActionAndGoto::ActionAndGoto(int sy, int st, int ty)
{
symbol = sy;
status_convert = st;
type = ty;
}
void ActionAndGoto::SetActionAndGoto(int sy, int st, int ty)
{
symbol = sy;
status_convert = st;
type = ty;
}
void ActionAndGoto::output()
{
switch(type)
{
case 1:
{
record<<"后继为"<<symbol<<"类型为"<<"规约---- ";
record<<"按产生式"<<status_convert<<endl;
return;
}
case 2:
{
record<<"类型为"<<"移进---- ";
record<<"接收到终结符"<<symbol<<"转移到状态"<<status_convert<<endl;
return;
}
case 4:
{
record<<"类型为"<<"接收---- ";
record<<"分析结束"<<endl;
return;
}
case 3:
{
record<<"非终结符"<<symbol<<"移进到状态"<<status_convert<<endl;
return;
}
default:return;
}
}
/* ---------------------------------------------------- */
/* ---------------------------------------------------- */
/* ---------------------------------------------------- */
LRTable_Item::LRTable_Item()
{
_aag.clear();
aag_num = 0;
this->line_num = -1;
}
void LRTable_Item::AddItem(int sy, int st, int ty)
{
ActionAndGoto *temp = new ActionAndGoto(sy, st, ty);
_aag.push_back(*temp);
aag_num++;
}
void LRTable_Item::output()
{
for( int i = 0 ; i < aag_num ; i++)
_aag[i].output();
}
/* ---------------------------------------------------- */
/* ---------------------------------------------------- */
/* ---------------------------------------------------- */
LRTable::LRTable(void)
{
this->_item.clear();
this->item_num = 0;
}
void LRTable::output()
{
for( int i = 0 ; i < item_num ; i++)
if( _item[i].aag_num != 0 )
{
record<<"in status "<<_item[i].line_num<<" ; "<<endl;
_item[i].output();
record<<endl<<endl;
}
}
void LRTable::addItem(int line_num)
{
LRTable_Item *newItem = new LRTable_Item();
newItem->line_num = line_num;
_item.push_back(*newItem);
item_num++;
}
LRTable_Item * LRTable::findItem(int status_num)
{
for( int i = 0 ; i < item_num ; i++)
if( _item[i].line_num == status_num )
return &_item[i];
return NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -