]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
Update Converter.pl to read write from Standard I/O
authorVishal Gupta <vishalgupta7972@gmail.com>
Mon, 4 Jun 2018 17:32:56 +0000 (23:02 +0530)
committerVishal Gupta <vishalgupta7972@gmail.com>
Mon, 4 Jun 2018 17:32:56 +0000 (23:02 +0530)
*Converter.pl: Updated the file to use input/output redirection in
Makefile.
*Makefile: Updated Makefile to support IO in converter.pl

lib/Automake/Parser/Converter.pl
lib/Automake/Parser/Makefile
lib/Automake/Parser/ParserTable.pm

index 70c06b93192aee2c8c3ee272035bc738b3f60b6b..ca6a315f0f73aa9c7f10a2c1f894bd4cdc07bac8 100644 (file)
@@ -1,11 +1,11 @@
 #!/usr/bin/perl
 use strict;
 
-#Input data for conversion
-my $data;
-open ( $data , "< automake.dot" );
-
-#Storing parser table
+#Stores the parser table. 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 and its 
+#value is an array consisting of number of elements to be reduced and a 
+#reference to a function to create a node.
 my @table;
 
 #Stores labels of nodes.
@@ -13,13 +13,18 @@ my @labels;
 
 my $acceptstate = 0;
 
-while( <$data> )
+while( <> )
 {
+       #Finding label word in the current line as every node and edge description 
+       #contains label property. The value of label is extracted.
        if(m/label=\"(.*)\"/)
        {
                my $token = $1;
+               #Every edge is denoted as state_number -> state_number . The current 
+               #line is searched for this and to and from state number are extracted.
                if(m/(\d+) -> (\d+)/)
                {
+                       # "$end" token is replaced with end.
                        if($token eq "\$end")
                        {
                                $table[ $1 ]{ end } = $2;
@@ -29,15 +34,28 @@ while( <$data> )
                                $table[ $1 ]{ $token } = $2;
                        }
                }
+               #The line describing the node contains State word in its description 
+               #followed by state number. The state number is extracted and its value 
+               #is stored.
                elsif(m/State (\d+)\\n/)
                {
                        $labels[ $1 ] = $token;
                }
        }
+       #Edges denoting reduction are represented as:
+       #state_number -> state_number R production_number.
+       #production_number denotes the production by which reduction is to happen. 
+       #It is extracted from the label value of the specified state.
        elsif(m/(\d+) -> "\d+R(\d+)"/)
        {
                my $state_number = $1;
                my $production_number = $2;
+               #The production is specified as:
+               #production_number left side: right side .\l
+               #If left side is $accept then acceptance state number is set to the 
+               #current state number else a reduce key is inserted into current state 
+               #with value equal to an array having number of words on right side and 
+               #function with name of the value of left side.
                $labels[$state_number] =~ m/$production_number (.+): (.+)\.\\l/;
                if($1 eq "\$accept")
                {
@@ -51,14 +69,10 @@ while( <$data> )
        }
 }
 
-#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";
+print "package ParserTable;\n\nuse Exporter;\nuse Tree;\n\nour \@ISA=qw(Exporter);\nour \@Export=qw(\@table \$accept);\n\nour \$accept=$acceptstate;\n\n";
 
+#Prints the table.
 my @data;
-
 for my $href ( @table )
 {
        my @hashval;
@@ -76,4 +90,4 @@ for my $href ( @table )
        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
+print sprintf( "our \@table=(\n\t\t%s\n);" , join ( ",\n\t\t" , @data ));
\ No newline at end of file
index b98bffcc5ebbebf9e01a5260d152a8732ea2898e..3d5a269e2566c0b022ef168c478db956e6f0081f 100644 (file)
@@ -1,20 +1,20 @@
 
-all: execute
+all: ast.png
 
-execute: Lexer.pm Tree.pm ParserTable.pm parser.pl
+ast.png: Lexer.pm Tree.pm ParserTable.pm parser.pl
        perl -I. parser.pl
        unflatten -f -l 5 -c 6 -o ast1.gv ast.gv
        dot -Tpng ast1.gv > ast.png
        rm ast1.gv
 
-build: buildGrammer buildTree
+build: automake.dot ParserTable.pm
 
-buildGrammer: automake.y
+automake.dot: automake.y
        bison --graph automake.y
        rm automake.tab.c
        unflatten -f -l 5 -c 6 -o automake1.dot automake.dot
        dot -Tpng automake1.dot > automake.png
        rm automake1.dot
 
-buildTree: automake.dot Converter.pl
-       perl -I. Converter.pl
+ParserTable.pm: automake.dot Converter.pl
+       perl -I. Converter.pl < automake.dot > ParserTable.pm
index 5d0404a4c6691697c5bfbee1fec4bd9df32b3eb7..12aaaa4141f483cffb456deab2f0c73d7d8dd717 100644 (file)
@@ -9,20 +9,20 @@ our @Export=qw(@table $accept);
 our $accept=9;
 
 our @table=(
-               {value => 1, stmts => 3, stmt => 4, lhs => 5, optionlist => 6, input => 2},
-               {':' => 7, '_' => 8},
+               {stmt => 4, input => 2, lhs => 5, stmts => 3, value => 1, optionlist => 6},
+               {'_' => 8, ':' => 7},
                {end => 9},
-               {reduce => [1,  \&input], optionlist => 6, lhs => 5, stmt => 10, value => 1},
+               {value => 1, optionlist => 6, stmt => 10, lhs => 5, reduce => [1,  \&input]},
                {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},
+               {DATA => 21, PYTHON => 18, LIBRARIES => 15, TEXINFOS => 24, PROGRAMS => 14, MASN => 23, value => 13, JAVA => 19, HEADERS => 22, SCRIPTS => 20, LTLIBRARIES => 16, primaries => 25, LISP => 17},
                {rhs => 26},
                {reduce => [2,  \&optionlist]},
                {},
                {newline => 27},
                {reduce => [2,  \&stmts]},
                {rhs => 28},
-               {reduce => [1,  \&primaries], '_' => 29},
+               {'_' => 29, reduce => [1,  \&primaries]},
                {reduce => [1,  \&primaries]},
                {reduce => [1,  \&primaries]},
                {reduce => [1,  \&primaries]},