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

📄 main.cpp

📁 <compiler construction principles and practice>书中定义的tiny语言编译器。
💻 CPP
字号:
// main.cpp : 定义控制台应用程序的入口点。
//


#include "stdafx.h"
#include <iostream>
using namespace std;
#include <iomanip>
#include <fstream>
#include <string.h>

int Error = 0;

#include "globals.h"
#include "Scan.h"
#include "Parse.h"
#include "systab.h"
#include "Analyze.h"
#include "Code.h"
#include "Cgen.h"



int _tmain(int argc, _TCHAR* argv[])
{
	char sourcefile[120], codefile[120];
	cout<<"Enter source file name:  ";
	cin>>sourcefile;
	if ( strchr (sourcefile, '.') == NULL)
	{
		strcpy(codefile, sourcefile);
		strcat(sourcefile,".tny");
		
	}
	else
	{
		int n;
		for(n = 0; sourcefile[n] != '.'; n++);
		strncpy(codefile, sourcefile, n);
		codefile[n]='\0';
	}
	strcat(codefile, ".tm");

	Analyze tiny(sourcefile);
	
	TreeNode * tree = tiny.parse();
	if(!Error)
		tiny.buildSymtab( tree);
	
	if(!Error)
		tiny.typeCheck( tree );
	cout<<endl<<endl;

	if(!Error)
	{	Cgen tinycode(codefile);
		tinycode.codeGen(tree, codefile);
	}

	ofstream out;
	out.open("Tiny.bat");
	out<<"echo\ntm.exe "<<codefile;
	out.close();
	system("pause");
	system("Tiny.bat");

	
	return 0;
}

⌨️ 快捷键说明

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