?? morpheme.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 + -