📄 main.cpp
字号:
// Main function of the compiler
//
// Written by bood, boodweb@163.com, http://boodweb.126.com
// 2004-08-06
// Adds support for simple preprocessing
// i.e. file include and simple macro definition
// bood, 2005-03-13
// Disable the awful warnings
#pragma warning(disable:4786)
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include "global.h"
#include "pp_scan.h"
#include "scan.h"
#include "parse.h"
#include "analyze.h"
#include "symtable.h"
#include "code.h"
#include "util.h"
using namespace std;
void copyright()
{
cout<<"\nC Minus Compiler v0.2\n";
cout<<"According to the design in the book\n"
"\"Compiler Construction Principles and Practice\""
" by Kenneth C. Louden\n";
cout<<"Generate assmeble code, link using MASM/TASM\n\n";
cout<<"Wrriten by bood, 2004-08-13\n";
cout<<"Homepage: http://boodweb.126.com\n";
cout<<"Email: boodweb@yahoo.com.cn\n\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;
}
// preprocessing into preproc.txt
fpreproc.open("preproc.txt");
preprocess(argv[1], fpreproc);
fpreproc.close();
include_it = include_list.begin();
// compile preproc.txt just as before
fsource.open("preproc.txt");
ftoken.open("token.txt");
fsyntax.open("syntax.txt");
fsymbol.open("symbol.txt");
fcode.open("code.txt");
TreeNode *p=parse();
PrintSyntaxTree(p,fsyntax);
BuildSymbolTable(p);
if(bSemanticError) {
cout<<"Semantic error found, compilation stopped\n";
return 0;
}
fsymbol<<"name"<<"\t\t"<<"location"
<<"\t\t"<<"lineno"<<"\t\t"<<
"nestlevel"<<endl;
PrintOneTable(&GlobalBucket,fsymbol);
PrintSymbolTable(p,fsymbol);
TypeCheck(p);
if(bSemanticError) {
cout<<"Semantic error found, compilation stopped\n";
return 0;
}
genCode(p);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -