main.cpp

来自「<compiler construction principles and」· C++ 代码 · 共 68 行

CPP
68
字号
// 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 + =
减小字号Ctrl + -
显示快捷键?