Execute SNUSP/Perl: Difference between revisions

Content added Content deleted
(Perl implementation of SNUSP)
 
mNo edit summary
Line 36: Line 36:
print qq[do "\Q$include\E" or die;\n];
print qq[do "\Q$include\E" or die;\n];


my %commands;
my %commands = (
$commands{'<'} = q{ --$col; $col < 0 and die; };
'<' => q{ --$col; $col < 0 and die; },
$commands{'>'} = q{ ++$col };
'>' => q{ ++$col },
$commands{'+'} = q{ ++$data[$row][$col] };
'+' => q{ ++$data[$row][$col] },
$commands{'-'} = q{ --$data[$row][$col] };
'-' => q{ --$data[$row][$col] },
$commands{'.'} = q{ print chr $data[$row][$col] };
'.' => q{ print chr $data[$row][$col] },
$commands{','} = q{ goto (schedule(readchar($data[$row][$col]) ? 'NEXT' : 'REDO')) };
',' => q{ goto (schedule(readchar($data[$row][$col]) ? 'NEXT' : 'REDO')) },
# /, \, and ! are implemented in the main loop
# /, \, and ! are implemented in the main loop


$commands{'?'} = q{ goto (schedule($data[$row][$col] ? 'NEXT' : 'SKIP')) };
'?' => q{ goto (schedule($data[$row][$col] ? 'NEXT' : 'SKIP')) },


$commands{'@'} = q{ push @st, 'SKIP' };
'@' => q{ push @st, 'SKIP' },
$commands{'#'} = q{ goto (pop @st) };
'#' => q{ goto (pop @st) },


$commands{':'} = q{ --$row; $row < 0 and die };
':' => q{ --$row; $row < 0 and die },
$commands{';'} = q{ ++$row };
';' => q{ ++$row },
$commands{'%'} = q{ $_ = int rand(1 + $_) for $data[$row][$col] };
'%' => q{ $_ = int rand(1 + $_) for $data[$row][$col] },
# & is implemented in the main loop.
# & is implemented in the main loop.
);


tr/;{}// or s/(\s*)\z/;$1/ for values %commands;
tr/;{}// or s/(\s*)\z/;$1/ for values %commands;