Skip to content

Commit 5b95bba

Browse files
committed
add grammar rules, fix bugs
1 parent 2af0e36 commit 5b95bba

File tree

5 files changed

+276
-122
lines changed

5 files changed

+276
-122
lines changed

inputfile1.txt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
{
22
array = [2, 10, 3, 0, 1, 4, 9, 8, 12, 7, 83, 6, -3, 100, 27];
3-
print(array[2]);
43
size = 15;
54
i = 1;
6-
75
while(i < size) {
8-
6+
print(array);
97
key = array[i];
10-
print(key);
118
j = i - 1;
12-
13-
if (j >= 0) { temp = array[j] > key; }
14-
else { temp = False; }
9+
if (j >= 0) {
10+
temp = array[j] > key;
11+
}
12+
else {
13+
temp = False;
14+
}
1515

1616
while (j >= 0 andalso temp) {
17-
18-
array[j + 1] = array[j];
19-
print(j);
17+
array[j + 1] = array[j];
2018
j = j - 1;
21-
22-
if (j >= 0) { temp = array[j] > key; }
23-
else { temp = False; }
19+
if (j >= 0) {
20+
temp = array[j] > key;
21+
}
22+
else {
23+
temp = False;
24+
}
2425
}
2526

2627
array[j + 1] = key;

inputfile2.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
number = 33;
2+
number = 31;
33
isPrime = 1;
44
i = 2;
5+
56
while(isPrime == 1 andalso number > i)
67
{
78
if (number mod i == 0)
89
{
910
isPrime = 0;
1011
}
1112
i = i + 1;
12-
print(i);
1313
}
1414

1515
if(isPrime == 1)

inputfile3.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
3+
array = [2, 10, 3, 0, 1, 4, 9, 8, 12, 7, 83, 6, -3, 100, 27];
4+
size = 15;
5+
i = 1;
6+
while(i < size) {
7+
8+
key = array[i];
9+
print(key);
10+
j = i - 1;
11+
12+
if (j >= 0) { temp = array[j] > key; }
13+
else { temp = False; }
14+
15+
while (j >= 0 andalso temp) {
16+
array[j + 1] = array[j];
17+
j = j - 1;
18+
19+
if (j >= 0) { temp = array[j] > key; }
20+
else { temp = False; }
21+
}
22+
23+
array[j + 1] = key;
24+
i = i + 1;
25+
}
26+
27+
print(array);
28+
}

inputfile4.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
data = [ [ 100, 42 ], [ 100, 50 ], [ 123, 456 ], [ 300, 9000 ] ];
3+
result = [ 0, 0, 0, 0 ];
4+
i = 0;
5+
while (i < 4){
6+
a = data[i][0];
7+
b = data[i][1];
8+
if (a > 0){
9+
while (b > 0){
10+
if (a > b){
11+
a = a - b;
12+
} else {
13+
b = b - a;
14+
}
15+
}
16+
}
17+
result[i] = a;
18+
i = i + 1;
19+
}
20+
print(result);
21+
}

0 commit comments

Comments
 (0)