编译原理课后习题答案(第三版)

精品文档

第二章

P36-6

(1)

L(G1)是0~9组成的数字串

(2)

最左推导:

N?ND?NDD?NDDD?DDDD?0DDD?01DD?012D?0127N?ND?DD?3D?34N?ND?NDD?DDD?5DD?56D?568

最右推导:

N?ND?N7?ND7?N27?ND27?N127?D127?0127N?ND?N4?D4?34N?ND?N8?ND8?N68?D68?568

P36-7

G(S)

O?1|3|5|7|9N?2|4|6|8|OD?0|NS?O|AOA?AD|N

P36-8

文法:

E?T|E?T|E?TT?F|T*F|T/F F?(E)|i最左推导:

E?E?T?T?T?F?T?i?T?i?T*F?i?F*F?i?i*F?i?i*iE?T?T*F?F*F?i*F?i*(E)?i*(E?T)?i*(T?T)?i*(F?T)?i*(i?T)?i*(i?F)?i*(i?i)最右推导:

E?E?T?E?T*F?E?T*i?E?F*i?E?i*i?T?i*i?F?i*i?i?i*iE?T?F*T?F*F?F*(E)?F*(E?T)?F*(E?F)?F*(E?i)?F*(T?i)?F*(F?i)?F*(i?i)?i*(i?i)语法树:/********************************

.

EE+TE+TFTFiFiii+i+i*****************/

P36-9

句子iiiei有两个语法树:

SS??iSeSiS??iiSeSiSei??iiSeiiiSei??iiieiiiiei

P36-10

/**************

S?TS|TT?(S)|( )

***************/

P36-11

/*************** L1:

S?ACA?aAb|ab C?cC|?L2:

S?ABA?aA|?

B?bBc|bcL3:

.

EE+TTT*FFFiiii-i-i精品文档

EE-TE-TFTFiFiii+i*i

精品文档

S?ABA?aAb|? B?aBb|?L4:

S?A|BA?0A1|? B?1B0|A***************/

第三章习题参考答案

P64–7

(1)

* 1(01|)101 X Y

0

1 ? ? 1 0 1 X 1 2 3 4 5

1 确定化:

{X} φ {1,2,3} {2,3} {2,3,4} {2,3,5} {2,3,4,Y} 0 φ φ {2,3} {2,3} {2,3,5} {2,3} {2,3,5} 1 {1,2,3} φ {2,3,4} {2,3,4} {2,3,4} Y {2,3,4,Y} {2,3,4,}

0

1 0 0 2 3

0 0 1 1 0 0 1 1 4 5 6 0 1 1 1 最小化:

.

精品文档

{0,1,2,3,4,5},{6}{0,1,2,3,4,5}0?{1,3,5} {0,1,2,3,4,5}1?{1,2,4,6}{0,1,2,3,4},{5},{6}{0,1,2,3,4}?{1,3,5}0{0,1,2,3},{4},{5},{6} {0,1,2,3}0?{1,3} {0,1,2,3}1?{1,2,4}{0,1},{2,3}{4},{5},{6}{0,1}?{1} {0,1}?{1,2}01{2,3}0?{3} {2,3}1?{4}{0},{1},{2,3},{4},{5},{6} 0

1 2 0

0 0 1 0 0 1 1 3 4 5 0 1 1 1

P64–8

(1)

(1|0)*01

(2)

(1|2|3|4|5|6|7|8|9)(0|1|2|3|4|5|6|7|8|9)*(0|5)|(0|5)

(3)

0*1(0|10*1)*|1*0(0|10*1)*

P64–12

(a)

a

a,b 0 a

确定化:

{0} {0,1} {1} .

1 a {0,1} {0,1} {0} b {1} {1} φ 精品文档

φ 给状态编号:

0 1 2 3 φ φ a 1 1 0 3 b 2 2 3 3

a

a 0 1

a b b b

b 2 3

a

最小化:

{0,1},{2,3}{0,1}?{1} {0,1}?{2}ab{2,3}?{0,3} {2,3}?{3}

ab{0,1},{2},{3}

a a

b b 1 2 0 a b (b)

b b a 2 3 0

a b a a b b a 4 5 1 a a

已经确定化了,进行最小化

.

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4