编译原理(紫龙书)中文第2版习题答案

 主页   资讯   文章   代码   电子书 

Exercises for Section 12.3

12.3.1

Answer

  1. kill(I,D,X) :- defines(I,X) & defines(D,X)
  2. out(D,D,X) :- defines(D,X)
  3. out(I,D,X) :- in(I,D,X) & NOT kill (I,D,X)
  4. in(I,D,X) :- out(J,D,X) & pred(J,I,X)

    12.3.2

Answer

  1. kill(I,X,O,Y) :- defines(I,X) OR defines(I,Y)
  2. out(I,X,O,Y) :- eval(I,X,O,Y)
  3. out(I,X,O,Y) :- in(I,X,O,Y) & NOT kill(I,X,O,Y)
  4. in(I,X,O,Y) :- out(J,X,O,Y) & pred(J,I)

12.3.3

Answer

  1. out(I,X) :- in(J,X) & pred(I,J)
  2. in(I,X) :- use(I,X) & NOT defines(I,X)

12.3.5

Answer

a)

R1: Path(1,2) Path(2,3) Path(3,4) Path(4,1) Path(4,5) Path(5,6)
R2: Path(1,3) Path(2,4) Path(3,1) Path(3,5) Path(4,6)
R3: Path(1,4) Path(1,5) Path(2,1) Path(2,5) Path(3,6) Path(4,3) Path(2,6) Path(3,2)
R4: Path(1,6) Path(4,2)

b) Same to above