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

資源簡介

遞歸下降語法分析程序要求: 忽略注釋; 有出錯恢復(fù)處理功能; 顯示錯誤格式“第xx行出現(xiàn)xxx錯誤”

資源截圖

代碼片段和文件信息

#include?
#include?
#include?
#include?
#define?_KEY_WORDEND?“waiting?for?your?expanding“

using?namespace?std;

typedef?struct?//詞的結(jié)構(gòu),二元組形式(單詞種別,單詞自身的值)
{
int?typenum;?//單詞種別
char?*?word;
}WORD;

WORD*?oneword?=?new?WORD;
char?input[255];
char?token[255]?=?““;
int?p_input;?//指針
int?p_token;
int?kk;//標(biāo)記是否已經(jīng)出錯,如果整個程序判斷到最后沒有出錯,輸出Success
int?flag=0;//標(biāo)記括號數(shù)目,falg=0左右括號匹配,flag>0左括號多了,flag<0右括號多了
bool?print_flag=true;//標(biāo)志是否已經(jīng)檢測出缺少右括號的錯誤
int?row=1;//定義行數(shù),每次讀取一個回車則為換行
int?error_row?=?0;//標(biāo)志總共幾個錯誤
char?ch;
char?*?rwtab[]?=?{?“begin““if““then““while““do““end““int““main““else““float““double““return““cout“_KEY_WORDEND?};


WORD?*?scanner();//掃描獲取到每個單詞的種別碼
int?Irparser();//程序的判斷
int?yucu();//語句串的分析
int?statement();//語句的分析
int?expression();//表達(dá)式的判斷
int?term();//項的分析
int?factor();//因子的分析
char?m_getch();

int?main()
{
????//以“#”結(jié)束
????p_input=0;
????printf(“---語法分析程序開始---\n“);
????printf(“讀取到的源程序如下:\n“);
????/*do
????{
????????scanf(“%c“&ch);
????????input[p_input++]=ch;
????}while(ch!=‘#‘);*/

????FILE?*fp=NULL;
????fp?=?fopen(“error_data.txt““r“);
????if(fp?==?NULL)
????{
????????printf(“Not?found?file!“);
????????return?0;
????}
????while((input[p_input]=getc(fp))!=EOF)
????{
????????putchar(input[p_input]);
????????p_input++;
????}

????printf(“\n“);

????p_input=0;
????kk=0;
????oneword?=?scanner();
????Irparser();
????printf(“\n“);
????printf(“===以上是程序分析結(jié)果===\n“);
????printf(“總共%d行,其中有%d個錯誤\n“rowerror_row);//輸出行數(shù)以及錯誤個數(shù)
????printf(“========================\n“);
????printf(“---語法分析程序結(jié)束---\n“);
????return?0;
}

//從輸入緩沖區(qū)讀取一個字符到ch中
char?m_getch()
{
ch?=?input[p_input];
p_input++;
return?ch;
}

//去掉空白符號,不包括回車
void?getbc()
{
while?(ch?==?‘?‘)
{
ch?=?input[p_input];
p_input++;
}
}

//拼接單詞
void?concat()
{
token[p_token]?=?ch;
p_token++;
token[p_token]?=?‘\0‘;
}

//判斷是否字母
int?letter()
{
if?(ch?>=?‘a(chǎn)‘&&ch?<=?‘z‘?||?ch?>=?‘A‘&&ch?<=?‘Z‘)
return?1;
else
return?0;
}

//判斷是否數(shù)字
int?digit()
{
if?(ch?>=?‘0‘&&ch?<=?‘9‘)
return?1;
else
return?0;
}

//檢索關(guān)鍵字表格
int?reserve()
{
int?i?=?0;
while(strcmp(rwtab[i]?_KEY_WORDEND))
{
if?(!strcmp(rwtab[i]?token))
return?i?+?1;
i++;
}
return?10;//如果不是關(guān)鍵字,則返回種別碼10
}

//回退一個字符
void?retract()
{
p_input--;
}

//詞法掃描程序
WORD?*?scanner()
{
WORD?*?myword?=?new?WORD;
myword->typenum?=?10;??//初始值
myword->word?=?““;
p_token?=?0;???//單詞緩沖區(qū)指針
m_getch();
getbc();//去掉空白

if?(letter())//判斷讀取到的首字母是字母
{
????????//如int
while?(letter()?||?digit())
{
concat();?//連接
m_getch();
}
retract();?//回退一個字符
myword->typenum?=?reserve();//判斷是否為關(guān)鍵字,返回種別碼
myword->word?=?token;
return?myword;
}
else?if?(digit())??//判斷讀取到的單詞首字符是數(shù)字
{
while?(digit())?//所有數(shù)字連接起來
{
concat();
m_getch();
}
retract();
//數(shù)字單詞種別碼統(tǒng)一為20,單詞自身的值為數(shù)字本身
myword->typenum?=?20;
myword->word?=?tok

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件??????16039??2018-05-10?22:58??遞歸下降語法分析程序(代碼+說明文檔)\main.cpp

?????文件??????84978??2018-07-10?14:58??遞歸下降語法分析程序(代碼+說明文檔)\說明文檔.docx

?????目錄??????????0??2018-07-10?14:58??遞歸下降語法分析程序(代碼+說明文檔)

-----------?---------??----------?-----??----

???????????????101017????????????????????3


評論

共有 條評論