Skip to content

Commit

Permalink
remove iexpr code
Browse files Browse the repository at this point in the history
  • Loading branch information
linsyking committed Apr 5, 2023
1 parent 367483b commit 033f35b
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 194 deletions.
1 change: 0 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ hello world
- [Syntax](./docs/Syntax.md)
- [Encoding](./docs/Encoding.md)
- [Double Substitution Lemma](./docs/DSL.md)
- [i Expressions](./docs/i-expr.md)

## Examples

Expand Down
32 changes: 0 additions & 32 deletions docs/i-expr.md

This file was deleted.

132 changes: 132 additions & 0 deletions examples/iexpr.meow
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@

digit(x) {
"1" = "S0";
"2" = "SS0";
"3" = "SSS0";
"4" = "SSSS0";
"5" = "SSSSS0";
"6" = "SSSSSS0";
"7" = "SSSSSSS0";
"8" = "SSSSSSSS0";
"9" = "SSSSSSSSS0";
x
}

exp(x,y) {
var sm = {
" 0" = "";
"S" = `"`+x+`" `;
y
};
var pre = {
"S" = "mul ";
"S0" = "";
y
};
!(pre + sm)
}

nrep(x,p) {
"0" = p;
"1" = p;
"2" = p;
"3" = p;
"4" = p;
"5" = p;
"6" = p;
"7" = p;
"8" = p;
"9" = p;
x
}

len(x) {
var s = nrep(x, "S");
s + "0"
}

ten() {
succ(digit("9"))
}

revdigit(x) {
"S0" = "1";
"SS0" = "2";
"SSS0" = "3";
"SSSS0" = "4";
"SSSSS0" = "5";
"SSSSSS0" = "6";
"SSSSSSS0" = "7";
"SSSSSSSS0" = "8";
"SSSSSSSSS0" = "9";
x
}

head(x) {
var s = {
"$0" = "S";
"$1" = "SS";
"$2" = "SSS";
"$3" = "SSSS";
"$4" = "SSSSS";
"$5" = "SSSSSS";
"$6" = "SSSSSSS";
"$7" = "SSSSSSSS";
"$8" = "SSSSSSSSS";
"$9" = "SSSSSSSSSS";
"$" + x
};
var rep = nrep(s, "");
pred(rep + "0")
}

num(x) {
var nl = pred(len(x));
var hd = head(x);
var hdnum = revdigit(hd);
var remain = {
"$" + hdnum = "";
"$" + x
};
!(if(
eq(len(x), "S0"),
spack(digit(x)),
`add mul "` + hd + `" exp ten "` + nl + `" ` + `num "` + remain + `"`
))
}

spack(x) {
`"` + x + `"`
}

leq(x,y) {
in(x,y)
}

show(x) {
var la = {
"SSSSSSSSSS" = "";
x
};
var rem = {
"SSSSSSSSSS" = "S";
sub(x,la)
};
!(if(
leq(len(x), digit("9")),
spack(revdigit(x)),
`cat show "` + rem + `" revdigit "` + la + `"`
))
}

fib(x) {
if(
eq(x, zero()),
zero(),
!(if(
leq(x, num("2")),
spack(num("1")),
`add fib pred x fib pred pred x`
))
)
}
20 changes: 6 additions & 14 deletions examples/syn.cat
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,14 @@ add x y = let "0" y x
sub x y = let y "0" x
mul x y = let "S" let "0" "" y x
dr x y z = let y x let x y z
encode s = cat cat "_^" let "$" "\$" let "^" "\^" let "\" "\\" s "_$"
decode s = let "\\" "\" let "\$" "$" let "\^" "^" let "_^" "" let "_$" "" s
encode s = cat cat "#$" let "$" "\$" let "#" "\#" let "\" "\\" s "$#"
decode s = let "\\" "\" let "\$" "$" let "\#" "#" let "_#" "" let "_$" "" s
encat x y = cat let "#$" "" x let "$#" "" y
enraw s = let "#$" "" let "$#" "" encode s
enrep s x y = let enraw x y s
rep2 s x xr y yr = decode let "x$" enraw xr let "y$" enraw yr enrep enrep encode s x "x$" y "y$"
eq x y = let encode x "F" let encode y "T" encode x
if c x y = decode let "T$" encode x let "F$" encode y cat c "$"
in x y = not eq y let x "" y
not x = if x false true
ife x = eq x ""
digit x = let "1" "S0" let "2" "SS0" let "3" "SSS0" let "4" "SSSS0" let "5" "SSSSS0" let "6" "SSSSSS0" let "7" "SSSSSSS0" let "8" "SSSSSSSS0" let "9" "SSSSSSSSS0" x
exp x y = ! cat let "S" "mul " let "S0" "" y let " 0" "" let "S" cat cat `"` x `" ` y
nrep x p = let "0" p let "1" p let "2" p let "3" p let "4" p let "5" p let "6" p let "7" p let "8" p let "9" p x
len x = cat nrep x "S" "0"
ten = succ digit "9"
revdigit x = let "S0" "1" let "SS0" "2" let "SSS0" "3" let "SSSS0" "4" let "SSSSS0" "5" let "SSSSSS0" "6" let "SSSSSSS0" "7" let "SSSSSSSS0" "8" let "SSSSSSSSS0" "9" x
head x = pred cat nrep let "$0" "S" let "$1" "SS" let "$2" "SSS" let "$3" "SSSS" let "$4" "SSSSS" let "$5" "SSSSSS" let "$6" "SSSSSSS" let "$7" "SSSSSSSS" let "$8" "SSSSSSSSS" let "$9" "SSSSSSSSSS" cat "$" x "" "0"
num x = ! if eq len x "S0" spack digit x cat cat cat cat cat cat cat `add mul "` head x `" exp ten "` pred len x `" ` `num "` let cat "$" revdigit head x "" cat "$" x `"`
spack x = cat cat `"` x `"`
leq x y = in x y
show x = ! if leq len x digit "9" spack revdigit x cat cat cat cat `cat show "` let "SSSSSSSSSS" "S" sub x let "SSSSSSSSSS" "" x `" revdigit "` let "SSSSSSSSSS" "" x `"`
fib x = if eq x zero zero ! if leq x num "2" spack num "1" "add fib pred x fib pred pred x"
148 changes: 8 additions & 140 deletions examples/syn.meow
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,32 @@ dr(x,y,z) {
encode(s) {
var rep = {
"$" = "\$";
"^" = "\^";
"#" = "\#";
"\" = "\\";
s
};
"_^"+ rep +"_$"
"#$"+ rep +"$#"
}

decode(s) {
var rep = {
"_^" = "";
"_$" = "";
"$#" = "";
"#$" = "";
s
};
"\\" = "\";
"\#" = "#";
"\$" = "$";
"\^" = "^";
rep
}

encat(x,y) {
{"_$"=""; x} + {"_^"=""; y}
{"#$"=""; x} + {"$#"=""; y}
}

enraw(s) {
"_^" = "";
"_$" = "";
"#$" = "";
"$#" = "";
encode(s)
}

Expand Down Expand Up @@ -106,135 +106,3 @@ not(x) {
ife(x) {
eq(x,"")
}

digit(x) {
"1" = "S0";
"2" = "SS0";
"3" = "SSS0";
"4" = "SSSS0";
"5" = "SSSSS0";
"6" = "SSSSSS0";
"7" = "SSSSSSS0";
"8" = "SSSSSSSS0";
"9" = "SSSSSSSSS0";
x
}

exp(x,y) {
var sm = {
" 0" = "";
"S" = `"`+x+`" `;
y
};
var pre = {
"S" = "mul ";
"S0" = "";
y
};
!(pre + sm)
}

nrep(x,p) {
"0" = p;
"1" = p;
"2" = p;
"3" = p;
"4" = p;
"5" = p;
"6" = p;
"7" = p;
"8" = p;
"9" = p;
x
}

len(x) {
var s = nrep(x, "S");
s + "0"
}

ten() {
succ(digit("9"))
}

revdigit(x) {
"S0" = "1";
"SS0" = "2";
"SSS0" = "3";
"SSSS0" = "4";
"SSSSS0" = "5";
"SSSSSS0" = "6";
"SSSSSSS0" = "7";
"SSSSSSSS0" = "8";
"SSSSSSSSS0" = "9";
x
}

head(x) {
var s = {
"$0" = "S";
"$1" = "SS";
"$2" = "SSS";
"$3" = "SSSS";
"$4" = "SSSSS";
"$5" = "SSSSSS";
"$6" = "SSSSSSS";
"$7" = "SSSSSSSS";
"$8" = "SSSSSSSSS";
"$9" = "SSSSSSSSSS";
"$" + x
};
var rep = nrep(s, "");
pred(rep + "0")
}

num(x) {
var nl = pred(len(x));
var hd = head(x);
var hdnum = revdigit(hd);
var remain = {
"$" + hdnum = "";
"$" + x
};
!(if(
eq(len(x), "S0"),
spack(digit(x)),
`add mul "` + hd + `" exp ten "` + nl + `" ` + `num "` + remain + `"`
))
}

spack(x) {
`"` + x + `"`
}

leq(x,y) {
in(x,y)
}

show(x) {
var la = {
"SSSSSSSSSS" = "";
x
};
var rem = {
"SSSSSSSSSS" = "S";
sub(x,la)
};
!(if(
leq(len(x), digit("9")),
spack(revdigit(x)),
`cat show "` + rem + `" revdigit "` + la + `"`
))
}

fib(x) {
if(
eq(x, zero()),
zero(),
!(if(
leq(x, num("2")),
spack(num("1")),
`add fib pred x fib pred pred x`
))
)
}
1 change: 0 additions & 1 deletion src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub enum Expr {
MacAp(MacAp),
Var(String),
Block(Box<Block>),
IExpr(Box<Expr>),
}

#[derive(Debug, Clone)]
Expand Down
1 change: 0 additions & 1 deletion src/expr.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Tokz: Tok = {

VarName: String = {
r"[a-z]?[a-z0-9_]*" => String::from_str(<>).unwrap(),
"!" => String::from_str("!").unwrap()
}

Literal: String = {
Expand Down
Loading

0 comments on commit 033f35b

Please sign in to comment.