LL1语法分析c++实现first集follow集分析表分析栈Word格式文档下载.docx

上传人:b****3 文档编号:15857246 上传时间:2022-11-16 格式:DOCX 页数:29 大小:19.29KB
下载 相关 举报
LL1语法分析c++实现first集follow集分析表分析栈Word格式文档下载.docx_第1页
第1页 / 共29页
LL1语法分析c++实现first集follow集分析表分析栈Word格式文档下载.docx_第2页
第2页 / 共29页
LL1语法分析c++实现first集follow集分析表分析栈Word格式文档下载.docx_第3页
第3页 / 共29页
LL1语法分析c++实现first集follow集分析表分析栈Word格式文档下载.docx_第4页
第4页 / 共29页
LL1语法分析c++实现first集follow集分析表分析栈Word格式文档下载.docx_第5页
第5页 / 共29页
点击查看更多>>
下载资源
资源描述

LL1语法分析c++实现first集follow集分析表分析栈Word格式文档下载.docx

《LL1语法分析c++实现first集follow集分析表分析栈Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《LL1语法分析c++实现first集follow集分析表分析栈Word格式文档下载.docx(29页珍藏版)》请在冰豆网上搜索。

LL1语法分析c++实现first集follow集分析表分析栈Word格式文档下载.docx

charVn[MaxVnNum+1];

/*非终结符集*/

intvnNum;

charVt[MaxVtNum+1];

/*终结符集*/

intvtNum;

structpNodeP[MaxRuleNum];

intPNum;

charbuffer[MaxPLength+1];

charch;

charst[MaxStLength];

/*要分析的符号串*/

structcollectNode

intnVt;

structcollectNode*next;

structcollectNode*first[MaxVnNum+1];

/*first集*/

structcollectNode*follow[MaxVnNum+1];

/*follow集*/

intanalyseTable[MaxVnNum+1][MaxVtNum+1+1];

intanalyseStack[MaxStackDepth+1];

/*分析栈*/

inttopAnalyse;

/*分析栈顶*/

voidInit();

/*初始化*/

intIndexCh(charch);

voidInputVt();

/*输入终结符*/

voidInputVn();

/*输入非终结符*/

voidShowChArray(char*collect,intnum);

/*输出Vn或Vt的内容*/

voidInputP();

/*产生式输入*/

boolCheckP(char*st);

/*判断产生式正确性*/

voidFirst(intU);

voidAddFirst(intU,intnCh);

/*加入first集*/

boolHaveEmpty(intnVn);

voidFollow(intV);

/*计算follow集*/

voidAddFollow(intV,intnCh,intkind);

voidShowCollect(structcollectNode**collect);

/*输出first或follow集*/

voidFirstFollow();

/*计算first和follow*/

voidCreateAT();

/*构造预测分析表*/

voidShowAT();

/*输出分析表*/

voidIdentify(char*st);

voidInitStack();

voidShowStack();

voidPop();

voidPush(intr);

intmain()

chartodo,ch;

Init();

InputVn();

InputVt();

InputP();

getchar();

FirstFollow();

printf("

所得first集为:

"

);

ShowCollect(first);

所得follow集为:

ShowCollect(follow);

CreateAT();

ShowAT();

todo='

y'

;

while('

==todo)

{

\n是否继续进行句型分析?

(y/n):

todo=getchar();

!

=todo&

&

'

n'

=todo)

\n(y/n)?

"

}

if('

inti;

InitStack();

请输入符号串(以#结束):

ch=getchar();

i=0;

#'

=ch&

i<

MaxStLength)

\n'

=ch)

st[i++]=ch;

==ch&

st[i]=ch;

Identify(st);

else

输入出错!

\n"

}

voidInit()

inti,j;

vnNum=0;

vtNum=0;

PNum=0;

for(i=0;

=MaxVnNum;

i++)

Vn[i]='

\0'

=MaxVtNum;

Vt[i]='

MaxRuleNum;

P[i].lCursor=NULL;

P[i].rHead=NULL;

P[i].rLength=0;

=MaxPLength;

buffer[i]='

MaxVnNum;

first[i]=NULL;

follow[i]=NULL;

for(j=0;

j<

=MaxVnNum+1;

j++)

analyseTable[i][j]=-1;

intIndexCh(charch)

intn;

n=0;

/*isVn?

*/

while(ch!

=Vn[n]&

=Vn[n])

n++;

return100+n;

/*isVt?

=Vt[n]&

=Vt[n])

returnn;

return-1;

voidShowChArray(char*collect)

intk=0;

=collect[k])

%c"

collect[k++]);

voidInputVn()

intinErr=1;

intn,k;

charch;

while(inErr)

\n请输入所有的非终结符,注意:

请将开始符放在第一位,并以#号结束:

ch='

/*初始化数组*/

while(n<

MaxVnNum)

Vn[n++]='

while(('

=ch)&

(n<

MaxVnNum))

-1==IndexCh(ch))

Vn[n++]=ch;

vnNum++;

Vn[n]='

/*以“#”标志结束用于判断长度是否合法*/

k=n;

if('

=(ch=getchar()))

;

\n符号数目超过限制!

inErr=1;

continue;

/*正确性确认,正确则,执行下下面,否则重新输入*/

Vn[k]='

ShowChArray(Vn);

输入正确确认?

(y/n):

scanf("

%c"

&

ch);

==ch)

录入错误重新输入!

else

inErr=0;

/*输入终结符*/

voidInputVt()

\n请输入所有的终结符,注意:

以#号结束:

MaxVtNum)

Vt[n++]='

MaxVtNum))

Vt[n++]=ch;

vtNum++;

Vt[n]='

Vt[k]='

ShowChArray(Vt);

voidInputP()

inti=0,n,num;

prin

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 其它模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1