Implemented control constructs

This commit is contained in:
Dmitry Boulytchev 2018-03-20 20:30:58 +03:00
commit a60a491e73
23 changed files with 487 additions and 9 deletions

View file

@ -1,4 +1,4 @@
TESTS=test001 test002 test003 test004 test005 test006 test007 test008 test009 test010 test011 test012
TESTS=test001 test002 test003 test004 test005 test006 test007 test008 test009 test010 test011 test012 test015 test017 test018 test019 test020 test021 test022 test023
RC=../src/rc.opt

12
regression/test012.expr Normal file
View file

@ -0,0 +1,12 @@
read (n);
while n >= 0 do
if n > 1
then
write (0);
if n == 3 then write (0) else write (1) fi
else
write (1);
if n > 0 then write (0) else write (1) fi
fi;
n := n - 1
od

1
regression/test012.input Normal file
View file

@ -0,0 +1 @@
3

20
regression/test015.expr Normal file
View file

@ -0,0 +1,20 @@
s := 0;
read (n);
p := 2;
while n > 0 do
c := 2;
f := 1;
while c*c <= p && f do
f := (p % c) != 0;
c := c + 1
od;
if f != 0 then
if n == 1 then write (p) else skip fi;
n := n - 1
else skip fi;
p := p + 1
od

1
regression/test015.input Normal file
View file

@ -0,0 +1 @@
1000

15
regression/test017.expr Normal file
View file

@ -0,0 +1,15 @@
read (n);
i := 2;
fib_1 := 1;
fib_2 := 1;
fib := 1;
while i < n do
fib := fib_1 + fib_2;
fib_2 := fib_1;
fib_1 := fib;
i := i+1
od;
write (fib)

1
regression/test017.input Normal file
View file

@ -0,0 +1 @@
20

43
regression/test018.expr Normal file
View file

@ -0,0 +1,43 @@
read (n);
c := 1;
p := 2;
while c do
cc := 1;
while cc do
q := 2;
while q * q <= p && cc do
cc := p % q != 0;
q := q + 1
od;
if cc then cc := 0 else p := p + 1; cc := 1 fi
od;
d := p;
i := 0;
q := n / d;
m := n % d;
while q > 0 && m == 0 do
i := i + 1;
d := d * p;
m := n % d;
if m == 0 then q := n / d else skip fi
od;
write (p);
write (i);
n := n / (d / p);
p := p + 1;
c := n != 1
od

1
regression/test018.input Normal file
View file

@ -0,0 +1 @@
23409

13
regression/test019.expr Normal file
View file

@ -0,0 +1,13 @@
i := 0;
s := 0;
for i := 0, i < 100, i := i+1
do
for j := 0, j < 100, j := j+1
do
s := s + j
od;
s := s + i
od;
write (s)

0
regression/test019.input Normal file
View file

20
regression/test020.expr Normal file
View file

@ -0,0 +1,20 @@
s := 0;
read (n);
p := 2;
while n > 0 do
c := 2;
f := 1;
for c := 2, c*c <= p && f, c := c+1
do
f := p % c != 0
od;
if f != 0 then
if n == 1 then write (p) fi;
n := n - 1
fi;
p := p + 1
od

1
regression/test020.input Normal file
View file

@ -0,0 +1 @@
1000

9
regression/test021.expr Normal file
View file

@ -0,0 +1,9 @@
read (n);
f := 1;
for skip, n >= 1, n := n-1
do
f := f * n
od;
write (f)

1
regression/test021.input Normal file
View file

@ -0,0 +1 @@
10

14
regression/test022.expr Normal file
View file

@ -0,0 +1,14 @@
read (n);
fib_1 := 1;
fib_2 := 1;
fib := 1;
for i := 2, i < n, i := i+1
do
fib := fib_1 + fib_2;
fib_2 := fib_1;
fib_1 := fib
od;
write (fib)

1
regression/test022.input Normal file
View file

@ -0,0 +1 @@
20

8
regression/test023.expr Normal file
View file

@ -0,0 +1,8 @@
s := 0;
repeat
read (n);
s := s + n
until n == 0;
write (s)

6
regression/test023.input Normal file
View file

@ -0,0 +1,6 @@
5
6
7
8
9
0