-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.shank
95 lines (79 loc) · 1.92 KB
/
test.shank
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{My for loops work a bit differently the "i" does not have to be declared as a variable. It is created as an idt and then
thrown out once the work is done. Also the fib function here might be wrong.
GO TO start() FOR TEST
}
define fib (x : integer)
variables a, b, c :integer
a:=1
b:=1
Write a
Write b
for i from 2 to x
c:= a + b
a:=b
b:=c
Write c
define add (x,y:integer; var sum: integer)
variables counter : integer
counter := y
sum := x
while counter > 0
counter := counter - 1
sum := sum + 1}
{define addRecursive (x,y : integer; var sum : integer)
variables yMinusOne, xPlusOne, newSum : integer
{ in here, x and y are constant }
if y = 0 then
sum := x
else
xPlusOne := x + 1
yMinusOne := y - 1
addRecursive xPlusOne, yMinusOne, var newSum
sum := newSum
}
define start ()
constants pi = 3.141
variables a: integer
constants p = 3.141
variables b: integer
variables x: integer
variables c: string from 0 to 10
{try changing a to string literal - throws an error}
a := 4
b := 6
Write "a is: " a
Write "b is: " b
Write "x is: " x
Write "using the add function"
{Try removing the var to see if var functionality works. This checking is done in interpreter.}
{YOU CAN TEST FUNCTION TYPE MISMATCH HERE BY CHANGING a TO c}
add a b var x
Write a "+" b "=" x
Write "a, b, x:" a b x
Write "a and b remained unchanged and x changed! Also shows builtin function and user-defined functions are working."
{Uncomment the line below to test MathOpNode checking. This part is done through interpreter for me.}
{c:= "hello"
a := a mod c
}
{Uncomment the line below to test function lookup}
{minus a b var c}
{Uncomment the line below to test function parameter length}
{add a b v b var c}
{
{pi := 5}
if a mod 15=0 then
b := 6
elsif a mod 3=0 then
b := 6
elsif a mod 5 = 0 then
b := 6
else
b := 6
for i from 1 to 10
b := 6
while a < 5
a:=8
repeat until a = 100
a:=a+1
a := a mod a
}