Skip to content

Commit

Permalink
feat:
Browse files Browse the repository at this point in the history
- implement numbers in meow
  • Loading branch information
linsyking committed Apr 4, 2023
1 parent ec3b20f commit f3f97bb
Show file tree
Hide file tree
Showing 11 changed files with 417 additions and 385 deletions.
1 change: 0 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ cargo run ./examples/syn.meow
Examples:

```
no error found.
> true()
T
> false()
Expand Down
24 changes: 0 additions & 24 deletions examples/exp.meow

This file was deleted.

50 changes: 0 additions & 50 deletions examples/math.meow

This file was deleted.

63 changes: 27 additions & 36 deletions examples/syn.cat
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
true() {"T"}

false() {"F"}

zero() {"0"}

succ(x) {cat "S" x}

pred(x) {
let "S0" "0" x
}

dr(x,y,z) {
let y x let x y z
}

encode(s) {
cat cat "_^" let "$" "\$" let "^" "\^" let "\" "\\" s "_$"
}

eq(x,y) {
let encode x "F" encode y "T" encode "x"
}

if(c,x,y) {
decode let "T$" encode x let "F$" encode y cat c "$"
}

in(x,y) {
eq y let x "" y
}

test2() {
let "bb" "g" cat "bc" "bc"
}

true = "T"
false = "F"
zero = "0"
succ x = cat "S" x
pred x = let "S0" "0" x
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
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 `"`
139 changes: 130 additions & 9 deletions examples/syn.meow
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ pred(x) {
x
}

add (x,y) {
"0" = y;
x
}

sub (x,y) {
y = "0";
x
}

mul(x,y) {
"S" = {"0"=""; y};
x
}

dr(x,y,z) {
y = x;
x = y;
Expand Down Expand Up @@ -56,19 +71,125 @@ if(c,x,y) {
}

in(x,y) {
eq(y,{x=""; y})
}

encode_add(s,x) {
x = "\" + x;
s
not(eq(y,{x=""; y}))
}

decode_add(s,x) {
"\" + x = x;
s
not(x) {
if(x, false(), true())
}

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 + `"`))
}
7 changes: 0 additions & 7 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,3 @@ pub enum Tok {
Var(String),
Literal(String),
}

#[test]
fn tt() {
// let dd = Stmt{name: "ss", args: [], }
let mut xx = vec![String::from("sdsds")];
xx.push(String::from("sdsd"));
}
Loading

0 comments on commit f3f97bb

Please sign in to comment.