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

📄 lexanalyze.h

📁 pl0文法编译器
💻 H
字号:
#ifndef __LEXANALYZE_H
#define __LEXANALYZE_H

#include "SymSet.h"
#include <string>
#include <fstream>
#include <vector>
#include <map>
using namespace std;

/*****************************词法分析***********************************/
/***将源文件全部缓冲到内存												*/
/***作者:马永焘														*/
/***日期:2006年2月15日													*/
/************************************************************************/

class PL0Compiler;

class LexAnalyze
{
public:
	LexAnalyze(PL0Compiler *);
	LexAnalyze(ifstream &fileStream);
	
public:
	token_pair getSymbol();
	int  getLineNum(){return lineNum+1;}//返回当前行数
	Location getLocation();
	void showScript();

private:
	PL0Compiler *pl0Compiler;
	vector<string> linesOfFile;//源代码的所有行
	string curLine;//当前读取的行
	int	lineNum;//行数
	int indexOfCh;//当前读取字符的索引
	resvword_value resvwordMap;// 保留字-枚举值映射表
	token_pair tokenPair;

private:
	void initResvwordMap();
	void initSourceFile( ifstream &fileStream );
	bool getCh(char &ch);//读取字符
	void backChar(){indexOfCh = (indexOfCh-1)<0?0:(indexOfCh-1);}//后退一个字符
	inline void getNBC(char &ch);//跳过非空字符或换行符
	bool resvSearch(const string &word);//查保留字表,若是保留字返回true否则返回false
	void getNum(string &token, char &ch);
};

inline void LexAnalyze::getNBC(char &ch)
{
	while(ch==' ' || ch=='\t' || ch=='\n')
	{
		getCh( ch );
	}
}

#endif //cifa.h

⌨️ 快捷键说明

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