www.pudn.com > pl0.zip > Simpsc.cpp


// Simpsc.cpp: implementation of the Simpsc class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "Simpsc.h" 
#include "pcode.h" 
#include "Table.h" 
#include "Grammar.h" 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
Simpsc::~Simpsc() 
{ 
	if(ChaTable) delete ChaTable; 
	if(gra) delete gra; 
	if(CodeList) delete CodeList; 
	pas.close(); 
} 
 
void Simpsc::OpenFile(string &name) 
{ 
	string n; 
	n=name+".txt"; 
	pas.open(n.data(),ios::in); 
	if(!pas) 
	{ 
		cout<<"打开程序文件失败!\n"; 
		exit(0); 
	} 
	else 
	{ 
		ChaTable=new Table(this); 
		gra=new Grammar(this); 
		CodeList=new pcode; 
	} 
} 
 
bool Simpsc::WordCheck() 
{ 
	int i,j,row; 
	char astr[Longest]; 
	string passage; 
 
	TokenFile.open("TokenFile.dat",ios::binary|ios::out); 
	if(!TokenFile) 
	{ 
		cout<<"打开输出文件失败!\n"; 
		exit(0); 
	} 
	j=0; 
//	cout<gra->Analysis(Token); 
	//gra->Analysis(); 
} 
 
void Simpsc::DisplaySrcfile() 
{ 
	char astr[Longest]; 
	int i; 
//	long pos=pas.tellg(); 
//	pas.seekg(0L,ios::beg); 
	for(i=1;!pas.eof();i++) 
	{ 
		pas.getline(astr,Longest,'\n'); 
		cout<Interpret(); 
} 
 
void Simpsc::ListCode() 
{ 
	CodeList->PrintCode(); 
} 
 
void Simpsc::OutFile(string &name) 
{ 
	this->CodeList->OutToFile(name); 
}