Utoljára aktív 1741195905

A stack, implemented in string rewrite rules.

wryl gist felülvizsgálása 1741195905. Revízióhoz ugrás

1 file changed, 58 insertions

stack(fájl létrehozva)

@@ -0,0 +1,58 @@
1 + Spawn the stack and the reading head.
2 + start -> ()|
3 +
4 + Handle a push.
5 + Continually push symbols until you run into another instruction.
6 + If you can't push any more symbols, and a push is pending, push a separator.
7 + )|push1 -> 1)|push
8 + )|push; -> ;)|
9 +
10 + Handle a drop.
11 + Continue erasing symbols until you encounter a separator.
12 + ;)|drop; -> |drop;)
13 + 1|drop -> |drop
14 + ;|drop;) -> ;)|
15 + Handle the last element being dropped.
16 + (|drop;) -> ()|
17 + Handle an empty drop.
18 + ()|drop; -> ()|
19 +
20 + Handle an addition.
21 + Seek to the separator that divides two runs of symbols.
22 + ;)|add; -> |+;)
23 + 1|+ -> |+1
24 + When you reach it, eliminate it, then reset.
25 + ;|+ -> |>
26 + If there's only one number on the stack, reset.
27 + (|+ -> (|>
28 +
29 + Handle a subtraction.
30 + Seek to the separator that divides two runs of symbols.
31 + ;)|sub; -> |-;)
32 + 1|- -> |-1
33 + When you encounter it, stop and consume one symbol from both sides of the separator.
34 + 1;|-1 -> ;|-
35 + If you run out of symbols on the left side of the separator, reset.
36 + (;|- -> (|>
37 + ;;|- ->|>
38 + If you run out of symbols on the right side of the separator, reset.
39 + ;|-;) -> ;)|
40 + If there's only one number on the stack, reset.
41 + (|- -> (|>
42 +
43 + Handle a reset.
44 + Seek back to the instruction stream.
45 + |>1 -> 1|>
46 + |>; -> ;|>
47 + |>) -> )|
48 +
49 + ::=::
50 +
51 + start
52 + push 11;
53 + push 111;
54 + add;
55 + push 1;
56 + sub;
57 + push;
58 + add;
Újabb Régebbi