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

📄 mlr1.h

📁 使用MFC实现编译原理词法分析器
💻 H
字号:
#if !defined(AFX_MLR1_H__E7626B26_4BA9_4910_849A_151001216F5E__INCLUDED_)
#define AFX_MLR1_H__E7626B26_4BA9_4910_849A_151001216F5E__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif
//-128		空输入
//-127		结束符$
//-126		小数点
//-125..-1	非终结符编号
//0			字符串结束标志
//1-127		终结符的ASCII码

#ifndef LENGTH
#define ID_LENGTH   20
#define LINE_LENGTH 128
#define MAX_IDENT   125
#define MAP_SIZE	16
#define LR_NULL		-128
#define LR_EOF		-127
#define LR_DOT		-126
#define LR_EOS		0
#endif

class MLR1{
public:
	CString GetFirst(int i);
	CString GetFollow(int i);
public:
	MLR1();
	virtual ~MLR1();
	void	ReSet(FILE*);
	const	CStringArray& GetIdentList();
	int		GetExpressNum();
	int		GetIdentNum();
protected:
	bool	Lex1();
	bool	Lex2();
	int		Lex2_1(char*&,bool isUse=false);
	bool	Lex3();
	//词法、语法分析模块
	void	FirstSet1();
	void	FirstSet2(int,int,int);
	bool	FirstSet3(const char*,char*);
	bool	FirstSet4(const char,char*);	
	CString FirstSet5(const char*,bool has_null=false);
	void	FirstSet6();
	//First集求解模块
	CString FollowSet1(const char*,bool has_eof=false);
	bool	FollowSet2(const char*);
	void	FollowSet3();
	bool	FollowSet4(int,int,int);
	//Follow集求解模块
	void	LR0_table1();
	void	LR0_table2(char*);
	//构造LR0分析表模块
private:
	CStringArray	list_Ident;
	CStringArray	list_Express;
	//非终结符表和产生式表
	CStringArray	list_Seed0;
	CStringArray	list_Clouser0;
	int*			list_Index0;
	//用token[LINE_LENGTH]作为临时索引表,完成后拷贝到list_Index0
	//list_Clouser0中字符串的第一个字符指向种子表,LR0项目从第二个字符开始
	struct s_first{
		char Fi[MAP_SIZE];
		char Fo[MAP_SIZE];
		char flag;}
					m_first[MAX_IDENT];
	//b6:正在计算Fi0x40
	//b5-b3:正在计算Fo0x20,Fo以求解0x10,包含LR_EOF0x08
	//b2-b0:Fi已求解0x04,推出LR_NULL0x02,b1有效0x01
	char			token[2048];
	int				token_len;
	//token不止用来缓冲输入串,还被各个功能模块用做工作区
	//所以各功能模块不能同时进行
	char			bit_map[MAP_SIZE];
	//如果说token被各模块用做位图的话
	//bit_map则是一个小的位图
	FILE*			p_file;
};
inline const CStringArray& MLR1::GetIdentList(){
	return list_Ident;}
inline int MLR1::GetExpressNum(){
	return list_Express.GetSize();}
inline int MLR1::GetIdentNum(){
	return list_Ident.GetSize();}
#endif
//First集以空推导检测为前提
//Follow集以First集为前提

⌨️ 快捷键说明

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