codegenerator.cpp

来自「an easy compiler to compile C」· C++ 代码 · 共 53 行

CPP
53
字号
// odeGenerator.cpp: implementation of the CodeGenerator class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SymbolTable.h"
#include "CodeGenerator.h"
#include <iostream>

using namespace std;

extern SymbolTable symbol_table;

CodeGenerator::CodeGenerator()
{

}

void CodeGenerator::emit(const Token& tk) {

	switch(tk.type) {
	case '+': case '-': case '*': case '/':
		cout << (char) tk.type;
		break;

	case Token::DIV:
		cout << "DIV";
		break;

	case Token::MOD:
		cout << "MOD";
		break;
	
	case Token::NUM:
		cout << tk.value;
		break;

	case Token::ID:
		cout << symbol_table.getLexeme(tk.value);
		break;
	
	case ';':
		cout << endl;
		break;

	default:
		cout << "(token: " << tk.type << ", value: " << tk.value;
		break;
	}//switch
}


⌨️ 快捷键说明

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