summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVishal Gupta <vishalgupta7972@gmail.com>2018-08-04 12:34:02 +0530
committerVishal Gupta <vishalgupta7972@gmail.com>2018-08-04 12:34:02 +0530
commit7e49c6d6e4057413e2c66d6bf18a0bf789cf4ebe (patch)
tree78c2c84f422034a061ade8c2d68bc2d9f5845810
parentf88180b165a1bb4873d8ea255d6707ab6851f454 (diff)
downloadautomake-7e49c6d6e4057413e2c66d6bf18a0bf789cf4ebe.tar.gz
Updated make install to make parser work from any directory
*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
-rw-r--r--lib/Automake/Parser/Makefile11
-rw-r--r--lib/Automake/Parser/ParserTable.pm32
-rw-r--r--lib/Automake/Parser/Tree.pm19
-rw-r--r--lib/Automake/Parser/parser.pl20
-rw-r--r--lib/Automake/Parser/t/app/Makefile.am2
-rw-r--r--lib/Automake/Parser/test.sh6
6 files changed, 53 insertions, 37 deletions
diff --git a/lib/Automake/Parser/Makefile b/lib/Automake/Parser/Makefile
index 5df91c3a2..f271f8071 100644
--- a/lib/Automake/Parser/Makefile
+++ b/lib/Automake/Parser/Makefile
@@ -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
diff --git a/lib/Automake/Parser/ParserTable.pm b/lib/Automake/Parser/ParserTable.pm
index ae54f0db8..9edbca9a3 100644
--- a/lib/Automake/Parser/ParserTable.pm
+++ b/lib/Automake/Parser/ParserTable.pm
@@ -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
diff --git a/lib/Automake/Parser/Tree.pm b/lib/Automake/Parser/Tree.pm
index 8230ce5f1..e6e9c9836 100644
--- a/lib/Automake/Parser/Tree.pm
+++ b/lib/Automake/Parser/Tree.pm
@@ -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" );
}
}
}
diff --git a/lib/Automake/Parser/parser.pl b/lib/Automake/Parser/parser.pl
index d631a9a66..b2384fab9 100644
--- a/lib/Automake/Parser/parser.pl
+++ b/lib/Automake/Parser/parser.pl
@@ -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 )
diff --git a/lib/Automake/Parser/t/app/Makefile.am b/lib/Automake/Parser/t/app/Makefile.am
index 1566cc4be..70cfe4ddf 100644
--- a/lib/Automake/Parser/t/app/Makefile.am
+++ b/lib/Automake/Parser/t/app/Makefile.am
@@ -1 +1 @@
-bin_PROGRAMS=apple \ No newline at end of file
+bin_PROGRAMS=apple ball \ No newline at end of file
diff --git a/lib/Automake/Parser/test.sh b/lib/Automake/Parser/test.sh
index 6f49ad1bd..f7437d4bf 100644
--- a/lib/Automake/Parser/test.sh
+++ b/lib/Automake/Parser/test.sh
@@ -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