#! /usr/bin/perl

my $previous = "FIRST";
my $start = 0;
for (<>) {
	chomp;
	if (m/^DICT_BEGIN/) {
		$start = 1;
		print "$_\n";
		next;
	} elsif ($start == 0) {
		print "$_\n";
		next;
	}

	if (m/(CODE_BEGIN)\s+([^,\s]+)\s*,\s*([^\s]+)\s*,\s*([^,\s]+),.*$/) {
		print "\t$1\t$2, $3, $4, $previous\n";
		$previous = $4;
		next;
	} elsif (m/(COLON_BEGIN)\s+([^\s,]+)\s*,\s*([^\s]+)\s*,\s*([^,\s]+),.*$/) {
		print "\t$1\t$2, $3, $4, $previous\n";
		$previous = $4;
		next;
	} elsif (m/(VARIABLE)\s+([^\s,]+)\s*,\s*([^\s]+)\s*,\s*([^,\s]+),.*$/) {
		print "\t$1\t$2, $3, $4, $previous\n";
		$previous = $4;
		next;
	} elsif (m/(ALIAS)\s+([^,\s]+)\s*,\s*([^\s]+)\s*,\s*([^,\s]+)\s*,\s*([^,\s]+),.*$/) {
		print "\t$1\t$2, $3, $4, $5, $previous\n";
		$previous = $4;
		next;
	} else {
		print "$_\n";
	}
}
