编译原理实验二;语法分析Word文件下载.doc

上传人:b****1 文档编号:13191413 上传时间:2022-10-08 格式:DOC 页数:18 大小:551.50KB
下载 相关 举报
编译原理实验二;语法分析Word文件下载.doc_第1页
第1页 / 共18页
编译原理实验二;语法分析Word文件下载.doc_第2页
第2页 / 共18页
编译原理实验二;语法分析Word文件下载.doc_第3页
第3页 / 共18页
编译原理实验二;语法分析Word文件下载.doc_第4页
第4页 / 共18页
编译原理实验二;语法分析Word文件下载.doc_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

编译原理实验二;语法分析Word文件下载.doc

《编译原理实验二;语法分析Word文件下载.doc》由会员分享,可在线阅读,更多相关《编译原理实验二;语法分析Word文件下载.doc(18页珍藏版)》请在冰豆网上搜索。

编译原理实验二;语法分析Word文件下载.doc

block>

<

const-decl>

<

var-decl>

proc-decl>

statement>

<

=const<

const-assignment-list>

;

ident>

=<

number>

|<

<

=var<

ident-list>

|<

procedure<

expression>

|call<

id>

|begin<

statement-list>

end

|if<

condition>

then<

|while<

do<

=odd<

relation>

==|<

>

|>

=|>

=

term>

adding-operator>

=+|-

factor>

multiplying-operator>

=*|/

|(<

18

文法缩略版:

P->

S

S->

BD

B->

varH;

H->

id|H,id

D->

i=E|call(k)|if(k)DelseD|while(K)doD

K->

ERE

R->

|>

=|<

|==

E->

EOT|T

T->

TQF|F

O->

+|-

Q->

*|/

F->

id|nunber|(E)

programe>

=P

black>

=S

=B

=H

=D

=K

=E

=T

=F

实验环境:

windowsmicrosoftvisualc++

实验原理:

构造项集

Setofltemsclosure(I)

{

repeatforeachA®

a.Bb,ainJandeachprodutcion

gofGsuchthatB®

.g,eachoffirst(ba)isnotinJ:

ADDB®

.g,btoI

until…nomoreitemscanbeaddedtoI

returnI

}

Setofltemsgoto(I,X):

{

IfIisasetofLR

(1)itemsandXisagrammarsymbol(terminalornon-terminal),thengoto(I,X)isdefinedasfollows:

IfA.X,ainI

theneveryiteminclosure({AX.,a})willbeingoto(I,X).

Voiditems()

Cis{closure({S’®

.S,$})}

repeatthefollowingsuntilnomoresetofLR

(1)itemscanbeaddedtoC.

foreachIinCandeachgrammarsymbolX

ifgoto(I,X)isnotemptyandnotinC

addgoto(I,X)toC

简略分析表:

1

2

3

4

5

6

7

8

9

10

11

12

20

21

22

23

24

25

id

num

call

if

else

while

do

*

@

D

H

K

E

T

F

 

r4

acc

S5

S6

S7

S8

S20

S21

S22

17

19

S23

13

30

34

14

15

S16

16

r7

r12

S39

r15

r16

r17

.. 

 ..

 .

38

r13

39

42

40

S41

41

r18

r14

31

43

实验流程图:

实验结果:

输入:

输出:

输入的字符串以结束@

bi,i,i;

f(i>

i)i=n*n+new(i>

n)di=i+i@

栈符号输入动作

0bi,i,i;

n)di=i+i@移入

03bi,i,i;

0310bi,i,i;

n)di=i+i@根据H->

i规约

039bH,i,i;

03915bH,i,i;

0391516bH,i,i;

H,i规约

039bH,i;

03915bH,i;

0391516bH,i;

039bH;

0392

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

当前位置:首页 > PPT模板 > 动物植物

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

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