-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path040.fun
More file actions
148 lines (135 loc) · 2.28 KB
/
040.fun
File metadata and controls
148 lines (135 loc) · 2.28 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Test function names used as labels
fun printf(x) {
print(x)
}
fun text(y) {
print(y)
}
fun data(z) {
print(z)
}
fun format(a) {
print(a)
}
fun global(b) {
print(b)
}
# Declare several local variables in the scope
fun severalVariables() {
a = 1
b = 2
c = 3
d = 4
e = 5
f = 6
g = 7
h = 8
i = 9
j = 10
k = 11
l = 12
m = 13
n = 14
o = 15
p = 16
q = 17
r = 18
s = 19
t = 20
u = 21
v = 22
w = 23
x = 24
y = 25
z = 26
}
# Force postfix notation to push many variables onto the stack
fun overflowPostfix() {
x = (!1 + (2 * (3 / (4 - 1 + (5 % (1 + (6 <= (7 < (8 >= (9 > (10 == (11 != (12 && (13 || (14)))))))))))))))
print(x)
}
# Test weird comment locations
fun weirdComments()
# Weird Location 1
{
print(1)
if(1)
# Weird Location 2
{
print(2)
}
# Weird Location 3
else
# Weird Location 4
{
print(3)
}
x = 0
while(x < 5)
# Weird Location 5
{
x = x + 1
print(x)
}
}
# Test weird variable names
fun weirdVariableNames() {
ifelse = 1
whiletrue = 2
print(ifelse + whiletrue)
printf = 5
print(printf)
}
# Test correct return values among nested ifs and whiles
fun nestedIfsAndWhiles(num) {
if(num >= 5) {
i = 5
while(i > 0) {
num = num + 1
if(num == 20) {
if(i > 3) {
return 3
}
return 2
}
i = i - 1
}
} else {
return 1
}
return 0
}
# Test prime factorization for fun
fun primeFactorization(n) {
i = 2
while(i * i <= n) {
while(n % i == 0) {
print(i)
n = n / i
}
i = i + 1
}
if(n > 1) {
print(n)
}
}
fun main() {
severalVariables()
overflowPostfix()
weirdComments()
weirdVariableNames()
print(nestedIfsAndWhiles(3))
print(nestedIfsAndWhiles(5))
print(nestedIfsAndWhiles(3))
print(nestedIfsAndWhiles(15))
print(nestedIfsAndWhiles(20))
primeFactorization(2)
primeFactorization(10)
primeFactorization(505)
primeFactorization(65537)
printf(1)
text(2)
data(3)
format(4)
global(5)
}