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

📄 lexicalanalyzer.h

📁 这是我们老师给我们的例子
💻 H
字号:
class LexicalAnalyzer
{
	public:
		void setFilename(string filename);
		/*
		   to initiate the ifstream "input",
		   and the special node "noT" which means no token.
		*/
		LexicalAnalyzer();
	
		symbolElement* yylex();
		/*
		   return the pointer points to the node for current token in the symbolTable.
		*/
		bool isEnd();
		/*
		   If reaches the end of the current source file return true else false.
		*/
		int line;//the line of the current token.
		symbolElement* noT;//a special node,with nothing in it ,only means current lexeme is not a token.
		void ungetT();
		~LexicalAnalyzer();//destructer.
	private:
		string filename;//Used to store the path of the source file
		ifstream input;
		SymbolTable cTable;
		int cLength;//length of the current token,less then 64.
		symbolElement* curT;//point to current symbolElement
	    char buffer[64];
		/*
		   to buffer current token,an id has a limit length 64 characters. A num is supposed to be less than that. 
		*/
		bool DFA(int &state,char a);
		/*
		   Go through the DFA defind for the langue to find out 
		   what token the current lexeme is.
		   Return true if it can be sure of what token current lexeme is
		   false else.
		*/
		void skip();
		/*
		   skip the current lexeme,
		*/
		int findEntry(char a);
		/*
		  when read in a character,find the entry of the DFA for the lexeme.
		*/
		void inBuffer(char buffer[],char a);
		/*
		   insert the current character into buffer.
		*/
};

⌨️ 快捷键说明

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