mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-05 22:38:44 +00:00
return fixed for real, tests added
This commit is contained in:
parent
644c1b3086
commit
274bda6938
95 changed files with 870 additions and 14 deletions
18
regression/orig/test072.log
Normal file
18
regression/orig/test072.log
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
> 9
|
||||
55
|
||||
8
|
||||
34
|
||||
7
|
||||
21
|
||||
6
|
||||
13
|
||||
5
|
||||
8
|
||||
4
|
||||
5
|
||||
3
|
||||
3
|
||||
2
|
||||
2
|
||||
1
|
||||
1
|
||||
14
regression/orig/test073.log
Normal file
14
regression/orig/test073.log
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
> 7
|
||||
5040
|
||||
6
|
||||
720
|
||||
5
|
||||
120
|
||||
4
|
||||
24
|
||||
3
|
||||
6
|
||||
2
|
||||
2
|
||||
1
|
||||
1
|
||||
36
regression/orig/test074.log
Normal file
36
regression/orig/test074.log
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
3
|
||||
5
|
||||
7
|
||||
9
|
||||
11
|
||||
13
|
||||
15
|
||||
17
|
||||
19
|
||||
5
|
||||
13
|
||||
29
|
||||
61
|
||||
125
|
||||
253
|
||||
509
|
||||
1021
|
||||
2045
|
||||
2
regression/orig/test075.log
Normal file
2
regression/orig/test075.log
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> 55
|
||||
15
|
||||
8
regression/orig/test076.log
Normal file
8
regression/orig/test076.log
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
> 10
|
||||
20
|
||||
30
|
||||
40
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
6
regression/orig/test077.log
Normal file
6
regression/orig/test077.log
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
> 5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
12
regression/orig/test078.log
Normal file
12
regression/orig/test078.log
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
> 1
|
||||
2
|
||||
3
|
||||
4
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
3
|
||||
4
|
||||
1
|
||||
2
|
||||
6
regression/orig/test079.log
Normal file
6
regression/orig/test079.log
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
> 1
|
||||
1
|
||||
1
|
||||
1
|
||||
0
|
||||
0
|
||||
3
regression/orig/test080.log
Normal file
3
regression/orig/test080.log
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
> 0
|
||||
100
|
||||
300
|
||||
6
regression/orig/test081.log
Normal file
6
regression/orig/test081.log
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
> 1
|
||||
2
|
||||
3
|
||||
100
|
||||
200
|
||||
300
|
||||
17
regression/orig/test082.log
Normal file
17
regression/orig/test082.log
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
> 1
|
||||
1
|
||||
1
|
||||
1
|
||||
1
|
||||
2
|
||||
3
|
||||
100
|
||||
3
|
||||
2
|
||||
1
|
||||
6
|
||||
5
|
||||
4
|
||||
3
|
||||
2
|
||||
1
|
||||
3
regression/orig/test083.log
Normal file
3
regression/orig/test083.log
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
> 7
|
||||
7
|
||||
28
|
||||
3
regression/orig/test084.log
Normal file
3
regression/orig/test084.log
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
> 55
|
||||
310
|
||||
310
|
||||
8
regression/orig/test085.log
Normal file
8
regression/orig/test085.log
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
> 0
|
||||
15
|
||||
15
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
3
regression/orig/test086.log
Normal file
3
regression/orig/test086.log
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
> 1
|
||||
2
|
||||
3
|
||||
6
regression/orig/test087.log
Normal file
6
regression/orig/test087.log
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
> 1
|
||||
0
|
||||
1
|
||||
0
|
||||
1
|
||||
1
|
||||
2
regression/orig/test088.log
Normal file
2
regression/orig/test088.log
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
0
|
||||
3
|
||||
1
regression/orig/test089.log
Normal file
1
regression/orig/test089.log
Normal file
|
|
@ -0,0 +1 @@
|
|||
> > > 8
|
||||
3
regression/orig/test090.log
Normal file
3
regression/orig/test090.log
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
> 6
|
||||
7
|
||||
8
|
||||
9
regression/orig/test091.log
Normal file
9
regression/orig/test091.log
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
> 1
|
||||
2
|
||||
3
|
||||
2
|
||||
3
|
||||
4
|
||||
3
|
||||
4
|
||||
5
|
||||
5
regression/orig/test092.log
Normal file
5
regression/orig/test092.log
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
> 1
|
||||
1
|
||||
1
|
||||
1
|
||||
0
|
||||
2
regression/orig/test093.log
Normal file
2
regression/orig/test093.log
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> 11
|
||||
18
|
||||
4
regression/orig/test094.log
Normal file
4
regression/orig/test094.log
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
> 5
|
||||
7
|
||||
12
|
||||
-2
|
||||
1
regression/orig/test095.log
Normal file
1
regression/orig/test095.log
Normal file
|
|
@ -0,0 +1 @@
|
|||
> 5
|
||||
2
regression/orig/test096.log
Normal file
2
regression/orig/test096.log
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> 2
|
||||
1
|
||||
1
regression/orig/test097.log
Normal file
1
regression/orig/test097.log
Normal file
|
|
@ -0,0 +1 @@
|
|||
> 35
|
||||
1
regression/orig/test098.log
Normal file
1
regression/orig/test098.log
Normal file
|
|
@ -0,0 +1 @@
|
|||
> 12
|
||||
3
regression/orig/test099.log
Normal file
3
regression/orig/test099.log
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
> 1
|
||||
800
|
||||
800
|
||||
1
regression/orig/test100.log
Normal file
1
regression/orig/test100.log
Normal file
|
|
@ -0,0 +1 @@
|
|||
> 0
|
||||
1
regression/orig/test101.log
Normal file
1
regression/orig/test101.log
Normal file
|
|
@ -0,0 +1 @@
|
|||
> 0
|
||||
1
regression/orig/test102.log
Normal file
1
regression/orig/test102.log
Normal file
|
|
@ -0,0 +1 @@
|
|||
> 5
|
||||
16
regression/test072.expr
Normal file
16
regression/test072.expr
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
local n, i;
|
||||
|
||||
fun fib (n) {
|
||||
if n <= 1
|
||||
then 1
|
||||
else
|
||||
(fib (n-1) + fib (n-2))
|
||||
fi
|
||||
}
|
||||
|
||||
n := read ();
|
||||
|
||||
for i := n, i >= 1, i := i-1 do
|
||||
write (i);
|
||||
write (fib (i))
|
||||
od
|
||||
1
regression/test072.input
Normal file
1
regression/test072.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
9
|
||||
16
regression/test073.expr
Normal file
16
regression/test073.expr
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
local n, i;
|
||||
|
||||
fun fact (n) {
|
||||
if n <= 1
|
||||
then 1
|
||||
else
|
||||
(n * fact (n-1))
|
||||
fi
|
||||
}
|
||||
|
||||
n := read ();
|
||||
|
||||
for i := n, i >= 1, i := i-1 do
|
||||
write (i);
|
||||
write (fact (i))
|
||||
od
|
||||
1
regression/test073.input
Normal file
1
regression/test073.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
7
|
||||
16
regression/test074.expr
Normal file
16
regression/test074.expr
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
local x, m, n;
|
||||
|
||||
fun ack (m, n) {
|
||||
if m == 0 then (n+1)
|
||||
elif m > 0 && n == 0 then ack (m-1, 1)
|
||||
else ack (m-1, ack (m, n-1))
|
||||
fi
|
||||
}
|
||||
|
||||
x := read ();
|
||||
|
||||
for m := 0, m <= 3, m := m+1 do
|
||||
for n := 0, n <= 8, n := n+1 do
|
||||
write (ack (m, n))
|
||||
od
|
||||
od
|
||||
1
regression/test074.input
Normal file
1
regression/test074.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
17
regression/test075.expr
Normal file
17
regression/test075.expr
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
local x;
|
||||
|
||||
fun test (n, m) {
|
||||
local i, s;
|
||||
s := 0;
|
||||
for i := 0, i <= n, i := i + 1 do
|
||||
s := s + i;
|
||||
if s > m then return s fi
|
||||
od;
|
||||
|
||||
s
|
||||
}
|
||||
|
||||
x := read ();
|
||||
|
||||
write (test (10, 100));
|
||||
write (test (100, 10))
|
||||
1
regression/test075.input
Normal file
1
regression/test075.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
24
regression/test076.expr
Normal file
24
regression/test076.expr
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
local n, x, i;
|
||||
|
||||
fun printArray (x) {
|
||||
local elem;
|
||||
if x.length == 0 then return fi;
|
||||
for i:=0, i<x.length, i:=i+1 do
|
||||
write (x[i])
|
||||
od
|
||||
}
|
||||
|
||||
n := read ();
|
||||
|
||||
x := [10, 20, 30, 40];
|
||||
|
||||
printArray (x);
|
||||
|
||||
for i:=0, i<x.length, i:=i+1 do
|
||||
x[i] := i
|
||||
od;
|
||||
|
||||
printArray (x)
|
||||
|
||||
|
||||
|
||||
1
regression/test076.input
Normal file
1
regression/test076.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
29
regression/test077.expr
Normal file
29
regression/test077.expr
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
local n, x, i;
|
||||
|
||||
fun sort (x) {
|
||||
local i, j, y, n;
|
||||
n := x.length;
|
||||
|
||||
if n == 0 then x fi;
|
||||
|
||||
for i := 0, i<n, i := i+1 do
|
||||
for j := i+1, j<n, j := j+1 do
|
||||
if x[j] < x[i] then
|
||||
y := x[i];
|
||||
x[i] := x[j];
|
||||
x[j] := y
|
||||
fi
|
||||
od
|
||||
od;
|
||||
|
||||
x
|
||||
}
|
||||
|
||||
n := read ();
|
||||
x := [10, 9, 8, 7, 6, 5];
|
||||
|
||||
x := sort (x);
|
||||
|
||||
for i:=0, i<x.length, i:=i+1 do
|
||||
write (x[i])
|
||||
od
|
||||
1
regression/test077.input
Normal file
1
regression/test077.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
25
regression/test078.expr
Normal file
25
regression/test078.expr
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
local n, x, y;
|
||||
|
||||
fun append (x, y) {
|
||||
case x of
|
||||
Nil -> y
|
||||
| Cons (h, t) -> Cons (h, append (t, y))
|
||||
esac
|
||||
}
|
||||
|
||||
fun printList (x) {
|
||||
case x of
|
||||
Nil -> skip
|
||||
| Cons (h, t) -> write (h); printList (t)
|
||||
esac
|
||||
}
|
||||
|
||||
n := read ();
|
||||
|
||||
x := Cons (1, Cons (2, Nil));
|
||||
y := Cons (3, Cons (4, Nil));
|
||||
|
||||
printList (x);
|
||||
printList (y);
|
||||
printList (append (x, y));
|
||||
printList (append (y, x))
|
||||
1
regression/test078.input
Normal file
1
regression/test078.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
32
regression/test079.expr
Normal file
32
regression/test079.expr
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
local n, t;
|
||||
|
||||
fun insert (t, x) {
|
||||
case t of
|
||||
Leaf -> Node (x, Leaf, Leaf)
|
||||
| Node (y, l, r) -> if x > y
|
||||
then Node (y, insert (l, x), r)
|
||||
else Node (y, l, insert (r, x))
|
||||
fi
|
||||
esac
|
||||
}
|
||||
|
||||
fun find (t, x) {
|
||||
case t of
|
||||
Leaf -> 0
|
||||
| Node (y, l, r) -> if x == y then 1
|
||||
elif x > y then find (l, x)
|
||||
else find (r, x)
|
||||
fi
|
||||
esac
|
||||
}
|
||||
|
||||
n := read ();
|
||||
|
||||
t := insert (insert (insert (insert (Leaf, 5), 4), 6), 3);
|
||||
|
||||
write (find (t, 5));
|
||||
write (find (t, 4));
|
||||
write (find (t, 6));
|
||||
write (find (t, 3));
|
||||
write (find (t, 2));
|
||||
write (find (t, 1))
|
||||
1
regression/test079.input
Normal file
1
regression/test079.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
14
regression/test080.expr
Normal file
14
regression/test080.expr
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
local x;
|
||||
|
||||
fun sum (x) {
|
||||
case x of
|
||||
Nil -> 0
|
||||
| Cons (x, tl) -> (x + sum (tl))
|
||||
esac
|
||||
}
|
||||
|
||||
x := read ();
|
||||
|
||||
write (sum (Nil));
|
||||
write (sum (Cons (100, Nil)));
|
||||
write (sum (Cons (100, Cons (200, Nil))))
|
||||
1
regression/test080.input
Normal file
1
regression/test080.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
39
regression/test081.expr
Normal file
39
regression/test081.expr
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
local x, y, z;
|
||||
|
||||
fun zip (x) {
|
||||
case x of Pair (x, y) ->
|
||||
case x of
|
||||
Nil -> Nil
|
||||
| Cons (x, xs) -> case y of
|
||||
Nil -> Nil
|
||||
| Cons (y, ys) -> Cons (Pair (x, y), zip (Pair (xs, ys)))
|
||||
esac
|
||||
esac
|
||||
esac
|
||||
}
|
||||
|
||||
fun unzip (x) {
|
||||
case x of
|
||||
Nil -> Pair (Nil, Nil)
|
||||
| Cons (Pair (x, y), tl) ->
|
||||
case unzip (tl) of
|
||||
Pair (xs, ys) -> Pair (Cons (x, xs), Cons (y, ys))
|
||||
esac
|
||||
esac
|
||||
}
|
||||
|
||||
fun printList (l) {
|
||||
case l of
|
||||
Nil -> skip
|
||||
| Cons (x, xs) -> write (x); printList (xs)
|
||||
esac
|
||||
}
|
||||
|
||||
z := read ();
|
||||
|
||||
x := Cons (1, Cons (2, Cons (3, Nil)));
|
||||
y := Cons (100, Cons (200, Cons (300, Nil)));
|
||||
|
||||
case unzip (zip (Pair (x, y))) of
|
||||
Pair (x, y) -> printList (x); printList (y)
|
||||
esac
|
||||
1
regression/test081.input
Normal file
1
regression/test081.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
75
regression/test082.expr
Normal file
75
regression/test082.expr
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
local n;
|
||||
|
||||
fun collect_ints_acc (v, tail) {
|
||||
local i;
|
||||
case v of
|
||||
a@#unboxed -> Cons (a, tail)
|
||||
| #string -> tail
|
||||
| _ ->
|
||||
for i := 0, i < v.length, i := i + 1 do
|
||||
tail := collect_ints_acc (v[i], tail)
|
||||
od;
|
||||
tail
|
||||
esac
|
||||
}
|
||||
|
||||
fun collect_ints (v) {
|
||||
collect_ints_acc (v, Nil)
|
||||
}
|
||||
|
||||
fun print_list (l) {
|
||||
case l of
|
||||
Nil -> skip
|
||||
| Cons (n, t) -> write (n); print_list (t)
|
||||
esac
|
||||
}
|
||||
|
||||
n := read ();
|
||||
|
||||
case 1 of
|
||||
5 -> write (5)
|
||||
| 4 -> write (4)
|
||||
| 3 -> write (3)
|
||||
| 2 -> write (2)
|
||||
| 1 -> write (1)
|
||||
| 0 -> write (0)
|
||||
esac;
|
||||
|
||||
case 1 of
|
||||
a@5 -> write (a)
|
||||
| a@4 -> write (a)
|
||||
| a@3 -> write (a)
|
||||
| a@2 -> write (a)
|
||||
| a@1 -> write (a)
|
||||
| a@0 -> write (a)
|
||||
esac;
|
||||
|
||||
case A (1, 2, 3) of
|
||||
A (1, 3, 5) -> write (0)
|
||||
| A (3, 4, 5) -> write (0)
|
||||
| A (1, 2, 3) -> write (1)
|
||||
| A (6, 7, 8) -> write (0)
|
||||
esac;
|
||||
|
||||
case "abc" of
|
||||
"def" -> write (0)
|
||||
| "ab" -> write (0)
|
||||
| "abc" -> write (1)
|
||||
| "" -> write (0)
|
||||
esac;
|
||||
|
||||
case [1, 2, 3] of
|
||||
[] -> write (0)
|
||||
| [a, b] -> write (0)
|
||||
| [a, b, c] -> write (a); write (b); write (c)
|
||||
| [_, _, _] -> write (0)
|
||||
esac;
|
||||
|
||||
case [1, 2, 3] of
|
||||
[] -> write (0)
|
||||
| [a, b] -> write (0)
|
||||
| [_, _, _] -> write (100)
|
||||
| [a, b, c] -> write (a); write (b); write (c)
|
||||
esac;
|
||||
|
||||
print_list (collect_ints ([1, 2, 3, [4, 5, 6, Cons (1, 2, 3)]]))
|
||||
1
regression/test082.input
Normal file
1
regression/test082.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
12
regression/test083.expr
Normal file
12
regression/test083.expr
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
local n, y;
|
||||
|
||||
fun test (n, m) {
|
||||
local i, s;
|
||||
write (n);
|
||||
write (m);
|
||||
n
|
||||
}
|
||||
|
||||
n := read ();
|
||||
y := 1 + (2 + (3 + (4 + (5 + (6 + test (7, 7))))));
|
||||
write (y)
|
||||
1
regression/test083.input
Normal file
1
regression/test083.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
23
regression/test084.expr
Normal file
23
regression/test084.expr
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
local n, y, y2, t;
|
||||
|
||||
fun test (n, m) {
|
||||
local i, s;
|
||||
s := 0;
|
||||
for i := 0, i <= n, i := i + 1 do
|
||||
s := s + i;
|
||||
if s > m then s fi
|
||||
od;
|
||||
|
||||
s
|
||||
}
|
||||
|
||||
n := read ();
|
||||
y := ((((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))))) + ((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))))) + (((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))))) + ((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + test(10, 100)))))))));
|
||||
|
||||
t := test (10, 100);
|
||||
y2 := ((((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))))) + ((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))))) + (((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))))) + ((((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))))) + (((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1)))) + ((((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + 1))) + (((1 + 1) + (1 + 1)) + ((1 + 1) + (1 + t))))))));
|
||||
|
||||
write (t);
|
||||
write (y2);
|
||||
write (y)
|
||||
|
||||
1
regression/test084.input
Normal file
1
regression/test084.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
31
regression/test085.expr
Normal file
31
regression/test085.expr
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
local n;
|
||||
|
||||
fun sum (l) {
|
||||
case l of
|
||||
{} -> 0
|
||||
| h : t -> (h + sum (t))
|
||||
esac
|
||||
}
|
||||
|
||||
fun print_list (l) {
|
||||
case l of
|
||||
{} -> skip
|
||||
| h : t -> write (h); print_list (t)
|
||||
esac
|
||||
}
|
||||
|
||||
fun array_to_list (a) {
|
||||
local l, i;
|
||||
l := {};
|
||||
for i := a.length, i > 0, i := i-1 do
|
||||
l := a[i-1] : l
|
||||
od;
|
||||
l
|
||||
}
|
||||
|
||||
n := read ();
|
||||
write (sum ({}));
|
||||
write (sum ({1, 2, 3, 4, 5}));
|
||||
write (sum (1:2:3:4:5:{}));
|
||||
print_list (array_to_list ([1, 2, 3, 4, 5]))
|
||||
|
||||
1
regression/test085.input
Normal file
1
regression/test085.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
26
regression/test086.expr
Normal file
26
regression/test086.expr
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
local n;
|
||||
|
||||
fun hd (l) {
|
||||
case l of
|
||||
h : _ -> h
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
fun tl (l) {
|
||||
case l of
|
||||
_ : tl -> tl
|
||||
esac
|
||||
}
|
||||
|
||||
fun print_list (l) {
|
||||
case l of
|
||||
{} -> skip
|
||||
| h : t -> write (h); print_list (t)
|
||||
esac
|
||||
}
|
||||
|
||||
n := read ();
|
||||
write ({1, 2, 3}.hd);
|
||||
print_list ({1, 2, 3}.tl)
|
||||
|
||||
1
regression/test086.input
Normal file
1
regression/test086.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
41
regression/test087.expr
Normal file
41
regression/test087.expr
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
local n;
|
||||
|
||||
infix "===" at "==" (v1, v2) {
|
||||
local s1, s2, i;
|
||||
|
||||
s1 := v1.string;
|
||||
s2 := v2.string;
|
||||
|
||||
if s1.length == s2.length
|
||||
then
|
||||
for i := 0, i < s1.length, i := i + 1
|
||||
do
|
||||
if s1[i] != s2[i] then return 0 fi
|
||||
od;
|
||||
1
|
||||
else 0
|
||||
fi
|
||||
}
|
||||
|
||||
infix "?" before "+" (v, l) {
|
||||
case l of
|
||||
{} -> 0
|
||||
| h : tl -> if h === v then 1 else (v ? tl) fi
|
||||
esac
|
||||
}
|
||||
|
||||
infix "+++" at "+" (l1, l2) {
|
||||
case l1 of
|
||||
{} -> l2
|
||||
| h : tl -> (h : tl +++ l2)
|
||||
esac
|
||||
}
|
||||
|
||||
n := read ();
|
||||
|
||||
write ({1, 2, 3} === {1, 2, 3});
|
||||
write ({1, 2, 3} === {1, 2, 4});
|
||||
write (1+2 ? {1, 2, 3});
|
||||
write (1*3+2 ? {1, 2, 3});
|
||||
write (1*3+2 ? {1, 2, 5});
|
||||
write (8*4 ? {1, 2, 3} +++ {5, 7, 32, 6})
|
||||
1
regression/test087.input
Normal file
1
regression/test087.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
8
regression/test088.expr
Normal file
8
regression/test088.expr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fun len(l) {
|
||||
case l of
|
||||
_ : xs -> len(xs) + 1
|
||||
|{} -> 0
|
||||
esac
|
||||
}
|
||||
write(len({}));
|
||||
write(len({1, 2, 3}))
|
||||
0
regression/test088.input
Normal file
0
regression/test088.input
Normal file
8
regression/test089.expr
Normal file
8
regression/test089.expr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fun test (a, b, c) {
|
||||
local x = a + b, y = b + c;
|
||||
{local e = x + y;
|
||||
e
|
||||
}
|
||||
}
|
||||
|
||||
write (test (read (), read (), read ()))
|
||||
3
regression/test089.input
Normal file
3
regression/test089.input
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
1
|
||||
2
|
||||
3
|
||||
12
regression/test090.expr
Normal file
12
regression/test090.expr
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fun a (x) { x + 1}
|
||||
fun b (x) { x + 2}
|
||||
fun c (x) { x + 3}
|
||||
|
||||
{
|
||||
local funs = [a, b, c];
|
||||
local n = read (), i;
|
||||
|
||||
for i := 0, i < 3, i := i+1 do
|
||||
write (funs[i] (n))
|
||||
od
|
||||
}
|
||||
1
regression/test090.input
Normal file
1
regression/test090.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
23
regression/test091.expr
Normal file
23
regression/test091.expr
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
fun map (f, l) {
|
||||
case l of
|
||||
{} -> {}
|
||||
| h : tl -> (f (h) : map (f, tl))
|
||||
esac
|
||||
}
|
||||
|
||||
fun a (x) { x + 1}
|
||||
fun b (x) { x + 2}
|
||||
|
||||
fun print_list (x) {
|
||||
case x of
|
||||
{} -> skip
|
||||
| h : tl -> write (h); print_list (tl)
|
||||
esac
|
||||
}
|
||||
|
||||
local x = read ();
|
||||
|
||||
print_list ({1, 2, 3});
|
||||
print_list (map (a, {1, 2, 3}));
|
||||
print_list (map (b, {1, 2, 3}))
|
||||
|
||||
1
regression/test091.input
Normal file
1
regression/test091.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
19
regression/test092.expr
Normal file
19
regression/test092.expr
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
fun f (l) {
|
||||
infix "===" at "==" (a, b) {
|
||||
a == b
|
||||
}
|
||||
|
||||
case l of
|
||||
{} -> 1
|
||||
| {_} -> 1
|
||||
| a : b : tl -> a === b && f (b : tl)
|
||||
esac
|
||||
}
|
||||
|
||||
local x = read ();
|
||||
|
||||
write (f ({}));
|
||||
write (f ({1}));
|
||||
write (f ({1, 1}));
|
||||
write (f ({1, 1, 1}));
|
||||
write (f ({1, 2, 1}))
|
||||
1
regression/test092.input
Normal file
1
regression/test092.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
12
regression/test093.expr
Normal file
12
regression/test093.expr
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
fun plus (x) {
|
||||
fun f (y) {
|
||||
x + y
|
||||
}
|
||||
|
||||
f
|
||||
}
|
||||
|
||||
local x = read ();
|
||||
|
||||
write (plus(5)(6));
|
||||
write (plus(8)(10))
|
||||
1
regression/test093.input
Normal file
1
regression/test093.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
22
regression/test094.expr
Normal file
22
regression/test094.expr
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
fun a (x, y) {
|
||||
local a = x + y, b = x - y;
|
||||
{
|
||||
local f = fun () {
|
||||
write (x);
|
||||
write (y);
|
||||
write (a);
|
||||
write (b)
|
||||
};
|
||||
|
||||
a := 100;
|
||||
b := 200;
|
||||
x := 800;
|
||||
y := 1000;
|
||||
|
||||
f
|
||||
}
|
||||
}
|
||||
|
||||
local x = read ();
|
||||
|
||||
a (5, 7) ()
|
||||
1
regression/test094.input
Normal file
1
regression/test094.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
5
regression/test095.expr
Normal file
5
regression/test095.expr
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
infix "++" at "+" (a, b) { a+b}
|
||||
|
||||
local x = read ();
|
||||
|
||||
write (infix "++" (2, 3))
|
||||
1
regression/test095.input
Normal file
1
regression/test095.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
23
regression/test096.expr
Normal file
23
regression/test096.expr
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
fun f () {
|
||||
local x, l = {};
|
||||
fun g () { x}
|
||||
|
||||
x := 1;
|
||||
l := g : l;
|
||||
|
||||
x := 2;
|
||||
l := g : l;
|
||||
|
||||
l
|
||||
}
|
||||
|
||||
fun p (l) {
|
||||
case l of
|
||||
{} -> skip
|
||||
| h : tl -> write (h ()); p (tl)
|
||||
esac
|
||||
}
|
||||
|
||||
local x = read ();
|
||||
|
||||
p (f ())
|
||||
1
regression/test096.input
Normal file
1
regression/test096.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
13
regression/test097.expr
Normal file
13
regression/test097.expr
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
fun f (a) {
|
||||
fun g (b) {
|
||||
fun h (c) {
|
||||
fun (x) { x + a + b + c}
|
||||
}
|
||||
h (b)
|
||||
}
|
||||
g (a)
|
||||
}
|
||||
|
||||
local x = read ();
|
||||
|
||||
write (f(10)(5))
|
||||
1
regression/test097.input
Normal file
1
regression/test097.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
7
regression/test098.expr
Normal file
7
regression/test098.expr
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
infixr "**" before "*" (f, g) {
|
||||
fun (x) { f (g (x))}
|
||||
}
|
||||
|
||||
local x = read ();
|
||||
|
||||
write ((fun (x) { x+2} ** fun (x) { x+3})(7))
|
||||
1
regression/test098.input
Normal file
1
regression/test098.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
19
regression/test099.expr
Normal file
19
regression/test099.expr
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
fun lazy (f) {
|
||||
local flag = 0, value = 0;
|
||||
|
||||
fun () {
|
||||
if flag
|
||||
then value
|
||||
else
|
||||
value := f ();
|
||||
flag := 1;
|
||||
value
|
||||
fi
|
||||
}
|
||||
}
|
||||
|
||||
local l = lazy (fun () {write (1); 800});
|
||||
local x = read ();
|
||||
|
||||
write (l ());
|
||||
write (l ())
|
||||
1
regression/test099.input
Normal file
1
regression/test099.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
11
regression/test100.expr
Normal file
11
regression/test100.expr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fun f (x) {
|
||||
fun inner (y) {
|
||||
if y == 0 then 0 else inner (y-1) fi
|
||||
}
|
||||
|
||||
inner (x)
|
||||
}
|
||||
|
||||
local n = read ();
|
||||
|
||||
write (f (5))
|
||||
1
regression/test100.input
Normal file
1
regression/test100.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
15
regression/test101.expr
Normal file
15
regression/test101.expr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
fun f (x) {
|
||||
fun inner1 (y) {
|
||||
if y == 0 then 0 else inner2 (y-1) fi
|
||||
}
|
||||
|
||||
fun inner2 (y) {
|
||||
if y == 0 then 0 else inner1 (y-1) fi
|
||||
}
|
||||
|
||||
inner1 (x)
|
||||
}
|
||||
|
||||
local n = read ();
|
||||
|
||||
write (f (5))
|
||||
1
regression/test101.input
Normal file
1
regression/test101.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
9
regression/test102.expr
Normal file
9
regression/test102.expr
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fun f (x) {
|
||||
fun g () { x}
|
||||
fun h () { g}
|
||||
g
|
||||
}
|
||||
|
||||
local n = read ();
|
||||
|
||||
write (f(5)())
|
||||
1
regression/test102.input
Normal file
1
regression/test102.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
5
|
||||
|
|
@ -660,7 +660,7 @@ module Expr =
|
|||
| c:(%"true" {Const 1} | %"false" {Const 0}) => {notRef atr} => {ignore atr c}
|
||||
|
||||
| %"infix" s:STRING => {notRef atr} => {ignore atr (Var (infix_name s))}
|
||||
| %"fun" "(" args:!(Util.list0)[ostap (LIDENT)] ")" body:basic[def][infix][Weak] => {notRef atr} => {ignore atr (Lambda (args, body))}
|
||||
| %"fun" "(" args:!(Util.list0)[ostap (LIDENT)] ")" "{" body:scope[def][infix][Weak][parse def] "}"=> {notRef atr} => {ignore atr (Lambda (args, body))}
|
||||
| "[" es:!(Util.list0)[parse def infix Val] "]" => {notRef atr} => {ignore atr (Array es)}
|
||||
| -"{" scope[def][infix][atr][parse def] -"}"
|
||||
| "{" es:!(Util.list0)[parse def infix Val] "}" => {notRef atr} => {ignore atr (match es with
|
||||
|
|
@ -671,7 +671,7 @@ module Expr =
|
|||
| None -> []
|
||||
| Some args -> args))
|
||||
}
|
||||
| x:LIDENT {if notRef atr then Var x else Ref x}
|
||||
| x:LIDENT {if notRef atr then ignore atr (Var x) else Ref x}
|
||||
|
||||
| {isVoid atr} => %"skip" {materialize atr Skip}
|
||||
|
||||
|
|
@ -679,12 +679,6 @@ module Expr =
|
|||
elif:(%"elif" parse[def][infix][Val] %"then" scope[def][infix][atr][parse def])*
|
||||
els:(%"else" scope[def][infix][atr][parse def])? %"fi"
|
||||
{If (e, the, List.fold_right (fun (e, t) elif -> If (e, t, elif)) elif (match els with Some e -> e | _ -> materialize atr Skip))}
|
||||
(*
|
||||
| %"if" e:parse[def][infix][Val] %"then" the:scope[def][infix][Void][parse def]
|
||||
elif:(%"elif" parse[def][infix][Val] %"then" scope[def][infix][atr][parse def])*
|
||||
=> {isVoid atr} => %"fi"
|
||||
{If (e, the, List.fold_right (fun (e, t) elif -> If (e, t, elif)) elif Skip)}
|
||||
*)
|
||||
| %"while" e:parse[def][infix][Val] %"do" s:scope[def][infix][Void][parse def]
|
||||
=> {isVoid atr} => %"od" {materialize atr (While (e, s))}
|
||||
|
||||
|
|
@ -842,7 +836,7 @@ module Definition =
|
|||
m:(%"local" {`Local} | %"public" e:(%"external")? {match e with None -> `Public | Some _ -> `PublicExtern} | %"external" {`Extern})
|
||||
locs:!(Util.list (local_var m infix expr def)) ";" {locs, infix}
|
||||
| - <(m, orig_name, name, infix')> : head[infix] -"(" -args:!(Util.list0 arg) -")"
|
||||
(body:expr[def][infix'][Expr.Weak (*Void*)] {
|
||||
("{" body:expr[def][infix'][Expr.Weak] "}" {
|
||||
match m with
|
||||
| `Extern -> raise (Semantic_error (Printf.sprintf "body for an external function '%s' can not be specified" orig_name))
|
||||
| _ -> [(name, (m, `Fun (args, body)))], infix'
|
||||
|
|
@ -945,7 +939,7 @@ let eval (_, expr) i =
|
|||
|
||||
(* Top-level parser *)
|
||||
ostap (
|
||||
imports[cmd]: l:$ is:(%"import" !(Util.list (ostap (LIDENT))) -";")* {
|
||||
imports[cmd]: l:$ is:(%"import" !(Util.list (ostap (UIDENT))) -";")* {
|
||||
let is = "Std" :: List.flatten is in
|
||||
let infix =
|
||||
List.fold_left
|
||||
|
|
@ -973,11 +967,11 @@ ostap (
|
|||
is, infix
|
||||
};
|
||||
parse[cmd]:
|
||||
<(is, infix)> : imports[cmd] <(d, infix')> : definitions[infix] expr:!(Expr.parse definitions infix' Expr.Weak (*Void*))? {
|
||||
<(is, infix)> : imports[cmd] <(d, infix')> : definitions[infix] expr:!(Expr.parse definitions infix' Expr.Weak)? {
|
||||
(is, Infix.extract_exports infix'), Expr.Scope (d, match expr with None -> Expr.Skip | Some e -> e)
|
||||
};
|
||||
definitions[infix]:
|
||||
<(def, infix')> : !(Definition.parse infix Expr.basic definitions) <(defs, infix'')> : definitions[infix'] {
|
||||
<(def, infix')> : !(Definition.parse infix (*Expr.basic*) (fun def infix atr -> Expr.scope def infix atr (Expr.parse def)) definitions) <(defs, infix'')> : definitions[infix'] {
|
||||
def @ defs, infix''
|
||||
}
|
||||
| empty {[], infix}
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ let rec eval env (((cstack, stack, glob, loc, i, o) as conf) : config) = functio
|
|||
| BEGIN (_, _, locals, _) -> eval env (cstack, stack, glob, {loc with locals = Array.init locals (fun _ -> Value.Empty)}, i, o) prg'
|
||||
|
||||
| END -> (match cstack with
|
||||
| (prg', loc')::cstack' -> eval env (cstack', Value.Empty :: stack, glob, loc', i, o) prg'
|
||||
| (prg', loc')::cstack' -> eval env (cstack', (*Value.Empty ::*) stack, glob, loc', i, o) prg'
|
||||
| [] -> conf
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue