Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions dana/programs-erroneous/scope_error.dana
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# x is declared in the loop but called outside
# the loop -> out of scope error

def main
var i is int
i := 10
loop:
var x is byte
x := 'A'
i := i - 1
if i=0 : break
x := 42
64 changes: 64 additions & 0 deletions dana/programs/IntXor.dana
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# A (not so efficient) program that returns the XOR of 2 ints

def main:

# A binary number is represented with an array
# where every bit is stored as an int

# Function definitions
def DecToBin: n as int, N as int[15]
var max i is int
max := 16384
i := 14

loop:
N[i] := n / max
n := n % max
max := max / 2
i = i - 1
if i < 0: break

def BinToDec is int: N as int[15]
var max i n is int
max := 16384
i := 14
n := 0

loop:
n := n + N[i] * max
max := max / 2
i = i - 1
if i < 0: break
return n

def XOR: A B X is int[15]
var i is int
i := 14

loop:
X[i] := (A[i] + B[i]) % 2
i = i - 1
if i < 0: break


# Main program
var a b x is int
var A B X is int[15]

# Read input
writeString: "Input 2 non negative integers"
a := readInteger()
b := readInteger()

# Convert to binary
DecToBin: a, A
DecToBin: b, B

# Calculate XOR
XOR: A, B, X

# Convert result to int
x := BinToDec(X)

# Print result
writeInteger: x
1 change: 1 addition & 0 deletions dana/programs/IntXor.input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10472 31738
1 change: 1 addition & 0 deletions dana/programs/IntXor.output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
21266