Continue massaging Ostap

This commit is contained in:
Dmitry Boulytchev 2020-01-30 23:36:15 +03:00
parent 848fd31dc4
commit b4ba38a0f7
8 changed files with 84 additions and 31 deletions

View file

@ -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