equal
deleted
inserted
replaced
|
1 #!/usr/bin/perl -w |
|
2 |
|
3 use strict; |
|
4 use Parse::RecDescent; |
|
5 use Data::Dumper; |
|
6 |
|
7 my $grammar_file = shift; |
|
8 unless (defined $grammar_file) { |
|
9 print "Usage: $0 grammar_file\n"; |
|
10 exit 1; |
|
11 } |
|
12 |
|
13 unless (-f $grammar_file) { |
|
14 die "Grammar file $grammar_file does not exit"; |
|
15 } |
|
16 |
|
17 my $grammar = ''; |
|
18 { |
|
19 open G, $grammar_file; |
|
20 local $/; |
|
21 $grammar = <G>; |
|
22 close G; |
|
23 } |
|
24 |
|
25 # Enable warnings within the Parse::RecDescent module. |
|
26 $::RD_ERRORS = 1; # Make sure the parser dies when it encounters an error |
|
27 $::RD_WARN = 1; # Enable warnings. This will warn on unused rules &c. |
|
28 $::RD_HINT = 1; # Give out hints to help fix problems. |
|
29 |
|
30 my $parser = Parse::RecDescent->new($grammar); |
|
31 |
|
32 my $content = ''; |
|
33 { |
|
34 local $/; |
|
35 $content = <>; |
|
36 } |
|
37 |
|
38 $::res = {}; |
|
39 my $p_res = $parser->file($content); |
|
40 |
|
41 #print Dumper $p_res; |
|
42 |
|
43 print Dumper $::res; |