All pastes #516875 Raw Edit

Ploximeth

public text v1 · immutable
#516875 ·published 2007-05-28 21:40 UTC
rendered paste body
#!/usr/bin/perl -w
use strict;
my $file = shift || die("$0: Parameters are $0 <filename> [output]\n");
my $out  = shift || "aout.pl";
open(FILE, $file) or die("$0: failed to open $file: $!\n");
open(OUTP, ">$out")  or die("$0: failed to open $out: $!\n");
my $read;
my $line = 0;
while ($read = <FILE>) {
	chomp($read);
	$read =~ s/\t//g;
	if (substr($read, 0, 7) eq "CAN HAS") {
		my $tmp = $read;
		$tmp =~ s/CAN HAS/use/;
		$tmp =~ s/\?/\;/;
		$read = $tmp;
	}
	elsif (substr($read, 0, 7) eq "I HAS A") {
		my $tmp = $read;	
		$tmp =~ s/I HAS A /my \$/; 
		$tmp .= "\;";
		$read = $tmp;
	}
	elsif (substr($read, 0, 7) eq "VISIBLE") {
		my $tmp = $read;
		my $rest = (split(/\s/, $tmp))[1];
		$tmp =~ s/VISIBLE/print/;
		if (substr($tmp, 6, 1) ne "\"") {
			$tmp = "print \$".$rest;
		}
		$tmp .= ".\"\\n\"\;";
		$read = $tmp;
	}
	elsif (substr($read, 0, 2) eq "UP") {
		my $tmp = $read;
		$tmp =~ s/\!\!/ /;
		my $u = (split(/\s/, $tmp))[2];
		my $b = (split(/\s/, $tmp))[1];
		$tmp =~ s/UP//;
		$tmp = "\$".$b;
		$tmp .= " += $u\;";
		$read = $tmp;
	}
	elsif (substr($read, 0, 2) eq "IZ") {
		my $vt = (split(/\s/, $read))[1];
		my $ch = (split(/\s/, $read))[2];
		my $te = (split(/\s/, $read))[4];
		my $la = (split(/\s/, $read))[-1];
		print "check for $la\n";
		$la = "die(\"\\n\")" if ($la eq "KTHXBYE");
		chop($te);
		if ($ch eq "BIGGER") {
			$read = "$la if (\$".$vt." > $te-2)\;";
		}
		elsif ($ch eq "SMALLER") {
			$read = "$la if (\$".$vt." < $te+2)\;";
		}
		elsif ($ch eq "EQUAL") {
			$read = "$la if (\$".$vt." eq $te)\;";
		}
		else {
			die("Syntax error on line $line, near IZ $vt $ch <= here\n");
		}
	}
	$read =~ s/IM OUTTA YR LOOP/\}/;
	$read =~ s/IM IN YR LOOP/while \(1\) \{/;
	$read =~ s/HAI/\#\!\/usr\/bin\/perl \-w/;
	$read =~ s/KTHXBAI/KTHXBYE/; # proper
	$read =~ s/KTHXBYE/die(\"END OF FILE LOL\")\;/;
	$line++;
	print OUTP $read."\n";
}
		
close(FILE) or die("$0: failed to close $file: $!\n");
close(OUTP) or die("$0: failed to close $out: $!\n");

__END__;

HAI
CAN HAS STDIO?
I HAS A VAR
IM IN YR LOOP
	UP VAR!!1
	VISIBLE VAR
	IZ VAR BIGGER THAN 10? KTHXBYE
IM OUTTA YR LOOP
KTHXBYE