试验二求文法中每个非终结符的FIRSTVT集Word格式文档下载.docx

上传人:b****7 文档编号:21892709 上传时间:2023-02-01 格式:DOCX 页数:8 大小:16.02KB
下载 相关 举报
试验二求文法中每个非终结符的FIRSTVT集Word格式文档下载.docx_第1页
第1页 / 共8页
试验二求文法中每个非终结符的FIRSTVT集Word格式文档下载.docx_第2页
第2页 / 共8页
试验二求文法中每个非终结符的FIRSTVT集Word格式文档下载.docx_第3页
第3页 / 共8页
试验二求文法中每个非终结符的FIRSTVT集Word格式文档下载.docx_第4页
第4页 / 共8页
试验二求文法中每个非终结符的FIRSTVT集Word格式文档下载.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

试验二求文法中每个非终结符的FIRSTVT集Word格式文档下载.docx

《试验二求文法中每个非终结符的FIRSTVT集Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《试验二求文法中每个非终结符的FIRSTVT集Word格式文档下载.docx(8页珍藏版)》请在冰豆网上搜索。

试验二求文法中每个非终结符的FIRSTVT集Word格式文档下载.docx

usingnamespacestd;

#defineMAX100structSTACK

intIeft;

intright;

};

intsearch(chart,char

iritnum)

inti;

for(i=0;

i<

num;

i++)

{

if(t==str[i])

returni;

}

return-1;

intmain()

char

wenfa[MAX][MAX];

//00

个长度为100的产生式charstr[MAX];

zhongjiefu[MAX];

feizhongjiefu[MAX];

chartemp[MAX];

inti,j,k;

int

flag1=0,flag2=0,fIag3

=0;

boolF[MAX][MAX];

STACKS[MAX];

inttop二T;

memset(F,faIse,sizeof(F));

cout«

"

请输入产生式,最后以end结束H«

endl;

whiIe(cin»

str&

&

strcmp(str,"

end"

))//只要str不等end,返回值就不为0:

strcmp(constchar*s1,constchar*s2);

说明:

当s1<

s2时,返回值<

0当s1=s2时,返回值二0当s1>

s2时,返回值>

strcpy(wenfa[fIag1++],str);

zhongjiefu[j])

if(wenfa[i][0]==fei

//求出

不重复的非终结符集和终结符集

for(i二0;

i<

fIag1;

i++)//取非终结符;

if(i==0)

feizhongjiefu[fIag2++]=wenfa[i][0];

//存法产生式的非终结符

1

eIse

for(j=0;

j<

flag2;

j++

break;

if(j==flag2)

feizhongjiefu[fIag2++]二wenfa[i][0];

for(i=0;

flag1;

i++

)//取终结符

intcount二0;

for(j-3;

st门en(wenfa[i]);

j++)

temp[count]二,\(T;

if(strcmp(temp,"

digit”)=0)

zhongjiefu[fIag3++]

rr

flag3;

j++)

if(zhongjiefu[j]=='

if(j二二flag3)

zhongjiefu[fIag3++]

V

strien(wenfa[i]);

if(j==3&

(wenfa[i][

j]>

,Z,||wenfa[i][j]<

'

A'

)&

flag3=0)

[i][j]>

Z‘||wenfa[i][jKA'

))

 

zhongjiefu[fIag3++]=wenfa[i][j];

for(k=0;

k<

fIag3;

k++

if(wenfa[i][j]=zhongjiefu[k])

zhongjiefu[fIag3++]=wenfa[i][j];

//开始

inta,b;

if(wenfa[i][3]>

Z'

|

}|wenfa[i][3]<

rA'

}{

intcount^O;

if(k=fIag3&

(wenfa

for(j二3;

st门en(wenfa[i]);

j++)

temp[count++]二wenfa

temp[count]二;

a二search(wenfa[i][0],feizhongjiefu,fIag2);

b=search('

zhongjiefu,fIag3);

F[a][b]二true;

top++;

S[top].Ieft二a;

S[top].right=b;

a=search(wenfa[i][0],feizhongjiefu,fIag2);

b=search(wenfa[i][3

],zhongjiefu,fIag3);

F[a][b]二true;

S[top].right=b;

intcount=0;

for(j=4;

st门en(wenfa[i]);

temp[count++]=wenfa

temp[count]二,\0,;

if(strcmp(temp,"

))//避免后续所指单词没有内容。

a=search(wenfa[i][0],feizhongjiefu,fIag2);

b二search('

top++;

if(wenfa[i][4]>

Z'

|wenfa[i][4]<

dig

it”)=0)

a=search(wenfa[i][0

],feizhongjiefu,fIag2);

b二search(wenfa[i][4],zhongjiefu,fIag3);

S[top],left=a;

S[top].right=b;

while(top!

=-1)

charB,a;

int;

op].left];

a二zhongjiefu[S[top]

・right];

11=S[top].right;

i++)

intt;

t二search(wenfa[i][0],feizhongjiefu,fIag2);

if(wenfa[订[3]=B&

B!

=wenfa[i][0]&

F[t][

t1]—false)

F[t][t1]=true;

B二feizhongjiefu[S[t

S[top].Ieft=t;

if(zhongjiefu[j]~

S[top].right=t1;

top__;

fIag2;

,FIRSTVT(,,«

feizhongjiefu[i]«

)={n

flag3-1;

j++)

*)

digit,”;

zhongjiefu[j]

«

n,n;

if(zhongjiefu[j]—'

*)

cout〈〈"

digit”;

if(F[i][j]二二true)

}"

endI«

endI«

endI;

return0;

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

当前位置:首页 > 人文社科 > 文化宗教

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

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