--- a/parser Fri Nov 27 23:12:41 2009 +0100
+++ b/parser Mon Nov 30 22:12:02 2009 +0100
@@ -1,14 +1,43 @@
#!/usr/bin/perl -w
+# Copyright (c) 2009, Tomas Zeman <tzeman@volny.cz>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted providing that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+$main::VERSION = "1.0";
+
use strict;
use Parse::RecDescent;
use Data::Dumper;
use Storable;
+use Getopt::Std;
-my $grammar_file = shift;
-my $storable = shift; # optional
+my $opts = {};
+getopts("do:g:", $opts);
+
+my $grammar_file = $opts->{g};
unless (defined $grammar_file) {
- print "Usage: $0 grammar_file\n";
+ HELP_MESSAGE();
exit 1;
}
@@ -37,7 +66,28 @@
$content = <>;
}
-$::res = {};
+$::res = {}; # parse tree result
my $p_res = $parser->file($content);
+my $storable = $opts->{o};
store($::res, $storable) if (defined $storable && length($storable) > 0);
-print Dumper $::res;
+print Dumper $::res if ($opts->{d});
+
+
+sub main::VERSION_MESSAGE {
+ my $fh = shift;
+ print $fh "parser version $main::VERSION - Copyright 2009 Tomas Zeman\n";
+}
+
+sub main::HELP_MESSAGE {
+ print <<EOF;
+Usage: parser [ -d ] [ -o data ] -g grammar_file
+
+ -o data store parse tree into file (using Storable module)
+ -d dump parse tree to stdout
+ -g grammar_file
+ file containing parse grammar
+
+EOF
+}
+
+