Компилятор и вм милана
This commit is contained in:
7
lab4/cmilan/test/add.mil
Normal file
7
lab4/cmilan/test/add.mil
Normal file
@@ -0,0 +1,7 @@
|
||||
BEGIN
|
||||
i := 1;
|
||||
j := 2;
|
||||
k := i + j;
|
||||
WRITE(k)
|
||||
END
|
||||
|
||||
14
lab4/cmilan/test/comment.mil
Normal file
14
lab4/cmilan/test/comment.mil
Normal file
@@ -0,0 +1,14 @@
|
||||
/* это комментарий */
|
||||
/* это продолжение комментария */
|
||||
|
||||
/*****************************
|
||||
* эта программа печатает 42 *
|
||||
****************************/
|
||||
|
||||
begin /* комментарий в конце строки */
|
||||
/* комментарий в начале строки */ write(42)
|
||||
/* многострочный
|
||||
комментарий */
|
||||
end
|
||||
|
||||
/* комментарий в конце файла */
|
||||
10
lab4/cmilan/test/factorial.mil
Normal file
10
lab4/cmilan/test/factorial.mil
Normal file
@@ -0,0 +1,10 @@
|
||||
BEGIN
|
||||
n := READ;
|
||||
factorial := 1;
|
||||
i := 1;
|
||||
WHILE i <= n DO
|
||||
factorial := factorial * i;
|
||||
i := i + 1
|
||||
OD;
|
||||
WRITE(factorial)
|
||||
END
|
||||
17
lab4/cmilan/test/fib.mil
Normal file
17
lab4/cmilan/test/fib.mil
Normal file
@@ -0,0 +1,17 @@
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> N-<2D><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
|
||||
BEGIN
|
||||
a := 1;
|
||||
b := 1;
|
||||
n := READ;
|
||||
|
||||
WHILE n > 1 DO
|
||||
t := a;
|
||||
a := b;
|
||||
b := b + t;
|
||||
n := n - 1
|
||||
OD;
|
||||
|
||||
WRITE(a)
|
||||
END
|
||||
|
||||
17
lab4/cmilan/test/gcd.mil
Normal file
17
lab4/cmilan/test/gcd.mil
Normal file
@@ -0,0 +1,17 @@
|
||||
/* Greatest common divisor */
|
||||
|
||||
BEGIN
|
||||
a := READ;
|
||||
b := READ;
|
||||
|
||||
WHILE a != b DO
|
||||
IF a < b THEN
|
||||
b := b - a
|
||||
ELSE
|
||||
a := a - b
|
||||
FI
|
||||
OD;
|
||||
|
||||
WRITE(a)
|
||||
END
|
||||
|
||||
8
lab4/cmilan/test/if.mil
Normal file
8
lab4/cmilan/test/if.mil
Normal file
@@ -0,0 +1,8 @@
|
||||
BEGIN
|
||||
i := 1;
|
||||
j := 2;
|
||||
|
||||
IF i < j THEN WRITE(i) FI;
|
||||
IF i < j THEN WRITE(i) ELSE WRITE(j) FI
|
||||
END
|
||||
|
||||
5
lab4/cmilan/test/invalid.mil
Normal file
5
lab4/cmilan/test/invalid.mil
Normal file
@@ -0,0 +1,5 @@
|
||||
BEGIN
|
||||
IF 1 2 THEN WRITE(n) ELSE WRITE(2) FI;
|
||||
X := Y + 1;
|
||||
WRITE (X +)
|
||||
END
|
||||
14
lab4/cmilan/test/invert.mil
Normal file
14
lab4/cmilan/test/invert.mil
Normal file
@@ -0,0 +1,14 @@
|
||||
BEGIN
|
||||
x := READ;
|
||||
x := -x;
|
||||
|
||||
WRITE(-x);
|
||||
|
||||
IF -x > 0 THEN x := 1 FI;
|
||||
|
||||
x := x + -1;
|
||||
x := x - -x;
|
||||
|
||||
x := x -1
|
||||
END
|
||||
|
||||
17
lab4/cmilan/test/loop.mil
Normal file
17
lab4/cmilan/test/loop.mil
Normal file
@@ -0,0 +1,17 @@
|
||||
BEGIN
|
||||
/* Read a number */
|
||||
|
||||
i := READ;
|
||||
|
||||
/* Count from 0 to this number */
|
||||
|
||||
IF i > 0 THEN step := 1 ELSE step := -1 FI;
|
||||
k := 0;
|
||||
WHILE k != i DO
|
||||
WRITE(k);
|
||||
k := k + step
|
||||
OD;
|
||||
|
||||
WRITE(i)
|
||||
END
|
||||
|
||||
14
lab4/cmilan/test/power.mil
Normal file
14
lab4/cmilan/test/power.mil
Normal file
@@ -0,0 +1,14 @@
|
||||
BEGIN
|
||||
N := READ;
|
||||
P := READ;
|
||||
|
||||
S := 1;
|
||||
|
||||
WHILE P > 0 DO
|
||||
S := S * N;
|
||||
P := P - 1
|
||||
OD;
|
||||
|
||||
WRITE(S)
|
||||
END
|
||||
|
||||
8
lab4/cmilan/test/read2.mil
Normal file
8
lab4/cmilan/test/read2.mil
Normal file
@@ -0,0 +1,8 @@
|
||||
BEGIN
|
||||
IF READ < READ
|
||||
THEN
|
||||
WRITE(1)
|
||||
ELSE
|
||||
WRITE(2)
|
||||
FI
|
||||
END
|
||||
9
lab4/cmilan/test/sum.mil
Normal file
9
lab4/cmilan/test/sum.mil
Normal file
@@ -0,0 +1,9 @@
|
||||
BEGIN
|
||||
i := 8;
|
||||
j := 2;
|
||||
|
||||
WHILE i != j DO
|
||||
IF i < j THEN j := j - i ELSE i := i - j FI
|
||||
OD;
|
||||
WRITE(i)
|
||||
END
|
||||
Reference in New Issue
Block a user