From e25a81dc12f8071a3fa8aeb294c9823e8d8e1985 Mon Sep 17 00:00:00 2001 From: Orestis Sabethai Date: Thu, 10 Apr 2025 19:06:03 +0300 Subject: [PATCH 1/2] Fix syntax of powint.dana Use"=" instead of "==" for equality and moved "var temp is int" declaration to the beginning of the block. The program still contains a semantic error so I copied it to the dana/programs-erroneous directory. --- dana/programs-erroneous/powint-erroneous.dana | 30 +++++++++++++++++++ dana/programs/powint.dana | 9 +++--- 2 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 dana/programs-erroneous/powint-erroneous.dana diff --git a/dana/programs-erroneous/powint-erroneous.dana b/dana/programs-erroneous/powint-erroneous.dana new file mode 100644 index 0000000..475718c --- /dev/null +++ b/dana/programs-erroneous/powint-erroneous.dana @@ -0,0 +1,30 @@ +def main + + def powint: base as int, exp as int, mod as int, result as ref int + + base := base % mod + var temp is int + + if exp < 1: + result := 1 + else: + if exp % 2 = 0: + powint: base, exp / 2, mod, temp # SEMANTIC ERROR: temp is not a ref variable but being passed to a ref parameter + result := (temp * temp) % mod + else: + powint: base, exp - 1, mod, temp # SEMANTIC ERROR: temp is not a ref variable but being passed to a ref parameter + result := (base * temp) % mod + + var b is int + var e is int + var m is int + var res is int + + b := readInteger() + e := readInteger() + m := readInteger() + + powint: b, e, m, res + + writeInteger: res + writeString: "\n" diff --git a/dana/programs/powint.dana b/dana/programs/powint.dana index b3631be..475718c 100644 --- a/dana/programs/powint.dana +++ b/dana/programs/powint.dana @@ -3,17 +3,16 @@ def main def powint: base as int, exp as int, mod as int, result as ref int base := base % mod + var temp is int if exp < 1: result := 1 else: - if exp % 2 == 0: - var temp is int - powint: base, exp / 2, mod, temp + if exp % 2 = 0: + powint: base, exp / 2, mod, temp # SEMANTIC ERROR: temp is not a ref variable but being passed to a ref parameter result := (temp * temp) % mod else: - var temp is int - powint: base, exp - 1, mod, temp + powint: base, exp - 1, mod, temp # SEMANTIC ERROR: temp is not a ref variable but being passed to a ref parameter result := (base * temp) % mod var b is int From c85f61ababbd9182bfd64a6eee1490b098da1a95 Mon Sep 17 00:00:00 2001 From: Orestis Sabethai Date: Wed, 16 Apr 2025 05:26:09 +0300 Subject: [PATCH 2/2] Fix syntax in binarysearch program Adjusted the bAdded a missing comma in a procedure call, changed function calls to use () instead of :, specifed a fixed size for the local array variable declaration, and corrected the assignment operator from "=" to ":=". --- dana/programs/binarysearch.dana | 10 +++++----- dana/programs/powint.dana | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dana/programs/binarysearch.dana b/dana/programs/binarysearch.dana index 146f3a8..5d8b013 100644 --- a/dana/programs/binarysearch.dana +++ b/dana/programs/binarysearch.dana @@ -11,13 +11,13 @@ def main i := i + 1 swap: arr[i], arr[j] j := j + 1 - swap: arr[i+1] arr[high] + swap: arr[i+1], arr[high] return: (i+1) def quicksort: arr as int [], low high as int var pi is int if low < high: - pi := (partition: arr, low, high) + pi := partition(arr, low, high) quicksort: arr, low, (pi - 1) quicksort: arr, (pi + 1), high @@ -40,7 +40,7 @@ def main high := mid - 1 return: -1 - var nums is int [] + var nums is int [100] var size k find is int k := 0 writeString: "Give size of array: " @@ -50,7 +50,7 @@ def main loop: if k <= size: nums[k] := readInteger() - k = k + 1 + k := k + 1 else: nums[k] := '\0' break @@ -62,4 +62,4 @@ def main find := readInteger() writeString: "\n" writeString: "Value is: " - writeInteger: (binarySearch: nums, 0, (size - 1), find) + writeInteger: (binarySearch( nums, 0, (size - 1), find)) diff --git a/dana/programs/powint.dana b/dana/programs/powint.dana index 475718c..7e6b6d2 100644 --- a/dana/programs/powint.dana +++ b/dana/programs/powint.dana @@ -9,10 +9,10 @@ def main result := 1 else: if exp % 2 = 0: - powint: base, exp / 2, mod, temp # SEMANTIC ERROR: temp is not a ref variable but being passed to a ref parameter + powint: base, exp / 2, mod, temp result := (temp * temp) % mod else: - powint: base, exp - 1, mod, temp # SEMANTIC ERROR: temp is not a ref variable but being passed to a ref parameter + powint: base, exp - 1, mod, temp result := (base * temp) % mod var b is int