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

📄 morpheme.h

📁 这是用VC6.0开发的集词法分析、语法分析、语义分析为一体的一个程序
💻 H
字号:
/* Morpheme.h: interface for the Morpheme class.
 * 词法分析器
 * 
 * 作者:胡通海
 * superflea2002@126.com
 * 哈尔滨工业大学(威海)
 *
/////////////////////////////////////////////////////////////////////*/

#if !defined(AFX_CMORPHEME_H__2918462B_43EF_4F84_9B2E_C1926B368DD1__INCLUDED_)
#define AFX_CMORPHEME_H__2918462B_43EF_4F84_9B2E_C1926B368DD1__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
#include "CommStruct.h"

class CMorpheme  
{
public:
	CMorpheme(const char *pWordCode[],
			  PTokenNode pTokenFile,
			  PSTable pSymbolTable,
			  PErrorNode pErrorCollection);		
										//
	CMorpheme(const char *pWordCode[],
			  PTokenNode pTokenFile,
			  PSTable pSymbolTable,
			  PErrorNode pErrorCollection,
			  CString strSourceFile);	
										//多一个源文件路径

	virtual ~CMorpheme();

private:
	unsigned m_rowCount;				//行计数
	unsigned m_colsCount;				//列计数

	PSTable m_pSymbolTable;				//符号表头指针
	PTokenNode m_pTokenFile;			//token串头指针
	PErrorNode m_pErrorCollection;		//错误信息头指针
	PTokenNode m_rearToken;				//token串尾指针
	PErrorNode m_rearError;				//错误串尾指针
	const char *m_pWordCode[KEYWORDCOUNT+1];	
										//单词编码指针
    
	ifstream m_finSource;				//源程序文件流
	CString m_strSourceFile;			//源程序文件路径
	char m_strLine[MAXLINE];			//每行源文件缓存    
	bool m_bStepOn;						//单步词法分析开始

public:	
	bool StepMorpheme(PTokenNode &pToken,CString strSourceFile="");				
										//分步词法分析
	bool Morpheme(CString strSourceFile="");					
										//开始词法分析
	unsigned int GetCurRow();			//获取当前行
	unsigned int GetCurCol();			//获取当前列

	bool AddError(const char *description,unsigned int rows=0,unsigned int cols=0);
										//添加错误信息
	bool DeleteToken(PTokenNode pToken);
										//删除token字
	void CloseSource();					//关闭源文件

private:	
	bool Init();						//初始化:符号表,字符串表,token串表,行、列计数器
	bool OpenSource();					//打开源文件	

	int ReadLine();						//读取一行:-1:错误;0:文件完;1:成功
	char GetCharNoNULL();				//读取当前行中的一个非空字符:-1:文件完
	char GetChar();						//读取当前行中的一个字符:-1:当前行完;-2:空格
	void Sort(char ch);					//根据当前读入的字符进行分类;生成token串
	unsigned int LookUp(const char *word,::SType type);
										//查填符号表;返回入口地址	
	unsigned int IsKeyId(const char *str);		
										//是否是关键字
	unsigned int FindKeyId(const char *str);
										//查找关键字种别码
	bool AddError(unsigned int rows,unsigned int cols,const char *description);
										//添加错误信息
	bool AddToken(unsigned char keycode,unsigned int strId);
										//添加token文件
	bool RecogDel(char ch);				//识别界限符
	bool RecogDigit(char ch);			//识别数字常数
	bool RecogChar(char ch);			//识别字符常数
	bool HandleCom(char ch);			//识别注释
	bool RecogId(char ch);				//识别标识符;

	bool EnLageSTable(const char *str);	//扩大符号表空间

	void SaveAll();						//保存所需文件
	char *TypeToString(SType type);		//将type转换成字符串
	CString IntoStr(unsigned int num);   //将整形转换成字符串
};

#endif // !defined(AFX_MORPHEME_H__2918462B_43EF_4F84_9B2E_C1926B368DD1__INCLUDED_)

⌨️ 快捷键说明

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