From c43a57130601e63ccdd70b0dfd0a5d2bf5bef3a6 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 18 Oct 2023 18:26:05 +0300 Subject: [CI] Added docker setup --- .../coolc-spim/my-code/factorial1.cl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Year 3/Compilers, Introduction/coolc-spim/my-code/factorial1.cl (limited to 'Year 3/Compilers, Introduction/coolc-spim/my-code/factorial1.cl') diff --git a/Year 3/Compilers, Introduction/coolc-spim/my-code/factorial1.cl b/Year 3/Compilers, Introduction/coolc-spim/my-code/factorial1.cl new file mode 100644 index 0000000..31fdb2a --- /dev/null +++ b/Year 3/Compilers, Introduction/coolc-spim/my-code/factorial1.cl @@ -0,0 +1,18 @@ +(* Although this is written from scratch, it is hard to end up with something + much different from what is presented in the original Stanford cs143 course. + So credit for this code goes to Alex Aiken, creator of that course. *) +class Main inherits A2I { + main(): Object { + (new IO).out_string( + i2a( + fact( + a2i((new IO).in_string()) + ) + ).concat("\n") + ) + }; + + fact(i: Int): Int { + if i = 0 then 1 else i * fact(i - 1) fi + }; +}; -- cgit v1.3.1-26-gb76a