#!/usr/bin/perl # # script to convert CNF grammars into prefix scheme representations # dan roy, http://web.mit.edu/droy/www # 1: Get command line values: if ($#ARGV !=0) { die "Usage: $0 inputfile\n"; } ($infile) = @ARGV; if (! -r $infile) { die "Can't read input $infile\n"; } if (! -f $infile) { die "Input $infile is not a plain file\n"; } open(INPUT, $infile) || die "Can't input $infile $!"; # Open the file print "(define $infile '(("; while () { $_ =~ s/\n//g; # remove carriage return $_ =~ s/[\)\(]//g; # delete parens $_ =~ s/\^/\)\(/g; # change and's into parens $_ =~ s/~(\S)/\(not $1\)/g; # change ~XX into (not XX) $_ =~ s/ v / /g; # remove wedges (v's) print $_; } print ")))\n"; close(INPUT); # Close the file