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

📄 symboltable.h

📁 一个用C++写的编译器
💻 H
字号:
/*
	SymbolTable class,it is a list,include struct SymbolElement as it's element.
	Used to store infomations about lexemes.
*/
using namespace std;
struct symbolElement
{
	string token;
	char* entry;//point to lexemeArr
	double attribute;//will be implemented later in parser 
	symbolElement* next;
	symbolElement()
	//constructor
	{
		token="";
		entry=0;
		attribute=NULL;
	}
};
//a struct in symbol table
class SymbolTable
{
	public:
		void initiate(string filename);
		/*
			Read the file in the path "filename",counted the characters in it
			allocate enough space to lexemeArr.
			Initiate the SymbolTable with keywords.
		*/
		symbolElement* insert(string lex,string tok);
		/*
		  first find(string lexeme),if founded ,return current
		  else insert the lex into lexemeArr and construct a new 
		  SymbolElement then insert it into the list.
		*/
		symbolElement* find(string lexeme);
		/*
		  search the list to find lexeme,if founded return the current pointer
		  else return 0.
		*/
		~SymbolTable();
		//destructor
	private:
		char* SymbolTable::insertArr(string lex);
		/*
			Insert lex into the lexemeArr,return the pointer that points to the
			first character of the string.
		*/
        string readArr(char* entry);
		/*
			Every lexeme in the array that "entry" points to is ended by '\n'.
			Returns the string it read from the array when it reachs a '\n'.
			The first character of the string is pointed by "entry".
		*/
		symbolElement* head;
		symbolElement* current;//Used to search the list
		int count;//count the number of SymbolElements
		int c;//first empty position of lexemeArr;
		int i;//number of characters in the source file;
		char* lexemeArr;//Used to store lexemes
};
//symbol table

⌨️ 快捷键说明

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