# -*- mode:perl; fill-column:80 -*- # Decoder for debug output from the Grill Tag interpreter. # # This program is used when the Grill Tag interpreter is being used to run a # program that was compiled from Genera Tag. For each block of 7a bits, it # translates that block to its corresponding meaning in the Genera Tag program # (although using symbol indexes rather than names). The intention is to make # it easy to determine that a Grill Tag program is doing the same thing as the # Genera Tag program it was compiled from. # # The abbreviations used are: # - "[y]" (where y is an integer): # 14*y+7 zeroes; # a grill with a-3 ones; # a grill with 7 ones; # a grill with a-4 ones; # 3*a-14*y-10 zeroes. # - "" (where y is an integer): # 1 zero; # a grill with 14*y+7 ones; # a grill with 3 ones; # a grill with 3*a-14*y-10 ones; # a-4 zeroes. # - "|y" (where y is an integer): # 1 zero; # a grill with 14*y+7 ones; # a grill with 3 ones; # a grill with 3.5*a-14*y-12 ones. # - "-": # 7*a zeroes. # - "+": # "10" repeated 3.5*a times. # - "+>": # "10" repeated 3*a+4 times, then a-4 zeroes. # - "(v w x y z)": # v zeroes; # a grill with w ones; # a grill with x ones; # a grill with y ones; # z zeroes. # - "(?)": # anything else. # # The value of a is determined by assuming that the first grill seen has a-3 # ones. use strict; use warnings; use 5.016; my $a; my $all_zeroes; my $all_grill; my $mostly_grill; while (<>) { s/[^01]//g; # Determine a, if we don't know it already. unless (defined $a) { /^0++((?:10)++)/ or die "Could not decode first grill"; my $first_grill = $1; $first_grill =~ s/0//g; $a = 3 + length $first_grill; $a % 2 and die "The value of a ($a) is apparently odd?"; $all_zeroes = "0" x (7 * $a); $all_grill = "10" x (7 * $a / 2); $mostly_grill = ("10" x (3 * $a + 2)) . ("0" x ($a - 4)); } while (my $chunk = substr $_, 0, 7*$a, "") { if ($chunk =~ /^(0++)((?:10)++)0((?:10)++)0((?:10)++)(0*+)$/) { my $v = length($1) - 1; my $w = length($2) / 2; my $x = length($3) / 2; my $y = length($4) / 2; my $z = length($5); if ($v % 14 == 7 && $w == $a - 3 && $x == 7 && $y == $a - 4 && $v + $z == 3 * $a - 3) { print "[", ($v - 7) / 14, "]"; } elsif ($v == $a - 3 && $w % 14 == 7 && $x == 3 && $w + $y == 3 * $a - 3 && $z == 0) { print "<", ($w - 7) / 14, "|"; } elsif ($v == 1 && $w % 14 == 7 && $x == 3 && $w + $y == 3 * $a - 3 && $z == $a-4) { print "|", ($w - 7) / 14, ">"; } elsif ($v == 1 && $w % 14 == 7 && $x == 3 && $w + $y == 7 * $a / 2 - 5) { print "|", ($w - 7) / 14; } else { print "($v $w $x $y $z)"; } } elsif (length($chunk) != 7*$a) { print "(? length ", length($chunk), ")"; } elsif ($chunk eq $all_zeroes) { print "-"; } elsif ($chunk eq $all_grill) { print "+"; } elsif ($chunk eq $mostly_grill) { print "+>"; } else { # print "\n\n$chunk\n"; # die; print "(?)"; } } print "\n"; }