if ($2 == 0) return (ack($1 - 1, 1))
return (ack($1 - 1, ack($1, $2 - 1)))
}
n=0
ack(3,3)
print n, "calls\n"
3.7.2 ack1
func ack() {
n = n+1
if ($1 == 0) return ($2+1)
if ($2 == 0) return (ack($1 - 1, 1))
return (ack($1 - 1, ack($1, $2 - 1)))
}
n=0
while (read(x)) {
read(y)
print ack(x,y), "\n"
}
print n,"\n"
3.7.3 code.c
#include "hoc.h"
#include "y.tab.h"
#include <stdio.h>
#define NSTACK 256
static Datum stack[NSTACK]; /* the stack */
static Datum *stackp; /* next free spot on stack */
#define NPROG 2000
Inst prog[NPROG]; /* the machine */
Inst *progp; /* next free spot for code generation */
Inst *pc; /* program counter during execution */