编译原理期末试题(8套含答案)详解 - 百度文库 ر

3 ķEE+E|E*E|iľi*i+i*iIJͬ﷨Ϊ______

[A]1 [B]3 [C]5 [D]7 4Ԫʽ֮ϵͨ ʵ֡

[A]ʱ [B]ָʾ [C]ű [D] 5ͬļϲܻ³ͻΪ

[A] [B]ƽ/ƽ [C]ƽ/Լ [D]Լ/Լ 6Żʱݵ

[A]﷨ [B]ʷ [C]ȼ۱任 [D]

7ʽa-(-b)*c沨ʾΪ

[A]a-b@c* [B]ab@c*- [C]ab@- [D]ab@c-* ע@Ϊ

Ŀ

8̵DISPLAY¼

[A]̵ [B]̵Ƕײ [C]̵ķصַ [D]̵ڵַ

3ķG1G2L(G1)=L(G2) G1G2ͬķG1G2ǵȼ۵ġ

4ķG[E]ET|E+T TF|T*F FP^F|P P(E)|iT+T*F+iľT ض T*F 5Ƶ̳Ϊ淶Լ ҲΪ Լ

6淶ԼеĿɹԼǾ ȷеĿɹԼ ض 7A BģC ?D E 沨ʽǣ¡ţã?šġšġ 8ķķŵԷֱΪ̳ ۺԣɻ 9űÿһ ַ ĿɡĿɽ׶Σű ַ ݡ

10һ̵DISPLAY ֱ DISPLAYݼϱ̵SPĵַ

ԶMĸ?{0,1}Ĵÿ10ֱӸұߡһСDFA MMȼ۵ʽ

33ҳ6ҳ

֤ʽ(ab)*a ʽa(ba)*ȼ ùǵСDFA

дһķʹǣ

L { 1n0m1m0n | m,n0 }

ķGS 1S0 | A

A 0A1 |

ķG[S]

S aSb | P

P bPc | bQc

34ҳ6ҳ

Q Qa | a

(1) Ƿķ빹ȹϵ

(2) ķG[S]ݹ顢ȡӺǷLL1ķ

֤ʵ

1.G[S]FIRSTVTLASTVT

FIERSTVTS={a,b} LASTBVTS={b,c}

FIERSTVT(P)={b} LASTBVTP={c} FIERSTVT(Q)={a} LASTBVTQ={a} ȹϵΪ

a b c a b c < > < < > > > > ȹϵͬʱaaԼbbԸķķ

2. ݹȡӺķΪ

S aSb | P P bP P Pc |Qc Q aQ Q aQ|

ͬ󲿵ʽSelectĽ

Select(SaSb)Select(SP) = {a}First(P) = {a}{b} =

Select(PPc)Select(PQc) = First(P)First(Q)={b}{a}= Select(QaQ)Select(Q) = {a}Follow(Q) = {a}{c} = ޸ĺķLL1ķ

֪ķGΪ:

0 S S 1 S aAd 2 S bAc 3 S aec 4 S bed 5 A e

ԹLR1Ŀɹǰ׺ͼLR1 𰸣 S I1SS , I0: # S S , d # a A I4SaA d , I8SaAd , I2 S aAd , # Sa Ad , # # Sa ec , # e I5Sae c , c I , 9Saec SA e , d # # bAc , Ae , d # I10 b S aec , I3: Sb Ac , A SbAc , 35ҳ6ҳ I6: SbAc,# c # Sb ed , # # e I7Sbe d ,

LR(1) £

action goto ״̬ a b c d e # S A S2 S3 0 1

1 ac

c S5 2 S7 3

S8 4

S9 r5 5

S10 6

r5 S11 7

r1 8

r3 9

r2 10 r4 11 ֪Դ£ prod:=0; i:=1;

while i20 do begin

prod:=prod+a[i]*b[i]; i:=i+1

end;

԰﷨Ƶ뷨ԴԪʽУAaʼַBbʼַֽڱַÿԪռĸֽڣ 𰸣

36ҳ6ҳ