⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symtable.cpp

📁 一个类c语言的解释器
💻 CPP
字号:
/*******************************************************
SymTable.cpp
武汉大学国际软件学院软件工程05级7班
崔灿
200532580235
2007-12-1
********************************************************/
#include "SymTable.h"

void SymTable::insert(Symbol* sym){
	//Symbol *s = new Symbol(sym);
	table->find(sym->id);
	(*table)[sym->id] = sym;
}

Symbol* SymTable::find(std::string id){
	//先在本层符号表里面查询
	if ((*table)[id]!=NULL)
	{
		return (*table)[id];
	}
	//parent==NULL时,已经是最高层的符号表了
	if (parent==NULL)
	{
		return NULL;
	}
	//递归的在上一层符号表里面查询
	return parent->find(id);
}

SymTable::SymTable(/*SymTable* parent*/){
	table = new map<string,Symbol*>;
	this->parent = NULL;
}

Symbol::Symbol(){
	this->size = 1;
	this->type = 0;
	this->isfun = false;
	this->isarr = false;
}

Symbol::Symbol(int type, std::string id, int size, std::string address){
	this->type = type;
	this->id = id;
	this->size = size;
	this->address = address;
}

Symbol::Symbol(Symbol *sym){
	
}

Function::Function(){
	args = new vector<int>;
}

Function* FunTable::get_fun(std::string id){
	return (*funs)[id];
}

FunTable::FunTable(){
	funs = new map<string,Function*>;
}

bool SymTable::contain(std::string id){
	if ((*table)[id]!=NULL)
	{
		return true;
	}
	return false;
}

SymTable::~SymTable(){
	map<string,Symbol*>::iterator it = table->begin();
	for(;it!=table->end();it++){
		delete it->second;
	}
	delete table;
}

FunTable::~FunTable(){
	map<string,Function*>::iterator it = funs->begin();
	for(;it!=funs->end();it++){
		delete it->second;
	}
	delete funs;
}

void FunTable::insert(Function *fun){
	funs->find(fun->id);
	(*funs)[fun->id]=fun;
}

Function::Function(Function *f){
	args = new vector<int>;
	this->address = f->address;
	this->args->assign(f->args->begin(),f->args->end());
	this->id = f->id;
	this->type = f->type;
}

⌨️ 快捷键说明

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