main.cpp

来自「一个简单的C语言子集的编译器,一个简单的C语言子集的编译器」· C++ 代码 · 共 52 行

CPP
52
字号
#pragma warning(disable:4786)

#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include "global.h"
#include "scan.h"
#include "parse.h"
#include "util.h"
#include "analyze.h"
#include "gencode.h"

using namespace std;
void copyright()
{
	cout<<"\nC Minus Compiler\n";
	cout<<"According to the design in the book\n"
		"\"Compiler Construction Principles and Practice\""
		" by Kenneth C. Louden\n";
	cout<<"Generate TM code, execute with TM.exe\n\n";
	cout<<"Wrriten by bood\n";
	cout<<"Homepage: http://boodweb.126.com\n";
	cout<<"Email: boodweb@yahoo.com.cn\n";
}
int main(int argc,char *argv[])
{
	init();
	copyright();
	if(argc<2){
		cout<<"No source file specified."<<endl;
		cout<<"Usgae: cminus <source file>\n";
		return 0;
	}
	fsource.open(argv[1]);
	ftoken.open("token.txt");
	fsyntax.open("syntax.txt");
	fsymbol.open("symbol.txt");
	fcode.open("code.txt");
	TreeNode *p=parse();
	PrintSyntaxTree(p,fsyntax);
	BuildSymbolTable(p);
	fsymbol<<"name"<<"\t\t"<<"location"
		<<"\t\t"<<"lineno"<<"\t\t"<<
		"nestlevel"<<endl;
	PrintOneTable(&GlobalBucket,fsymbol);
	PrintSymbolTable(p,fsymbol);
	TypeCheck(p);
	genCode(p);
	return 0;
}

⌨️ 快捷键说明

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