#!/usr/bin/perl

if (@ARGV != 1) {
    print STDERR "Usage: mkwordlist.pl <GF grammar>\n";
    exit 2;
}

my @words = allwords($ARGV[0]);

foreach (@words) {
    print "$_\n";
}


sub allwords {
    my $grammar = $_[0];

    my @r = ();

    open GF, "echo 'pg -printer=words' | gf -s -batch -nocpu '$grammar' |";
    while (<GF>) {
	if (!/^\s*$/) {
	    chomp;
	    push @r, split;
	}
    }
    close GF;

    return @r;
}
