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

📄 lexer.h

📁 用MFC写的RPG游戏
💻 H
字号:
//
// 词汇分析的部分
//
//	Copyright (c) 2000-2001 Chihiro.SAKAMOTO (HyperWorks)
//

#ifndef	__lexer_h__
#define	__lexer_h__

//
// 储存分析结果的结构体
//
struct LexValue	{
	string value;
	int type;
} ;

//
// Lexer类别
//
class Lexer	{
  public:
	// 记号种类
	enum	{
		IsNumber,
		IsString,
		IsDelimitter,
		IsLabel,
		IsMinus,
	} ;

  private:
	enum	{
		IsSpace = IsMinus + 1,
		IsTerminater,
		IsQuotation,
	} ;

  public:
	Lexer(const char *str);

	int NumToken() const { return nToken; }
	void NextToken() { Count++; }

	const char *GetString(int index=-1);
	bool GetValue(int *value, int index=-1);
	int GetType(int index=-1);

  protected:
	const char *SkipSpace(const char *p);
	int CharType(unsigned char ch);
	bool MatchType(int &type, unsigned char ch);

  protected:
	int			nToken;
	vector<LexValue> Value;
	int			Count;
} ;

// inline成员函数

inline const char *Lexer::GetString(int index)
{
	if (index >= 0)
		Count = index;
	if (Count >= nToken)
		return NULL;
	return Value[Count++].value.c_str();
}

inline int	Lexer::GetType(int index)
{
	if (index >= 0)
		Count = index;
	if (Count >= nToken)
		return -1;
	return Value[Count].type;
}

#endif

⌨️ 快捷键说明

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