pl0.cpp
来自「编译课程设计」· C++ 代码 · 共 73 行
CPP
73 行
#include <stdio.h>
#include "pl0.h"
#include "cifa.h"
#include "errors.h"
#include "biaoge.h"
#include "daima.h"
#include "yufa.h"
CPlCompiler::CPlCompiler(char *filename)
{
if (fp=fopen(filename,"r"))
{
errors=new CErrors(this);
biaoge=new CBiaoge(this);
daima=new CDaima;
cifa=new CCifa(this);
yufa=new CYufa(this);
}
else
{
cifa=0;
errors=0;
daima=0;
biaoge=0;
yufa=0;
}
}
CPlCompiler::~CPlCompiler()
{
if (cifa) delete cifa;
if (errors) delete errors;
if (daima) delete daima;
if (biaoge) delete biaoge;
if (yufa) delete yufa;
if (fp) fclose(fp);
}
int CPlCompiler::Compile()
{
if (!(cifa && yufa && daima && errors && biaoge && 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 (daima) daima->ListCode();
}
void CPlCompiler::Interpret()
{
if (daima) daima->Interpret();
}