]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
Updated make install to make parser work from any directory
authorVishal Gupta <vishalgupta7972@gmail.com>
Sat, 4 Aug 2018 07:04:02 +0000 (12:34 +0530)
committerVishal Gupta <vishalgupta7972@gmail.com>
Sat, 4 Aug 2018 07:04:02 +0000 (12:34 +0530)
*Added parser.pl to /usr/bin so that it can work from any directory
Modules are copied to /tmp/parser and the location is updated in
parser.pl. This is for development purpose only and it can be changed
in future.

*Added a basedir variable so that recursive automake can work to
arbitrary depth

lib/Automake/Parser/Makefile
lib/Automake/Parser/ParserTable.pm
lib/Automake/Parser/Tree.pm
lib/Automake/Parser/parser.pl
lib/Automake/Parser/t/app/Makefile.am
lib/Automake/Parser/test.sh

index 5df91c3a23d6c8acd4a1b88f2e906045845d459b..f271f807175c197cf94b5a67254ef0d833613632 100644 (file)
@@ -1,11 +1,10 @@
 
-all: ast.png
+all: install
 
-ast.png: Lexer.pm Tree.pm ParserTable.pm parser.pl input.txt
-       perl -I. Parser.pl input.txt > ast.gv
-       unflatten -f -l 10 -c 10 -o ast1.gv ast.gv
-       dot -Tpng ast1.gv > ast.png
-       rm ast.gv ast1.gv       
+install: Lexer.pm Tree.pm ParserTable.pm parser.pl
+       mkdir -p /tmp/parser
+       cp *.pm /tmp/parser/
+       cp parser.pl /usr/bin/  
        
 build: ParserTable.pm
 
index ae54f0db8b74d2764255846637136903570ebae3..9edbca9a391cd7d215daa6b98162337ea84f4a57 100644 (file)
@@ -9,23 +9,23 @@ our @Export=qw(@table $accept);
 our $accept=20;
 
 our @table=(
-               {makerule => 9, include => 4, comment => 2, stmt => 7, conditional => 11, stmts => 6, ifblock => 12, value => 1, input => 5, includerule => 10, optionlist => 15, automakerule => 8, if => 3, commentlist => 14, lhs => 13},
+               {optionlist => 15, commentlist => 14, if => 3, ifblock => 12, includerule => 10, stmt => 7, automakerule => 8, value => 1, stmts => 6, comment => 2, include => 4, conditional => 11, input => 5, lhs => 13, makerule => 9},
                {reduce => [1,  \&lhs], ':' => 16, '_' => 17},
                {reduce => [1,  \&commentlist]},
                {value => 18},
                {value => 19},
                {end => 20},
-               {conditional => 11, include => 4, comment => 2, stmt => 21, makerule => 9, if => 3, reduce => [1,  \&input], lhs => 13, commentlist => 14, optionlist => 15, automakerule => 8, includerule => 10, ifblock => 12, value => 1},
+               {optionlist => 15, commentlist => 14, if => 3, ifblock => 12, includerule => 10, stmt => 21, automakerule => 8, value => 1, comment => 2, conditional => 11, include => 4, reduce => [1,  \&input], lhs => 13, makerule => 9},
                {newline => 22},
                {reduce => [1,  \&stmt]},
                {reduce => [1,  \&stmt]},
                {reduce => [1,  \&stmt]},
                {reduce => [1,  \&stmt]},
-               {reduce => [0,  \&optionalelse], optionalelse => 24, else => 23},
+               {reduce => [0,  \&optionalelse], else => 23, optionalelse => 24},
                {'+' => 26, '=' => 25},
-               {reduce => [1,  \&stmt], comment => 27},
-               {SCRIPTS => 35, LIBRARIES => 30, LISP => 32, HEADERS => 37, PYTHON => 33, PROGRAMS => 29, LTLIBRARIES => 31, JAVA => 34, DATA => 36, TEXINFOS => 39, primaries => 40, value => 28, MASN => 38},
-               {rhsval => 41, rhs => 42},
+               {comment => 27, reduce => [1,  \&stmt]},
+               {TEXINFOS => 39, LISP => 32, HEADERS => 37, SCRIPTS => 35, value => 28, primaries => 40, LIBRARIES => 30, PYTHON => 33, PROGRAMS => 29, MASN => 38, JAVA => 34, LTLIBRARIES => 31, DATA => 36},
+               {rhs => 42, rhsval => 41},
                {reduce => [2,  \&optionlist]},
                {newline => 43},
                {reduce => [2,  \&includerule]},
@@ -34,10 +34,10 @@ our @table=(
                {reduce => [2,  \&stmts]},
                {newline => 45},
                {endif => 46},
-               {optionalrhs => 47, rhsval => 41, rhs => 48, reduce => [0,  \&optionalrhs]},
+               {optionalrhs => 47, rhsval => 41, reduce => [0,  \&optionalrhs], rhs => 48},
                {'=' => 49},
                {reduce => [2,  \&commentlist]},
-               {reduce => [1,  \&primaries], '_' => 50},
+               {'_' => 50, reduce => [1,  \&primaries]},
                {reduce => [1,  \&primaries]},
                {reduce => [1,  \&primaries]},
                {reduce => [1,  \&primaries]},
@@ -51,22 +51,22 @@ our @table=(
                {reduce => [1,  \&primaries]},
                {reduce => [2,  \&lhs]},
                {reduce => [1,  \&rhs]},
-               {rhsval => 51, reduce => [3,  \&makerule]},
-               {comment => 2, stmt => 7, include => 4, makerule => 9, stmts => 52, conditional => 11, includerule => 10, value => 1, ifblock => 12, lhs => 13, commentlist => 14, if => 3, automakerule => 8, optionlist => 15},
+               {reduce => [3,  \&makerule], rhsval => 51},
+               {if => 3, includerule => 10, ifblock => 12, stmt => 7, automakerule => 8, optionlist => 15, commentlist => 14, include => 4, conditional => 11, lhs => 13, makerule => 9, value => 1, stmts => 52, comment => 2},
                {reduce => [3,  \&stmts]},
-               {stmts => 53, conditional => 11, stmt => 7, comment => 2, include => 4, makerule => 9, commentlist => 14, lhs => 13, if => 3, automakerule => 8, optionlist => 15, includerule => 10, ifblock => 12, value => 1},
+               {automakerule => 8, stmt => 7, ifblock => 12, includerule => 10, if => 3, commentlist => 14, optionlist => 15, makerule => 9, lhs => 13, include => 4, conditional => 11, comment => 2, stmts => 53, value => 1},
                {value => 54, optionalcond => 55, reduce => [0,  \&optionalcond]},
-               {commentlist => 57, reduce => [0,  \&optionalcomments], optionalcomments => 56, comment => 2},
+               {reduce => [0,  \&optionalcomments], comment => 2, optionalcomments => 56, commentlist => 57},
                {reduce => [1,  \&optionalrhs], rhsval => 51},
-               {rhsval => 41, optionalrhs => 58, rhs => 48, reduce => [0,  \&optionalrhs]},
+               {optionalrhs => 58, reduce => [0,  \&optionalrhs], rhsval => 41, rhs => 48},
                {reduce => [3,  \&optionlist]},
                {reduce => [2,  \&rhs]},
-               {value => 1, ifblock => 12, includerule => 10, optionlist => 15, automakerule => 8, if => 3, lhs => 13, reduce => [4,  \&ifblock], commentlist => 14, makerule => 9, include => 4, stmt => 21, comment => 2, conditional => 11},
-               {comment => 2, stmt => 21, include => 4, makerule => 9, conditional => 11, includerule => 10, value => 1, ifblock => 12, lhs => 13, reduce => [3,  \&optionalelse], commentlist => 14, if => 3, automakerule => 8, optionlist => 15},
+               {commentlist => 14, optionlist => 15, automakerule => 8, stmt => 21, ifblock => 12, includerule => 10, if => 3, comment => 2, value => 1, reduce => [4,  \&ifblock], lhs => 13, makerule => 9, conditional => 11, include => 4},
+               {if => 3, ifblock => 12, includerule => 10, stmt => 21, automakerule => 8, optionlist => 15, commentlist => 14, conditional => 11, include => 4, reduce => [3,  \&optionalelse], lhs => 13, makerule => 9, value => 1, comment => 2},
                {reduce => [1,  \&optionalcond]},
                {reduce => [4,  \&conditional]},
                {reduce => [4,  \&automakerule]},
                {comment => 27, reduce => [1,  \&optionalcomments]},
-               {comment => 2, commentlist => 57, reduce => [0,  \&optionalcomments], optionalcomments => 59},
+               {reduce => [0,  \&optionalcomments], commentlist => 57, optionalcomments => 59, comment => 2},
                {reduce => [5,  \&automakerule]}
 );
\ No newline at end of file
index 8230ce5f14a67ca25eef077eb9e4d4e661dbf6e8..e6e9c9836261d2485b34c9aca6384351caf7f8b2 100644 (file)
@@ -305,7 +305,8 @@ sub includerule($$)
 }
 
 # printgraph(Hash)
-# prints the AST to Standard Output by traversing the tree starting at node pointed by hash.
+# prints the AST to Standard Output by traversing the tree starting at node
+# pointed by hash.
 sub printgraph($)
 {
        print "graph graphname {\n";
@@ -319,7 +320,8 @@ sub printgraph($)
 my $id = 0;
 
 # traverse(Hash, Parent Id)
-# Traverses the tree recursively. Prints the information about the current node to Standard Output. Call all its child with Parent Id equal to current Node Id.
+# Traverses the tree recursively. Prints the information about the current node
+# to Standard Output. Call all its child with Parent Id equal to current Node Id.
 sub traverse($$)
 {
        my ( $ref,$parent ) = @_;
@@ -353,10 +355,11 @@ sub traverse($$)
        }
 }
 
+# recursesubdirs(Basedir, Reference)
 # Recurse into sub directories to generate AST 
-sub recursesubdirs($)
+sub recursesubdirs($$)
 {
-       my ($ref) = @_;
+       my ( $basedir , $ref) = @_;
        my %node= %$ref;
        if( scalar @{ $node{childs} } == 2)
        {
@@ -364,10 +367,10 @@ sub recursesubdirs($)
                my %subdirNode = %$subdirRef;
                foreach $val ( @{ $subdirNode{subdirs} } )
                {
-                       system( "perl -I. Parser.pl $val/Makefile.am > $val/ast.gv" );
-                       system( "unflatten -f -l 10 -c 10 -o $val/ast1.gv $val/ast.gv" );
-                       system( "dot -Tpng $val/ast1.gv > $val/ast.png" );
-                       system( "rm $val/ast.gv $val/ast1.gv" );
+                       system( "parser.pl $basedir/$val/Makefile.am > $basedir/$val/ast.gv" );
+                       system( "unflatten -f -l 10 -c 10 -o $basedir/$val/ast1.gv $basedir/$val/ast.gv" );
+                       system( "dot -Tpng $basedir/$val/ast1.gv > $basedir/$val/ast.png" );
+                       system( "rm $basedir/$val/ast.gv $basedir/$val/ast1.gv" );
                }
        }
 }
index d631a9a66019aa7350d48329ebf6ea64136266a5..b2384fab9cf5aae08359e8727f563f4013d8ca79 100644 (file)
@@ -1,13 +1,27 @@
 #!/usr/bin/perl
+
+BEGIN
+{
+       # Adds the directory containing modules which are copied during
+       # make install
+       unshift (@INC, '/tmp/parser');
+}
+
 use strict;
 use Lexer;
 use Tree;
 use ParserTable;
+use File::Basename;
+
+# Stores the relative path of the Makefile.am file with respect to 
+# current working directory
+my $basedir = File::Basename::dirname($ARGV[0]);
 
-#To enable debug mode, use 1
+# To enable debug mode, use 1 . Prints the parser stack at each 
+# iteration
 my $debug = 0;
 
-#Stores the list of tokens generated by lexer.
+# Stores the list of tokens generated by lexer.
 my @tokens; 
 
 my @stack = (0);
@@ -22,7 +36,7 @@ while ( @stack )
        {
                print STDERR "Complete\n";
                printgraph( $stack[-4] );
-               recursesubdirs( $stack[-4] );
+               recursesubdirs( $basedir, $stack[-4] );
                last;
        }
        while( !@tokens )
index 1566cc4be92defe1c270e3a9aac6994282c88941..70cfe4ddf1dbb8dac3e90928e11706b2a889bee1 100644 (file)
@@ -1 +1 @@
-bin_PROGRAMS=apple
\ No newline at end of file
+bin_PROGRAMS=apple ball
\ No newline at end of file
index 6f49ad1bd4397c3b56708b2d4cfe35cb0671da10..f7437d4bf1bfbe5f4fc009c620dd9a8ef0444448 100644 (file)
@@ -3,8 +3,7 @@ testfile()
 {
        filename=$1
        echo $filename
-       echo `pwd`
-       perl parser.pl $filename > $filename.gv
+       parser.pl $filename > $filename.gv
        unflatten -f -l 10 -c 10 -o $filename1.gv $filename.gv
        dot -Tpng $filename1.gv > $filename.png
        rm $filename.gv $filename1.gv
@@ -12,7 +11,8 @@ testfile()
 
 if [ $# -eq 0 ]
 then
-       for entry in t/*.txt
+       cd t
+       for entry in *.txt
        do
                testfile $entry
        done