mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-10 00:38:47 +00:00
Intermediate; pattern matching in x86
This commit is contained in:
parent
34767b9dcb
commit
1f1ef2ce57
7 changed files with 184 additions and 303 deletions
|
|
@ -7,7 +7,7 @@ RC=../src/rc.opt
|
|||
check: $(TESTS)
|
||||
|
||||
$(TESTS): %: %.expr
|
||||
#@$(RC) $< && cat $@.input | ./$@ > $@.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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
fun append (x, y) {
|
||||
case x of
|
||||
`nil -> return y
|
||||
| `cons (h, t) -> return `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,31 +0,0 @@
|
|||
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))
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue