lexicalanalyzer.h

来自「这是我们老师给我们的例子」· C头文件 代码 · 共 52 行

H
52
字号
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 + =
减小字号Ctrl + -
显示快捷键?