
258 Compilers – Principles and Practice
defn: FUNC procname { type($2) = FUNCTION; fprintf(fout1,"%s\nDFN\n",
name($2));
fprintf(fout2,"%d: DFN %s -- --\n", ++mcount, name($2));
($2)->u.I = mcount;}
’(’ ’)’ stmt {fprintf(fout1,"DFE\n");
fprintf(fout2,"%d: RET T%d -- --\n",++mcount, tcount);}
;
procname: VAR
| FUNCTION
;
With the following example source code:
int: a, b, c
b = c + 9
func myfunc() a = a + 7 end
c = 11
we got the following IR (RPN):
int a DCL int b DCL int c DCL c 9 + b = myfunc DFN a 7 + a = DFE
and the following 4-tuple IR:
DCL int a --
DCL int b --
DCL int c --
1: LD c T1 --
2: LD 9 T2 --
3: ADD T1 T2 T3
4: = T3 b --
5: DFN myfunc -- --