Extended pattern-matching

This commit is contained in:
Dmitry Boulytchev 2018-11-06 00:21:38 +03:00 committed by danyaberezun
parent 9569598775
commit 155ad46ec2
10 changed files with 253 additions and 45 deletions

View file

@ -7,9 +7,9 @@ RC=../src/rc.opt
check: $(TESTS)
$(TESTS): %: %.expr
$(RC) $< && cat $@.input | ./$@ > $@.log && diff $@.log orig/$@.log
cat $@.input | $(RC) -i $< > $@.log && diff $@.log orig/$@.log
cat $@.input | $(RC) -s $< > $@.log && diff $@.log orig/$@.log
@$(RC) $< && cat $@.input | ./$@ > $@.log && diff $@.log orig/$@.log
@cat $@.input | $(RC) -i $< > $@.log && diff $@.log orig/$@.log
@cat $@.input | $(RC) -s $< > $@.log && diff $@.log orig/$@.log
clean:
rm -f test*.log *.s *~ $(TESTS)

View file

@ -5,3 +5,9 @@
2
3
5
5
1
2
3
4
5

View file

@ -0,0 +1,17 @@
> 1
1
1
1
1
2
3
100
3
2
1
6
5
4
3
2
1

View file

@ -27,4 +27,12 @@ case `a (1, 2, 3, 4, 5) of
| `a (_, _, _) -> write (3)
| `a (_, _, _, _) -> write (4)
| `a (_, _, _, _, _) -> write (5)
esac
esac;
write (`a (1, 2, 3, 4, 5).length);
write (`a (1, 2, 3, 4, 5)[0]);
write (`a (1, 2, 3, 4, 5)[1]);
write (`a (1, 2, 3, 4, 5)[2]);
write (`a (1, 2, 3, 4, 5)[3]);
write (`a (1, 2, 3, 4, 5)[4])

72
regression/test047.expr Normal file
View file

@ -0,0 +1,72 @@
fun collect_ints_acc (v, tail) local i {
case v of
a@#unboxed -> return `cons (a, tail)
| #string -> return tail
| _ ->
for i := 0, i < v.length, i := i + 1 do
tail := collect_ints_acc (v[i], tail)
od;
return tail
esac
}
fun collect_ints (v) {
return 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/test047.input Normal file
View file

@ -0,0 +1 @@
0