--- /dev/null
+#!/usr/bin/perl
+use strict;
+
+#Input data for conversion
+my $data;
+open ( $data , "< automake.dot" );
+
+#Storing parser table
+my @table;
+
+#Stores labels of nodes.
+my @labels;
+
+my $acceptstate = 0;
+
+while( <$data> )
+{
+ if(m/label=\"(.*)\"/)
+ {
+ my $token = $1;
+ if(m/(\d+) -> (\d+)/)
+ {
+ if($token eq "\$end")
+ {
+ $table[ $1 ]{ end } = $2;
+ }
+ else
+ {
+ $table[ $1 ]{ $token } = $2;
+ }
+ }
+ elsif(m/State (\d+)\\n/)
+ {
+ $labels[ $1 ] = $token;
+ }
+ }
+ elsif(m/(\d+) -> "\d+R(\d+)"/)
+ {
+ my $state_number = $1;
+ my $production_number = $2;
+ $labels[$state_number] =~ m/$production_number (.+): (.+)\.\\l/;
+ if($1 eq "\$accept")
+ {
+ $table[ $state_number ] = {};
+ $acceptstate = $state_number;
+ }
+ else
+ {
+ $table[ $state_number ]{ reduce } = [scalar( split( /\s+/ , $2 )) , " \\&$1" ];
+ }
+ }
+}
+
+#Output file
+my $ptable;
+open ( $ptable , ">ParserTable.pm" );
+
+print $ptable "package ParserTable;\n\nuse Exporter;\nuse Tree;\n\nour \@ISA=qw(Exporter);\nour \@Export=qw(\@table \$accept);\n\nour \$accept=$acceptstate;\n\n";
+
+my @data;
+
+for my $href ( @table )
+{
+ my @hashval;
+ for my $key ( keys %$href )
+ {
+ if($key eq "reduce")
+ {
+ push @hashval , sprintf( "$key => [%s]",join(", ",@{ $href -> { $key } }));
+ }
+ else
+ {
+ push @hashval, sprintf( "$key => %s",$href -> { $key });
+ }
+ }
+ push @data, sprintf( "{%s}" , join(", " , @hashval ));
+}
+
+print $ptable sprintf( "our \@table=(\n\t\t%s\n);" , join ( ",\n\t\t" , @data ));
\ No newline at end of file
use Exporter;
use Tree;
-our @ISA = qw(Exporter);
-our @Export = qw(@table $accept);
+our @ISA=qw(Exporter);
+our @Export=qw(@table $accept);
-#Stores the state number where the input is accepted
our $accept=9;
-# Stores the state diagram. Its an array of hashes. Each index corresponds
-# to ith state. Every key in hash corresponds to a token, value corresponds
-# to next state. reduce key specifies the reduction of token. Its an array
-# consisting of number of elements to be reduced and a reference to a function
-# to create a node.
our @table=(
- {value => 1, input => 2, stmts => 3, stmt => 4, lhs => 5, optionlist => 6},
- {":" => 7, "_" => 8},
+ {value => 1, stmts => 3, stmt => 4, lhs => 5, optionlist => 6, input => 2},
+ {':' => 7, '_' => 8},
{end => 9},
- {value => 1, lhs => 5, optionlist => 6, stmt => 10, reduce => [1, \&input]}, #input : stmts
- {"\n" => 11},
- {"=" => 12},
- {value => 13, PROGRAMS => 14, LIBRARIES => 15, LTLIBRARIES => 16, LISP => 17, PYTHON => 18, JAVA => 19, SCRIPTS => 20, DATA => 21, HEADERS => 22, MASN => 23, TEXINFOS => 24, primaries => 25},
+ {reduce => [1, \&input], optionlist => 6, lhs => 5, stmt => 10, value => 1},
+ {newline => 11},
+ {'=' => 12},
+ {HEADERS => 22, LTLIBRARIES => 16, value => 13, PROGRAMS => 14, LIBRARIES => 15, SCRIPTS => 20, MASN => 23, primaries => 25, TEXINFOS => 24, DATA => 21, JAVA => 19, PYTHON => 18, LISP => 17},
{rhs => 26},
- {reduce => [2, \&optionlist]}, #optionlist : value '_'
+ {reduce => [2, \&optionlist]},
{},
- {"\n" => 27},
- {reduce => [2, \&stmts]}, #stmts : stmt '\n'
+ {newline => 27},
+ {reduce => [2, \&stmts]},
{rhs => 28},
- {"_" =>29, reduce => [1, \&primaries]}, #primaries : value
- {reduce => [1, \&primaries]}, #primaries : PROGRAMS
- {reduce => [1, \&primaries]}, #primaries : LIBRARIES
- {reduce => [1, \&primaries]}, #primaries : LTLIBRARIES
- {reduce => [1, \&primaries]}, #primaries : LISP
- {reduce => [1, \&primaries]}, #primaries : PYTHON
- {reduce => [1, \&primaries]}, #primaries : JAVA
- {reduce => [1, \&primaries]}, #primaries : SCRIPTS
- {reduce => [1, \&primaries]}, #primaries : DATA
- {reduce => [1, \&primaries]}, #primaries : HEADERS
- {reduce => [1, \&primaries]}, #primaries : MASN
- {reduce => [1, \&primaries]}, #primaries : TEXINFOS
- {reduce => [2, \&lhs]}, #lhs : optionlist primaries
- {reduce => [3, \&stmt]}, #stmt : value ':' rhs
- {reduce => [3, \&stmts]}, #stmts : stmts stmt '\n'
- {reduce => [3, \&stmt]}, #stmt : lhs '=' rhs
- {reduce => [3, \&optionlist]} #optionlist : optionlist value '_'
- );
\ No newline at end of file
+ {reduce => [1, \&primaries], '_' => 29},
+ {reduce => [1, \&primaries]},
+ {reduce => [1, \&primaries]},
+ {reduce => [1, \&primaries]},
+ {reduce => [1, \&primaries]},
+ {reduce => [1, \&primaries]},
+ {reduce => [1, \&primaries]},
+ {reduce => [1, \&primaries]},
+ {reduce => [1, \&primaries]},
+ {reduce => [1, \&primaries]},
+ {reduce => [1, \&primaries]},
+ {reduce => [1, \&primaries]},
+ {reduce => [2, \&lhs]},
+ {reduce => [3, \&stmt]},
+ {reduce => [3, \&stmts]},
+ {reduce => [3, \&stmt]},
+ {reduce => [3, \&optionlist]}
+);
\ No newline at end of file