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

  • 大小: 14KB
    文件類型: .zip
    金幣: 2
    下載: 2 次
    發(fā)布日期: 2021-08-10
  • 語言: C/C++
  • 標(biāo)簽: 編譯原理??代碼??

資源簡(jiǎn)介

編譯原理語法分析器,使用遞歸下下降的分析方法

資源截圖

代碼片段和文件信息

#include
#include
#define?KEY_NUM?33
/*聲明*/
void?lrparser();
void?block();?
void?yucu();
void?statement();
void?assignment();
void?ifStatement();
void?whileStatement();
void?condition();
void?expression();
void?term();
void?factor();
void?oper();

char?prog[80]token[32]str[100];
char?ch;
int?synpindexsumconst_numkkrow;
FILE?*fp_in*fp_out;
char?*keyWord[KEY_NUM]={“auto““break““case““char““const“
“continue““default““do““double““else“
“enum““extern““float““for““goto“
“if““int““l(fā)ong““register““return“
“short““signed““sizeof““static““struct“
“switch““typedef““union““unsigned““void“
“volatile““while““main“};
char?*constant[100];
int?constValue[100];

/*****************************************************
文件操作?
*****************************************************/
/*打開文件*/
void?fileOpen(char?fileInput[]char?fileOuput[])
{
if((fp_in=fopen(fileInput“r“))==NULL)
{
printf(“打開讀取文件失敗!\n“);
return;
}
if((fp_out=fopen(fileOuput“w“))==NULL)
{
printf(“打開寫入文件出錯(cuò)!\n“);
return;
}
}
/*關(guān)閉文件*/
void?fileClose()
{
if(fp_in!=NULL)
fclose(fp_in);
if(fp_out!=NULL)
fclose(fp_out);
}
/*輸出文件*/
void?output(int?achar?tk[])
{
printf(“(%d%s)\n“atk);
fprintf(fp_out“(%d%s)\n“atk);
}
/*****************************************************
詞法分析
*****************************************************/
/*錯(cuò)誤處理*/
void?error(char?msg[])
{
printf(“%s\n“msg);
return;
}
/*讀取一個(gè)字符*/
void?getch()
{
ch=fgetc(fp_in);
}?
/*讀取空格*/
void?getbc()
{
while(ch==‘?‘?||?ch==‘\r‘?||?ch==‘\t‘?||?ch==‘\n‘)
{
if(ch==‘\n‘)
{
row++;
}
getch();
}
}
/*讀取回車*/
void?geten()
{
while(ch==‘\r‘)
getch();
}
/*讀取tab*/
void?gettab()
{
while(ch==‘\t‘)
getch();
}
/*讀取行*/
void?getline()
{
while(ch==‘\n‘)
getch();
}
/*換行*/
void?nextline()
{
while(ch!=‘\n‘)
getch();
}
/*連接字符串*/
void?concat()
{
int?len;
/*if(syn==35)
{
len=strlen(str);
str[len]=ch;
str[len+1]=‘\0‘;
}*/

len=strlen(token);
token[len]=ch;
token[len+1]=‘\0‘;
?
}
/*判斷是否為字母*/
bool?letter(char?c)
{
if((c>=‘a(chǎn)‘&&c<=‘z‘)||(c>=‘A‘&&c<=‘Z‘))
return?true;
if(c==‘_‘)
return?true;?
return?false;
}
/*判斷是否數(shù)字*/
bool?digit(char?c)
{
if(c>=‘0‘&&c<=‘9‘)
return?true;
return?false;
}
/*判斷是否關(guān)鍵字*/
int?reserve()
{
int?i;
for(i=0;i {
if(strcmp(tokenkeyWord[i])==0)
return?(i+100);
}
return?(10);
}
/*指針回退*/
void?retract()
{
fseek(fp_in-1SEEK_CUR);
}

/*十進(jìn)制轉(zhuǎn)二進(jìn)制*/

/*掃描*/
void?scaner()
{
//printf(“%d\n“syn);
memset(token0sizeof(token));
memset(str0sizeof(str));
getch();
getbc();
if(letter(ch))
{
while(letter(ch)||digit(ch))
{
concat();
getch();
}
retract();
syn=reserve();
//output(syntoken);
}
else?if(digit(ch))
{
while(digit(ch))
{
concat();
getch();
if

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2011-06-01?22:27??語法分析器\
?????文件???????????0??2011-05-12?20:52??語法分析器\out.txt
?????文件?????????128??2011-04-20?18:09??語法分析器\test.txt
?????文件??????????97??2011-04-20?17:51??語法分析器\程序說明.txt
?????文件????????9776??2011-04-20?17:02??語法分析器\語法分析器.cpp
?????文件???????32278??2011-04-20?17:10??語法分析器\語法分析器.exe

評(píng)論

共有 條評(píng)論