七.控制语句也可采用改写文法的方法 S→ ifb then s ifB then S, else S2 while b do s 可将上述文法改写为:
七. 控制语句也可采用改写文法的方法 S→if B then S1 │if B then S1 else S2 │while B do S1 可将上述文法改写为:
C→→ ifb then T→>CS1else W→ while R→WBdo S→CS1TS1|RS1
C→if B then T→C S1 else W→while R→W B do S→C S1 | T S1 | R S1
C→→ ifb then i backpatch(B truelist, ip) C netlist: =B. falselist T→→CS1else i g: ip; emt6220); ); backpatch(C netlist, p T netlist: merge(q (q, s netlist))
C→if B then { backpatch(B.truelist, ip); C.nextlist:=B.falselist } T→C S1 else { q:=ip; emit(j,-,-,0); backpatch(C.nextlist,ip); T.nextlist:=merge(q, S1 .nextlist) }
W→ while ( Wcode = ip R→WBdo backpatch(B truelist, p R netlist =B. falselist R code: =Wcode j
W→while { W.code:=ip } R→W B do { backpatch(B.truelist,ip); R.nextlist:=B.falselist; R.code:=W.code }
S→CS Snetlist: merge (C. nxtlisrt, S,. nextlist)) S→TS1 iS netlist: -merge(T. nxtlisrt, S netlist)) S→RS1 backpatch(S,. nextlist, R code) emit(, ",",Rcode); S netlist: R netlist
S→C S1 { S.nextlist:=merge(C.nxtlisrt, S1 .nextlist) } S→T S1 { S.nextlist:=merge(T.nxtlisrt, S1 .nextlist) } S→R S1 { backpatch(S1 .nextlist,R.code); emit(j,-,-,R.code); S.nextlist:=R.nextlist }