|
一个简单的C语言编译器(1)
源代码:
// // #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include <windows.h> #include <string> #include <fstream> #include <list> #include <stack> #include <ctype.h> using namespace std;
class Symbol { public: int line; string Word; char group; Symbol(); Symbol(const Symbol &b); virtual ~Symbol(); operator =(const Symbol &b); string code; };
class Label { public: Label(); virtual ~Label(); string text; private: int n; static int next(); static int _label; }; class Action { public: static int lookUp(char v,int s); private: Action(); ~Action(); static int Table[54][19]; static string vs; }; class Goto { public: static int lookUp(char v,int s); private: Goto(); ~Goto(); static int Table[54][9]; static string vs; }; class Compiler { public: optimize(); string code; char nextChar(); preProcess();//预处理器 parser();//语法分析器 Symbol *lexer();//词法分析器 void emitter();//生成器 Compiler(string CmdLine); virtual ~Compiler(); err(int no,int line); int hasError;//错误发生状态
private: int lookup(string m); char currentChar; string fileName; int line;//行数状态 Compiler(); int hasFile;//源文件打开状态 int needOutSuppose;//输出支持状态 ifstream in;//输入CRR文件 ofstream log;//输出日志文件 ofstream out;//输出ASM文件
|