Fixed and recompiled version of Madk’s (http://esolangs.org/wiki/User:Madk) original Cardinal interpreter.
The original Cardinal
interpreter contained a few faulty implemented and missing instructions. I corrected all errors, so the interpreter should run according to the language specification.
I added a handful of graphical interpreter exe files with different timespans between each step, just for the viewing pleasure.
You can download the original interpreter here from the Wayback Machine
All credit to the inventor of Cardinal, Madk. I only fixed the rather crippling errors in the source code and changed the original color scheme of the graphical interpreter.
(cleaned up by Manuel Lohmann)
Version 1: 2015-07-01
##How to use
You can simply drag and drop any Cardinal program text file on one of the
.exe
files for execution. The executables with gfx
in their names
are gui versions of the console version cardinal.exe
; very useful for
debugging or just to enjoy watching the program during execution.
The gfx
versions come in several flavors that execute each program step
at different speeds from 5ms/step to 1000ms/step.
To start a program from the console, e.g. enter
cardinal.exe program.txt
cardinal_50ms_gfx.exe program.txt
The interpreter opens a graphical window to display the progam progress, and if the interpreter was started via drag-and-drop, a console window gets opened automatically.
Each pointer has a blue arrow symbol at the bottom, showing its current movement direction, a red inactive value in the middle, and a green active value at the top.
% : start location for pointers, spreading out in all
cardinal directions (hence the name).
example:
^
^
% <%> < % >
v
v
Use as many start points as you need.
@ : terminate program
all pointers gone: terminate program
^ v < > : change pointer direction
U D L R : active value >0 ? set direction : keep direction
J : active value >0 ? skip next instruction : move normally
j : active value =0 ? skip next instruction : move normally
O : clockwise rotation of pointer direction
o : counterclockwise rotation of pointer direction
# : copy pointer into every direction except the direction where
the pointer came from
example:
^
># > #>
v
/ \ : reflect pointer direction at 45°, flip reflector to opposite state
example:
^
> / >/ > \
N : reflect L/R moving pointers, Let U/D pointers travel uninterruptedly
example:
> N >N > < <N < N
Z : reflect U/D moving pointers, let L/R pointers travel uninterruptedly
example:
v ^
v ^
Z Z v Z Z
I : reflect pointers coming from all directions to their opposite direction.
Works like N and Z combined.
V A { } : remove pointers coming from N S W E
example:
v
v
v
> } > } >} } V V V V
$ : set pointer to new coordinates X,Y = active value,inactive value
while keeping current direction
8 : trap pointer for three steps before it moves on
x : remove pointer
? : active value =0 ? remove pointer : move normally
! : active value !=0 ? remove pointer : move normally
~ : flip active/inactive value, active becomes inactive and vice versa
+ - : increment/decrement active value
t : active = active * inactive
d : active = active / inactive
* : active = active + inactive
' : active = active - inactive
M : active = active % inactive (MOD)
& : active = active AND inactive
| : active = active OR inactive
X : active = active XOR inactive
= : inactive = active
0 : set active to 0
n u ( ) : drop active value into direction the arc of the symbol is pointing to,
then set active value to the value of the character on the opposite side of the arc.
examples:
72 72 | 72 35 | 35 35 35 35 35 | 35 72 | 72 72 72
0 # 0# | 0 0 | #0 # 0 # 0 0 0 | 0 0 | #0 # 0 # 0
> u >u | > > | u> u > n > > n >n | > > | n> n > n >
| H H | H H H H H | H H | H H H
H=ASCII(72), #=ASCII(35)
` : toggle if pointer gets removed after dropping value, trying to pass n u ( )
example:
72 72 72
0 0 0
> > >
u u u u
H H
: : active = read value from console
. : console output = active value
; : print newline
, : console = ASCII of active value
" : toggle console output