⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 table.cpp

📁 此程序可以把编译原理中的不确定的有限自动机确定化
💻 CPP
字号:

#include "Table.h"

// TABLE_LINE 类的实现
TABLE_LINE::TABLE_LINE()
{
	Cols = 0;
	pGrids = NULL;
}

TABLE_LINE::TABLE_LINE(TABLE_LINE& Line)
{
	Cols = 0;
	pGrids = NULL;
	*this = Line;
}

TABLE_LINE::~TABLE_LINE()
{
	if (pGrids != NULL) delete []pGrids;
}

void TABLE_LINE::Reset()
{
	if (pGrids != NULL) 
		delete []pGrids;
	Cols   = 0;
	pGrids = NULL;
}

TABLE_LINE& TABLE_LINE::operator=(TABLE_LINE& other)
{
	int no;
	Reset();
	Cols   = other.Cols;
	pGrids = new STATE_SET[Cols];
	for(no = 0; no < Cols; no++)
		pGrids[no] = other.pGrids[no];
	return *this;
}

STATE_SET& TABLE_LINE::operator[](int no)
{	
	if (no >= 0 && no < Cols) 
		return pGrids[no];	
}

// TABLE 类的实现
TABLE::TABLE()
{
	LineNum = 0;
	pLines  = NULL;
}

TABLE::~TABLE()
{
	Reset();
}

int TABLE::GetLineNum()
{
	return LineNum;
}

TABLE_LINE  TABLE::GetLine(int no)
{
	TABLE_LINE  Line;
	if (no >= 0 && no < LineNum)
		Line = pLines[no];

	return Line;
}

TABLE_LINE& TABLE::operator [](int no)
{
	if (no >= 0 && no < LineNum)
		return pLines[no];	
}

void TABLE::AddLine(TABLE_LINE pNewLine)
{	// 进行深拷贝
	TABLE_LINE* pTemp;
	int   no;

	pTemp  = pLines;
	pLines = new TABLE_LINE[LineNum + 1];
	for(no = 0; no < LineNum; no++)
		pLines[no] = pTemp[no];
	pLines[LineNum] = pNewLine;
	
	delete []pTemp;
	LineNum = LineNum + 1;
}

void TABLE::Reset()
{
	if (pLines != NULL)  delete []pLines;
	LineNum = 0;
	pLines  = NULL;
}

STATE_SET  TABLE::GetGrid(int row,int col)
{
	STATE_SET  grid;
	if ((row >= 0 && row < LineNum) && 
		(col >=0 && col < pLines[row].Cols))
		grid = pLines[row].pGrids[col];

	return grid;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -