aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/functions.cup13
1 files changed, 13 insertions, 0 deletions
diff --git a/examples/functions.cup b/examples/functions.cup
new file mode 100644
index 0000000..89858c6
--- /dev/null
+++ b/examples/functions.cup
@@ -0,0 +1,13 @@
+fn rec_sum(n: int, accum: int): int {
+ if (n == 0)
+ return accum;
+ return rec_sum(n - 1, accum + n);
+}
+
+fn sum(n: int): int {
+ return rec_sum(n, 0);
+}
+
+fn main() {
+ return sum(10);
+} \ No newline at end of file