mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-15 19:28:47 +00:00
S-expressions and pattern matching
This commit is contained in:
parent
958bf482a8
commit
800d976b8e
8 changed files with 148 additions and 88 deletions
|
|
@ -9,7 +9,7 @@ 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
|
||||
cat $@.input | $(RC) -s $< > $@.log && diff $@.log orig/$@.log
|
||||
|
||||
clean:
|
||||
rm -f test*.log *.s *~ $(TESTS)
|
||||
|
|
|
|||
6
regression/orig/test039.log
Normal file
6
regression/orig/test039.log
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
> 1
|
||||
1
|
||||
1
|
||||
1
|
||||
0
|
||||
0
|
||||
|
|
@ -21,4 +21,3 @@ printList (x);
|
|||
printList (y);
|
||||
printList (append (x, y));
|
||||
printList (append (y, x))
|
||||
|
||||
|
|
|
|||
31
regression/test039.expr
Normal file
31
regression/test039.expr
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
fun insert (t, x) {
|
||||
case t of
|
||||
`leaf -> return `node (x, `leaf, `leaf)
|
||||
| `node (y, l, r) -> if x > y
|
||||
then return `node (y, insert (l, x), r)
|
||||
else return `node (y, l, insert (r, x))
|
||||
fi
|
||||
esac
|
||||
}
|
||||
|
||||
fun find (t, x) {
|
||||
case t of
|
||||
`leaf -> return 0
|
||||
| `node (y, l, r) -> if x == y then return 1
|
||||
elif x > y then return find (l, x)
|
||||
else return 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/test039.input
Normal file
1
regression/test039.input
Normal file
|
|
@ -0,0 +1 @@
|
|||
0
|
||||
Loading…
Add table
Add a link
Reference in a new issue