pl0.cpp
来自「c语言做的pl0编译器」· C++ 代码 · 共 71 行
CPP
71 行
///////////////////////////////////////////////////////////////////////
#include <stdio.h>
#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();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?