91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡(jiǎn)介

非常基礎(chǔ)的詞法分析器,能夠?qū)⒏鱾€(gè)單詞分開,判斷各個(gè)單詞的類型,并輸出相應(yīng)的tokens和符號(hào)表。還存在一些BUG,希望大家不吝賜教。

資源截圖

代碼片段和文件信息

#include“fileIO.h“
#include“table.h“
using?namespace?std;
int?typeCodetokenNumlength;?????????//分別表示種別碼,當(dāng)前單詞中的字符位置的下一位以及代碼長度
int?presentChar=0row=1;???????//分別表示當(dāng)前讀取到的文件的字符的下一位,讀取代碼當(dāng)前行數(shù)
char?token[15];????????????????//表示當(dāng)前讀取的單詞
char?ch;???????????????????????//表示當(dāng)前讀取的字符
char*?keywords[13]={“int““float““double““char““string““while““if““else““for““return““break““switch““case“};
char?str[50];??????????????????//專門用于保存字符串或者字符
tokenTable?table[200];
void?analyzer(string?code)
{
for(int?i=0;i<15;i++)
token[i]=NULL;
ch=code[presentChar++];
while(ch==‘?‘||ch==‘\t‘)
{???????//過濾空格符和制表符
if(presentChar==length)
{????
typeCode=0;?????????????//typeCode=0來表示代碼已到末尾
return;???????????????????//跳出函數(shù)
}
ch=code[presentChar++];
}
tokenNum=0;
if(ch>=‘a(chǎn)‘&&ch<=‘z‘){????????????//判斷是否是關(guān)鍵字,否則為標(biāo)識(shí)符
while((ch>=‘a(chǎn)‘&&ch<=‘z‘)||(ch>=‘0‘&&ch<=‘9‘)||(ch>=‘A‘&&ch<=‘Z‘)||ch==‘_‘)
{
token[tokenNum++]=ch;
ch=code[presentChar++];
}
token[tokenNum]=‘\0‘;
presentChar--;????????????????????????//計(jì)算完一個(gè)token后,presentChar會(huì)指向空格符的下一個(gè)符號(hào),所以必須減一
typeCode=IDENTIFIER;
for(int?i=0;i<13;i++){
if(!strcmp(tokenkeywords[i])){
typeCode=i+1;
break;
}
}
}
else?if((ch>=‘A‘&&ch<=‘Z‘)||ch==‘_‘||ch<0)
{??????????//上一個(gè)if已經(jīng)包含了a到z開頭的標(biāo)識(shí)符,進(jìn)入這個(gè)if的也都是標(biāo)識(shí)符
while((ch>=‘a(chǎn)‘&&ch<=‘z‘)||(ch>=‘A‘&&ch<=‘Z‘)||(ch>=‘0‘&&ch<=‘9‘)||ch==‘_‘||ch<0)
{
if(ch<0)
{
token[tokenNum++]=ch;
token[tokenNum++]=code[presentChar++];
}
else
token[tokenNum++]=ch;
ch=code[presentChar++];
}
token[tokenNum++]=‘\0‘;
presentChar--;????????????????????????????//計(jì)算完一個(gè)token后,presentChar會(huì)指向空格符的下一個(gè)符號(hào),所以必須減一
typeCode=IDENTIFIER;
}
else?if(ch>=‘0‘&&ch<=‘9‘)
{
while((ch>=‘0‘&&ch<=‘9‘)||ch==‘.‘)
{
token[tokenNum++]=ch;
ch=code[presentChar++];
}
token[tokenNum++]=‘\0‘;
presentChar--;????????????????????????????//計(jì)算完一個(gè)token后,presentChar會(huì)指向空格符的下一個(gè)符號(hào),所以必須減一
typeCode=NUMBER;
}
else?switch(ch)
{
case?‘+‘:
typeCode=ADD;token[tokenNum++]=ch;
ch=code[presentChar];
if(ch==‘+‘)
{
token[tokenNum]=ch;
typeCode=DADD;
presentChar++;
}
break;
case?‘-‘:
typeCode=SUB;token[tokenNum++]=ch;
ch=code[presentChar];
if(ch==‘-‘)
{
token[tokenNum]=ch;
typeCode=DSUB;
presentChar++;
}
break;
case?‘*‘:typeCode=MUL;token[0]=ch;break;
case?‘/‘:typeCode=DIV;token[0]=ch;break;
case?‘%‘:typeCode=MOD;token[0]=ch;break;
????case?‘=‘:
typeCode=ASSIGN;token[tokenNum++]=ch;
ch=code[presentChar];
if(ch==‘=‘)
{
token[tokenNum]=ch;
typeCode=EQUAL;
presentChar++;
}
break;
case?‘!‘:
typeCode=EXC;token[tokenNum++]=ch;
ch=code[presentChar];
if(ch==‘=‘)
{
token[tokenNum]=ch;
typeCode=NEQ;
presentChar++;
}
break;
case?‘>‘:
typeCode=MORETHAN;token[tokenNum++]=ch;
ch=code[presentChar];
if(ch==‘=‘)
{
token[tokenNum]=ch;
typeCode=MOE;
presentC

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----

?????文件????????602??2013-04-12?17:15??lee\Debug\cl.command.1.tlog

?????文件??????23052??2013-04-12?17:15??lee\Debug\CL.read.1.tlog

?????文件????????264??2013-04-12?17:15??lee\Debug\CL.write.1.tlog

?????文件????????406??2013-03-02?13:04??lee\Debug\lee.exe.embed.manifest

?????文件????????472??2013-03-02?13:04??lee\Debug\lee.exe.embed.manifest.res

?????文件????????381??2013-04-12?17:15??lee\Debug\lee.exe.intermediate.manifest

?????文件?????????52??2013-04-12?17:15??lee\Debug\lee.lastbuildstate

?????文件???????1998??2013-04-12?17:15??lee\Debug\lee.log

?????文件????????196??2013-03-02?12:54??lee\Debug\lee_manifest.rc

?????文件??????????2??2013-04-12?17:15??lee\Debug\link-cvtres.read.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link-cvtres.write.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.10020-cvtres.read.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.10020-cvtres.write.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.10020.read.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.10020.write.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.10252-cvtres.read.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.10252-cvtres.write.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.10252.read.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.10252.write.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.11924-cvtres.read.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.11924-cvtres.write.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.11924.read.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.11924.write.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.13988-cvtres.read.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.13988-cvtres.write.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.13988.read.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.13988.write.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.14432-cvtres.read.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.14432-cvtres.write.1.tlog

?????文件??????????2??2013-04-12?17:15??lee\Debug\link.14432.read.1.tlog

............此處省略218個(gè)文件信息

評(píng)論

共有 條評(píng)論