mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-07 15:28:49 +00:00
Continue massaging Ostap
This commit is contained in:
parent
848fd31dc4
commit
b4ba38a0f7
8 changed files with 84 additions and 31 deletions
|
|
@ -2,25 +2,48 @@ import Ostap;
|
|||
import List;
|
||||
import Fun;
|
||||
|
||||
public fun left (f) {
|
||||
fun (c, x) {
|
||||
fun (y) {
|
||||
f (c (x), y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public fun right (f) {
|
||||
fun (c, x) {
|
||||
fun (y) {
|
||||
c (f (x, y))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--- ops -> fun (x, y) {x `op` y}
|
||||
fun altl (ps) {
|
||||
case ps of
|
||||
p : ps -> foldl (infix |, p, ps)
|
||||
fun altl (level) {
|
||||
case level of
|
||||
[assoc, ps] ->
|
||||
case map (fun (p) {
|
||||
case p of
|
||||
[op, sema] -> op @ lift(assoc (sema))
|
||||
esac
|
||||
}, ps) of
|
||||
p : ps -> foldl (infix |, p, ps)
|
||||
esac
|
||||
esac
|
||||
}
|
||||
|
||||
public fun expr (ops, opnd) {
|
||||
fun inner (ops) {
|
||||
case ops of
|
||||
{} -> opnd
|
||||
{} -> fun (c) {opnd @ c}
|
||||
| level : tl ->
|
||||
local lops = altl (level),
|
||||
next = inner (tl);
|
||||
|
||||
fun this (k) {
|
||||
next |> fun (l) {lops |> fun (op) {this @ fun (r) {op (l, r)}}}
|
||||
| next
|
||||
$ k
|
||||
fun this (c) {
|
||||
next (id) |> fun (l) {lops |> fun (op) {this (op (c, l))}}
|
||||
| next (id) @ c
|
||||
-- $ k
|
||||
}
|
||||
|
||||
this
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue