table.cpp

来自「这是一个用c++写的预测分析法程序,是编译原理课程设计的内容,可以预测分析语言」· C++ 代码 · 共 100 行

CPP
100
字号

#include <windows.h>
#include <stdio.h>
#include "Table.h"

GRID::GRID()
{
	StackTopSign = END_SIGN;
	InputSign    = END_SIGN;	
}

void GRID::operator=(const GRID& other)
{
	StackTopSign   = other.StackTopSign;
	InputSign      = other.InputSign;
	SelectableRule = other.SelectableRule;	
}

TABLE::TABLE() : StackTopSignSet(),InputSignSet()
{
	nGrids = 0;
	Grid   = 0;
	m_bDetered = true;
	LeftRecursive = false;
}

TABLE::TABLE(const TABLE& other) : StackTopSignSet(),InputSignSet()
{
	nGrids = 0;
	Grid   = 0;
	*this = other;	
}

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

bool TABLE::IsDeterminate()
{
	return m_bDetered;
}

void TABLE::operator=(const TABLE& other)
{
	Reset();
	StackTopSignSet = other.StackTopSignSet;
	InputSignSet    = other.InputSignSet;
	m_bDetered      = other.m_bDetered;
	StartSign       = other.StartSign;
	LeftRecursive   = other.LeftRecursive;
	nGrids = other.nGrids;
	Grid = new GRID[nGrids];
	CopyMemory(Grid,other.Grid,sizeof(GRID) * nGrids);
}

void TABLE::Reset()
{
	StackTopSignSet.Reset();
	InputSignSet.Reset();
	if (Grid) delete []Grid;
	nGrids = 0;
	Grid = 0;
	m_bDetered = true;
	LeftRecursive = false;
}

int	TABLE::AddGrid(SIGN StackTop,SIGN Input,RULE Rule)
{
	int   i;
	GRID* pTemp;
	// 检查是否有在一个格子填写多个规则的情形
	for(i = 0; i < nGrids; i++)
		if (Grid[i].StackTopSign == StackTop && Grid[i].InputSign == Input)
		{
			m_bDetered = false;
			break;
		}

	pTemp = Grid;
	Grid  = new GRID[nGrids + 1];
	CopyMemory(Grid,pTemp,sizeof(GRID) * nGrids);
	Grid[nGrids].StackTopSign   = StackTop;
	Grid[nGrids].InputSign      = Input;
	Grid[nGrids].SelectableRule = Rule;
	nGrids = nGrids + 1;

	delete []pTemp;

	return nGrids;
}

GRID TABLE::operator[](int NO)
{
	GRID grid;
	if (NO >= 0 && NO < nGrids)
		grid = Grid[NO];
	return grid;
}

⌨️ 快捷键说明

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