www.pudn.com > pl0_compiler_c.rar > pl0.cpp


/////////////////////////////////////////////////////////////////////// 
#include  
#include "pl0.h" 
#include "cifa.h" 
#include "errors.h" 
#include "table.h" 
#include "code.h" 
#include "yufa.h" 
 
CPlCompiler::CPlCompiler(char *filename) 
{ 
	if (fp=fopen(filename,"r")) 
	{ 
		errors=new CErrors(this); 
		table=new Ctable(this); 
		code=new Ccode; 
		cifa=new CCifa(this); 
		yufa=new CYufa(this); 
	} 
	else 
	{ 
		cifa=0; 
		errors=0; 
		code=0; 
		table=0; 
		yufa=0; 
	} 
} 
CPlCompiler::~CPlCompiler() 
{ 
	if (cifa) delete cifa; 
	if (errors) delete errors; 
	if (code) delete code; 
	if (table) delete table; 
	if (yufa) delete yufa; 
	if (fp) fclose(fp); 
} 
int CPlCompiler::Compile() 
{ 
	if (!(cifa && yufa && code && errors && table && fp)) 
		return 0; 
	yufa->Analysis(); 
	return 1; 
} 
void CPlCompiler::DisplaySrcfile() 
{ 
	if (!fp) return; 
	long pos=ftell(fp); 
	fseek(fp,0,SEEK_SET); 
	char ch; 
	while((ch=getc(fp))!=EOF) putchar(ch); 
	putchar('\n'); 
	fseek(fp,pos,SEEK_SET); 
} 
int CPlCompiler::ErrorNumber() 
{ 
	if (!errors) return 0; 
	return errors->Number(); 
} 
void CPlCompiler::DisplayErrors() 
{ 
	if (errors) errors->Display(); 
} 
void CPlCompiler::ListCode() 
{ 
	if (code) code->ListCode(); 
} 
void CPlCompiler::Interpret() 
{ 
	if (code) code->Interpret(); 
}