Next: Implementing translation schemes with YACC
Up: MOOL program samples
Previous: MOOL program samples
When discovering a new programming language,
one usually asks how to write the factorial function.
Here's a MOOL program for this.
class Integer {
int value;
new (int n) {
this.value := n;
return n;
}
factorial() {
f := 1;
i := this.value;
while (i > 0) repeat {
f := i * f;
i := i - 1;
};
return f;
}
writeln() {
writeln(this.value);
return 0;
}
}
main {
n := Integer(10);
f := n.factorial();
writeln(f);
}
Next: Implementing translation schemes with YACC
Up: MOOL program samples
Previous: MOOL program samples
Marc Moreno Maza
2004-12-01