📄 symboltab.h
字号:
#ifndef MY_SYMBOLTABLE_H_
#define MY_SYMBOLTABLE_H_
/**: symboltable.h , header file
&
* define symbol table.
* author: lonelyforest. data: 2006.4.4
*/
#include "parser.h"
// size of the hash table
const int TabSIZE = 211;
// SHIFT is use as multiplier in hash function
const int SHIFT = 4; // 2*2*2*2, times 16, 4bit;
/*-----------------------------------------------------------------------*/
struct LineList { // LineListRec
int lineno; // Remember the line NO. in sourcefile
LineList* next;
LineList():lineno(0), next(NULL) {}
~LineList() { if (next) delete next; }
};
/*-----------------------------------------------------------------------*/
struct BucketList { // BucketListRec
BucketList* next; // the next hash
LineList* lines; // reference line
string name;
string scope;
tokenType type;
int memloc; // memory location
bool isArr;
public:
BucketList():memloc(0), lines(NULL), next(NULL) {}
~BucketList()
{
if (lines) delete lines; // ...
if (next) delete next;
}
};
/*-----------------------------------------------------------------------*/
/**: class symTable, symbol table;
&
* Encapsulation all method of symbol table
*
* author: lonelyforest. data: 2006.4.5
*/
class symTable {
public:
symTable();
~symTable();
void initial();
// functino insert, insert symbol intot symbol table
void insert(const string& name, const string &scope, const tokenType type,
const int lineno, const long memloc, const bool isArr = false);
// return the symbols' type(tokenType)
tokenType search_type(const string& name, const string& scope);
bool search_arr(const string& name, const string& scope);
// if found, then return symbols' memory locations, else return -1;
long lookup(const string& name, const string &scope);
// print symbol table to file: symFileName
void printSymTable(const string& symFileName);
protected:
int hash(const string& key);
BucketList* hashTable[TabSIZE];
};
/*-----------------------------------------------------------------------*/
#endif // end #ifndef
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -