diff options
author | Vishal Gupta <vishalgupta7972@gmail.com> | 2018-06-04 23:02:56 +0530 |
---|---|---|
committer | Vishal Gupta <vishalgupta7972@gmail.com> | 2018-06-04 23:02:56 +0530 |
commit | 0719bd6f1d8288cd99b71e5244ac8fb52b4bd422 (patch) | |
tree | b2b5d19b95ee60b77746e9200cba16cb02f7f90e | |
parent | d70d0e2243f6bf54fb9bce3ce159d905c78cef26 (diff) | |
download | automake-0719bd6f1d8288cd99b71e5244ac8fb52b4bd422.tar.gz |
Update Converter.pl to read write from Standard I/O
*Converter.pl: Updated the file to use input/output redirection in
Makefile.
*Makefile: Updated Makefile to support IO in converter.pl
-rw-r--r-- | lib/Automake/Parser/Converter.pl | 40 | ||||
-rw-r--r-- | lib/Automake/Parser/Makefile | 12 | ||||
-rw-r--r-- | lib/Automake/Parser/ParserTable.pm | 10 |
3 files changed, 38 insertions, 24 deletions
diff --git a/lib/Automake/Parser/Converter.pl b/lib/Automake/Parser/Converter.pl index 70c06b931..ca6a315f0 100644 --- a/lib/Automake/Parser/Converter.pl +++ b/lib/Automake/Parser/Converter.pl @@ -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 diff --git a/lib/Automake/Parser/Makefile b/lib/Automake/Parser/Makefile index b98bffcc5..3d5a269e2 100644 --- a/lib/Automake/Parser/Makefile +++ b/lib/Automake/Parser/Makefile @@ -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 diff --git a/lib/Automake/Parser/ParserTable.pm b/lib/Automake/Parser/ParserTable.pm index 5d0404a4c..12aaaa414 100644 --- a/lib/Automake/Parser/ParserTable.pm +++ b/lib/Automake/Parser/ParserTable.pm @@ -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]}, |