Skip to content

Commit e25a81d

Browse files
committed
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.
1 parent b2ca984 commit e25a81d

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
def main
2+
3+
def powint: base as int, exp as int, mod as int, result as ref int
4+
5+
base := base % mod
6+
var temp is int
7+
8+
if exp < 1:
9+
result := 1
10+
else:
11+
if exp % 2 = 0:
12+
powint: base, exp / 2, mod, temp # SEMANTIC ERROR: temp is not a ref variable but being passed to a ref parameter
13+
result := (temp * temp) % mod
14+
else:
15+
powint: base, exp - 1, mod, temp # SEMANTIC ERROR: temp is not a ref variable but being passed to a ref parameter
16+
result := (base * temp) % mod
17+
18+
var b is int
19+
var e is int
20+
var m is int
21+
var res is int
22+
23+
b := readInteger()
24+
e := readInteger()
25+
m := readInteger()
26+
27+
powint: b, e, m, res
28+
29+
writeInteger: res
30+
writeString: "\n"

dana/programs/powint.dana

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ def main
33
def powint: base as int, exp as int, mod as int, result as ref int
44

55
base := base % mod
6+
var temp is int
67

78
if exp < 1:
89
result := 1
910
else:
10-
if exp % 2 == 0:
11-
var temp is int
12-
powint: base, exp / 2, mod, temp
11+
if exp % 2 = 0:
12+
powint: base, exp / 2, mod, temp # SEMANTIC ERROR: temp is not a ref variable but being passed to a ref parameter
1313
result := (temp * temp) % mod
1414
else:
15-
var temp is int
16-
powint: base, exp - 1, mod, temp
15+
powint: base, exp - 1, mod, temp # SEMANTIC ERROR: temp is not a ref variable but being passed to a ref parameter
1716
result := (base * temp) % mod
1817

1918
var b is int

0 commit comments

Comments
 (0)