From 0508bde07cbb1e5256d1a4d10a07f55411917820 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 30 Apr 2024 01:29:09 +0300 Subject: [PATCH] Add some code examples that I used as test cases during implementation --- .../examples/arithmetic.ph | 16 ++++++++++++++++ .../examples/date-attr.ph | 19 +++++++++++++++++++ 04_semantics_and_running/examples/long-add.ph | 1 + .../examples/long-arith.ph | 1 + 04_semantics_and_running/examples/loop-sum.ph | 18 ++++++++++++++++++ 04_semantics_and_running/examples/loop.ph | 6 ++++++ 04_semantics_and_running/examples/print.ph | 4 ++++ 04_semantics_and_running/examples/proc-arg.ph | 6 ++++++ 04_semantics_and_running/examples/proc-var.ph | 11 +++++++++++ 04_semantics_and_running/examples/var.ph | 9 +++++++++ 10 files changed, 91 insertions(+) create mode 100644 04_semantics_and_running/examples/arithmetic.ph create mode 100644 04_semantics_and_running/examples/date-attr.ph create mode 100644 04_semantics_and_running/examples/long-add.ph create mode 100644 04_semantics_and_running/examples/long-arith.ph create mode 100644 04_semantics_and_running/examples/loop-sum.ph create mode 100644 04_semantics_and_running/examples/loop.ph create mode 100644 04_semantics_and_running/examples/print.ph create mode 100644 04_semantics_and_running/examples/proc-arg.ph create mode 100644 04_semantics_and_running/examples/proc-var.ph create mode 100644 04_semantics_and_running/examples/var.ph diff --git a/04_semantics_and_running/examples/arithmetic.ph b/04_semantics_and_running/examples/arithmetic.ph new file mode 100644 index 0000000..c73fb25 --- /dev/null +++ b/04_semantics_and_running/examples/arithmetic.ph @@ -0,0 +1,16 @@ +print 1 + 1, +print 10 - 5, +print 5 - 10, +print -5 + 2, +print -5 - 5, +print -5 - -5, +print 2 * 3, +print 2 * -3, +print -2 * 3, +print -2 * -3, +print 10 / 2, +print 10 / -2, +print -10 / 2, +print -10 / -2, +print 2024-04-27 - 5, +print 2024-04-27 + 5 diff --git a/04_semantics_and_running/examples/date-attr.ph b/04_semantics_and_running/examples/date-attr.ph new file mode 100644 index 0000000..d80a779 --- /dev/null +++ b/04_semantics_and_running/examples/date-attr.ph @@ -0,0 +1,19 @@ +var date = Today() + +print date, +print date'day, +print date'month, +print date'year, +print date'weekday, +print date'weeknum, + +date.day = 2, +date.month = 3, +date.year = 2'000, + +print date, +print date'day, +print date'month, +print date'year, +print date'weekday, +print date'weeknum diff --git a/04_semantics_and_running/examples/long-add.ph b/04_semantics_and_running/examples/long-add.ph new file mode 100644 index 0000000..f535fed --- /dev/null +++ b/04_semantics_and_running/examples/long-add.ph @@ -0,0 +1 @@ +print 1+1+1+1+1+1+1+1+1+1 \ No newline at end of file diff --git a/04_semantics_and_running/examples/long-arith.ph b/04_semantics_and_running/examples/long-arith.ph new file mode 100644 index 0000000..0fce414 --- /dev/null +++ b/04_semantics_and_running/examples/long-arith.ph @@ -0,0 +1 @@ +print 1 + 2 - 3 + 5 - 7 + 11 - 13 + 17 - 19 \ No newline at end of file diff --git a/04_semantics_and_running/examples/loop-sum.ph b/04_semantics_and_running/examples/loop-sum.ph new file mode 100644 index 0000000..b8d153e --- /dev/null +++ b/04_semantics_and_running/examples/loop-sum.ph @@ -0,0 +1,18 @@ +var nn = 1'000'000'000 +var count = 0 +var sum = 0 + +function Func{ second_number[int] } return int +is + (second_number + 3) * 5 +end function + +(% Calculate sum with a loop %) +do + do + sum = sum + Func(count), + count = count + 1 + until nn < count +unless nn = 0 done, + +print "Sum from 0 to" & nn & "is" & sum diff --git a/04_semantics_and_running/examples/loop.ph b/04_semantics_and_running/examples/loop.ph new file mode 100644 index 0000000..3a1227e --- /dev/null +++ b/04_semantics_and_running/examples/loop.ph @@ -0,0 +1,6 @@ +var num = -10 + +do + print num, + num = num + 1 +until num = 11 diff --git a/04_semantics_and_running/examples/print.ph b/04_semantics_and_running/examples/print.ph new file mode 100644 index 0000000..066d666 --- /dev/null +++ b/04_semantics_and_running/examples/print.ph @@ -0,0 +1,4 @@ +print "hello" & "world", +print 10, +print 2024-04-27, +print Today() - 365*100 \ No newline at end of file diff --git a/04_semantics_and_running/examples/proc-arg.ph b/04_semantics_and_running/examples/proc-arg.ph new file mode 100644 index 0000000..b9006c1 --- /dev/null +++ b/04_semantics_and_running/examples/proc-arg.ph @@ -0,0 +1,6 @@ +procedure PROC{ arg1[int], arg2[int], arg3[int], arg4[int], arg5[int] } +is + print arg1 & arg2 & arg3 & arg4 & arg5 +end procedure + +PROC(1, 2, 3, 4, 5) diff --git a/04_semantics_and_running/examples/proc-var.ph b/04_semantics_and_running/examples/proc-var.ph new file mode 100644 index 0000000..9c8af31 --- /dev/null +++ b/04_semantics_and_running/examples/proc-var.ph @@ -0,0 +1,11 @@ +procedure PROC{ } +var var1 = 1 +var var2 = 2 +var var3 = 3 +var var4 = 4 +var var5 = 5 +is + print var1 & var2 & var3 & var4 & var5 +end procedure + +PROC() diff --git a/04_semantics_and_running/examples/var.ph b/04_semantics_and_running/examples/var.ph new file mode 100644 index 0000000..59acb8d --- /dev/null +++ b/04_semantics_and_running/examples/var.ph @@ -0,0 +1,9 @@ +var foo = 20 +var bar = 10 + +print foo + bar, +print foo - bar, +print foo * bar, +print foo / bar, + +print (foo + (foo + (foo + (foo + bar))))