⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpsc.cpp

📁 第一次写的
💻 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<<pas.tellg()<<endl;
	for(row=1;!pas.eof();row++)
	{
		pas.getline(astr,Longest,'\n');
		passage.assign(astr);
		i=0;
		while(i<passage.length())
			WordAnaly(passage,i,j,Token,row);
	}
	for(i=0;i<j;i++)
		TokenFile.write((char*)&Token[i],sizeof(Word));
	
	TokenFile.close();
	cout<<"词法分析结束,所有信息已经输出到dat文件中"<<endl;
	return true;
}

bool Simpsc::Compile()
{
	return this->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<<i<<"\t"<<astr<<endl;
	}
	pas.seekg(0L,ios::beg);
	pas.clear();
}

void Simpsc::Interpret()
{
	CodeList->Interpret();
}

void Simpsc::ListCode()
{
	CodeList->PrintCode();
}

void Simpsc::OutFile(string &name)
{
	this->CodeList->OutToFile(name);
}

⌨️ 快捷键说明

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