Szewczyk notation for Minsky machine
Jump to navigation
Jump to search
Szewczyk notation is a tool invented by Kamila Szewczyk of thought useful when describing counter machines. Simply put, this notation for Minsky machines is a minimalistic representation of its capabilities.
Syntax
Minsky machine code is represented by a list of pairs separated from each other. The text representation looks like this:
a0 a1 b0 b1 c0 c1 ...
Each row is given an unique, consecutive ID. The notation supports two instructions:
inc rX
=>X -1
: increment registerrX
dec rX, Y
=>X Y
: decrement registerrX
ifrX > 0
, else jump to row with IDY
.
Properties
Numbers can be assumed of infinite precision. The ID's are 0 indexed and registers are initialized to 0
Examples
1 -1 1 1 1 1
Interpreter
A tiny, 321 byte Perl emulator for the Minsky machine code (assuming Szewczyk notation).
#!/usr/bin/perl use bignum;my(@a,@c,$d);push(@a,0)for(1..$ARGV[0]);s/(-?[0-9]+)[ \t]+(-?[0-9]+)/push(@{$c[$d++]},($1,$2));/ge while(<STDIN>); for($d=0;$d<@c;$d++){$a[$c[$d][0]]++if$c[$d][1]==-1;if($c[$d][1]>=0){$d=$c[$d][1]-1if($a[$c[$d][0]]==0);$a[$c[$d][0]]--if($a[ $c[$d][0]]>0);}}print((shift@a)."\n")for(1..$ARGV[0]);
Extensions
An I/O extension can be implemented as x1
equal to -2
(for output) and -3
(for input) to a given register.