pl0compiler.cpp

来自「pl0文法编译器」· C++ 代码 · 共 46 行

CPP
46
字号
#include "PL0Compiler.h"
#include "LexAnalyze.h"
#include "Errors.h"
#include "GramAnalyze.h"
#include "SymbolTable.h"
#include "CCode.h"
#include <iostream>
using namespace std;

PL0Compiler::PL0Compiler(const string &infileName, const string &outfileName):infileStream(infileName.c_str())
{	
	if(!infileStream)
	{
		cout<<"文件无法打开,请确认文件名或路径正确。"<<endl;
		lexAnalyze = 0;
		errors = 0;
		exit(1);
	}
	else
	{
		lexAnalyze = new LexAnalyze(this);
		errors = new Errors(this);
		gramAnalyze = new GramAnalyze(this);
		symbolTable = new SymbolTable(this);
		ccode = new CCode(this);
		outFileName = outfileName;
	}
}

PL0Compiler::~PL0Compiler()
{
	if(lexAnalyze) delete lexAnalyze;
	if(errors) delete errors;
	if(gramAnalyze) delete gramAnalyze;
	if(symbolTable) delete symbolTable;
	if(ccode) delete ccode;
	infileStream.close();
	//outfilestream.close();
}

void PL0Compiler::displayScript(){lexAnalyze->showScript();}
void PL0Compiler::compile(){gramAnalyze->startCompile();}
void PL0Compiler::listCode(){ccode->list();}
bool PL0Compiler::listError(){return errors->display();}
void PL0Compiler::wrtToFile(){ccode->writeToFile(outFileName);}

⌨️ 快捷键说明

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