Skip to content

Commit

Permalink
docs:
Browse files Browse the repository at this point in the history
- change codes for MR and encoding
  • Loading branch information
linsyking committed Apr 5, 2023
1 parent b986dac commit aeaf73b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 29 deletions.
5 changes: 4 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

Meow lang is a programming language that compiles to *catlet*, another language that is hard to read but easy to execute. Meow's syntax is easier to read than catlet, but meow and catlet are equivalent.

(It's called *catlet* because the only available two keywords are `cat` and `let`)
(It's called *catlet* because the only available two keywords are `cat` and `let`, *currently*)

Its main design purpose is to do experiments with "string substitution".

## Formal Definition

Currently the definition of substitution of strings are defined by the built-in `replace` function of `String`.

It's not allowed to do $[X/""]Y$ (replace empty string with some string).

## Concepts

There are **no** functions in Meow. Instead, we have *macros*. A macro is a piece of code that can be evaluated to a string.
Expand Down Expand Up @@ -42,6 +44,7 @@ hello world
- [Syntax](./docs/Syntax.md)
- [Encoding](./docs/Encoding.md)
- [Double Substitution Lemma](./docs/DSL.md)
- [Multiple Replacement](./docs/MR.md)

## Examples

Expand Down
24 changes: 7 additions & 17 deletions docs/Encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,28 @@ We have to first implement the `encode` and `decode` macro to help us.

Encoding means to encode a string into another string that has some special properties that we can use.

We define it by this:

$$
\mathtt{encode}(s) = \mathtt{"\_\^{\,}"} + (\mathtt{["\backslash \backslash"/"\backslash"]["\backslash \$"/"\$"]["\backslash \^{\,}"/"\^{\,}"]}s) + \mathtt{"\_\$"}
$$

We can prove the following results:

1. $|x|=1 \land x \neq \mathtt{"\backslash"} \Rightarrow $ $x\mathtt{"\^{\,}"} \not\subset \mathtt{["\backslash \backslash"/"\backslash"]["\backslash \$"/"\$"]["\backslash \^{\,}"/"\^{\,}"]}s$, $x\mathtt{"\$"} \not\subset \mathtt{["\backslash \backslash"/"\backslash"]["\backslash \$"/"\$"]["\backslash \^{\,}"/"\^{\,}"]}s$

## Code

```meow
encode(s) {
var rep = {
"\" = "\\";
"$" = "\$";
"^" = "\^";
"#" = "\#";
"\" = "\\";
s
};
"_^"+ rep +"_$"
"#$"+ rep +"$#"
}
decode(s) {
var rep = {
"_^" = "";
"_$" = "";
"$#" = "";
"#$" = "";
s
};
"\$" = "$";
"\^" = "^";
"\\" = "\";
"\#" = "#";
"\$" = "$";
rep
}
```
16 changes: 10 additions & 6 deletions docs/Multiple Replacement.md → docs/MR.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ First, we have to make sure that the multiple strings are all **independent**. O
Implementation code for 2 strings:

```meow
encat(x,y) {
{"#$"=""; x} + {"$#"=""; y}
}
enraw(s) {
"_^" = "";
"_$" = "";
"#$" = "";
"$#" = "";
encode(s)
}
Expand All @@ -32,11 +36,11 @@ enrep(s,x,y) {
}
rep2(s,x,xr,y,yr) {
var repx = enrep(encode(s),x,"x$");
var repy = enrep(repx,y,"y$");
var repx = enrep(encode(s),x,"x#");
var repy = enrep(repx,y,"y#");
decode({
"x$" = enraw(xr);
"y$" = enraw(yr);
"x#" = enraw(xr);
"y#" = enraw(yr);
repy
})
}
Expand Down
1 change: 0 additions & 1 deletion examples/syn.cat
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ 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
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#"
Expand Down
4 changes: 0 additions & 4 deletions examples/syn.meow
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ decode(s) {
rep
}

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

enraw(s) {
"#$" = "";
"$#" = "";
Expand Down

0 comments on commit aeaf73b

Please sign in to comment.