資源簡介
C語言編寫的一個詞法分析器,功能不復雜,主要是狀態圖實現詞法分析的思想。
代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
char?ch=NULL;?//存放最新讀進源程序的字符
char?strToken[120];?//存放構成單詞符號的字符串
char?*keyword[]={“dim““if““do““stop““end“};//關鍵字表
FILE?*?fp=NULL;?//輸入
FILE?*?fw=NULL;?//輸出
typedef?struct
{
char?*I[120];?//標識符數組
int?lenth;?//標識符數量
}?identified;?
typedef?struct?{
char?*cont[120];//存放常數的數組
int?lenth;//常數的數目
}?constnum;
//讀字符到ch中
void?getChar(FILE?*ifp)
{
if((ch=getc(ifp))==EOF)
exit(1);
}
//檢查ch中的字符是否為空白,若是,則調用getChar()讀取下一個字符,直到非空
void?getBC(FILE?*ifp)
{
while(ch==‘?‘||?ch==‘\n‘)
{
getChar(ifp);
}
}
//連接strToken和ch
void?conCat()
{
char?*?ct=&ch;
strcat(strTokenct);?//strcat函數,包括在中
}
//判斷是否為字母。
int?isLetter()
{
return?isalph
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????98816??2012-05-14?15:59??詞法分析器\編譯原理實驗1.doc
?????文件???????31232??2012-05-11?11:35??詞法分析器\LEX.exe
?????文件????????3685??2012-05-11?11:23??詞法分析器\lex.c
?????目錄???????????0??2012-05-11?11:36??詞法分析器\
評論
共有 條評論