User:Zip/Thue/CT

From Esolang
Jump to navigation Jump to search

CT interpreter in Thue.

NOTE: Assumes that lines before the final ::= that don't contain ::= are comments. This is the behavior of Delic's Thue interpreter, but probably most interpreters don't do this. Just remove the comment lines if you want to run it in a different interpreter.

Interprets a cyclic tag program

Create command
|;::=d/:
|0::=./o
|1::=!/i
Move to end
o0::=0o
o1::=1o
o;::=;o
i0::=0i
i1::=1i
i;::=;i
:0::=0:
:1::=1:
:;::=;:
Move back
o]::=O]
oO::=Oo
iO::=Oi
:O::=O:
i]::=I]
oI::=Io
iI::=Ii
:I::=I:
:]::=']
o'::='o
i'::='i
:'::=':
Convert back to binary string
|O::=|cO
|I::=|cI
|'::=|c'
cO::=0c
cI::=1c
c'::=;c
c]::=]
Delete left-most data bit
0d::=d0
1d::=d1
[d0::=[r
[d1::=[r
1* instructions
0.::=.0
1.::=.1
[.0::=[r
[.1::=[o
o/::=0|

0!::=!0
1!::=!1
[!0::=[0r
[!1::=[1i
i/::=1|

Shared between commands
r/::=|
r0::=0r
r1::=1r

Input program here
PROGRAM::=1;
Input first bitstream here
BITS::=1
::=
[BITS|PROGRAM]