
370 Compilers – Principles and Practice
12.8.5 IF-THEN-ELSE Construct
Actions for IF-THEN-ELSE construct.
if: IF{Symbol *i; i = tree_root("dope"); $$ = i; ++lcount; lpush(lcount);
++lcount; lpush(lcount);}
cond: expr{int l; fprintf(fout1, "Label%d\nBZ\n", l = lpop()); lpush(l);
($$) -> y.I = ++mcount;
fprintf(fout2, "%d: BZ %d -- --\n", mcount, 0);
ethen(l);}
stmt:
| if’(’ cond ’)’ stmt end {int l; /* else-less if */
fprintf(fout1, "Label%d\n:\n", l = lpop()); lpop(); /*label1 */
fprintf(fout2, "%d: LABI %d -- --\n" , ++mcount, ($3)->y.I);
eendif(l);
} /* end, if cond fails */
| if’(’ cond ’)’ stmt end ELSE{int l,l1 ;
l = lpop(); /* label2 ...