stack
· 1.5 KiB · Text
原始文件
Playground
Spawn the stack and the reading head.
start -> ()|
Handle a push.
Continually push symbols until you run into another instruction.
If you can't push any more symbols, and a push is pending, push a separator.
)|push1 -> 1)|push
)|push; -> ;)|
Handle a drop.
Continue erasing symbols until you encounter a separator.
;)|drop; -> |drop;)
1|drop -> |drop
;|drop;) -> ;)|
Handle the last element being dropped.
(|drop;) -> ()|
Handle an empty drop.
()|drop; -> ()|
Handle an addition.
Seek to the separator that divides two runs of symbols.
;)|add; -> |+;)
1|+ -> |+1
When you reach it, eliminate it, then reset.
;|+ -> |>
If there's only one number on the stack, reset.
(|+ -> (|>
Handle a subtraction.
Seek to the separator that divides two runs of symbols.
;)|sub; -> |-;)
1|- -> |-1
When you encounter it, stop and consume one symbol from both sides of the separator.
1;|-1 -> ;|-
If you run out of symbols on the left side of the separator, reset.
(;|- -> (|>
;;|- ->|>
If you run out of symbols on the right side of the separator, reset.
;|-;) -> ;)|
If there's only one number on the stack, reset.
(|- -> (|>
Handle a reset.
Seek back to the instruction stream.
|>1 -> 1|>
|>; -> ;|>
|>) -> )|
::=::
start
push 11;
push 111;
add;
push 1;
sub;
push;
add;
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; |
59 |