]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
Added support for Conditional statement and Test files.
authorVishal Gupta <vishalgupta7972@gmail.com>
Sat, 16 Jun 2018 06:39:17 +0000 (12:09 +0530)
committerVishal Gupta <vishalgupta7972@gmail.com>
Sat, 16 Jun 2018 06:39:17 +0000 (12:09 +0530)
* automake.y : Updated to handle conditional statement and empty variable
* defination
* parser.pl : Updated to read from standard input and write to standard
* output. In debug mode, output on standard error stream.
* Converter.pl : Updated to handle empty grammar definitions.
* Tree.pm : Updated to handle conditional statements and write output to
* standard output
* Makefile : Added action test.
* test.sh : Read all text files in t directory and generates corresponding
* standard output
* Makefile : Added action test.
* t/*.txt : test files.

16 files changed:
lib/Automake/Parser/.gitignore
lib/Automake/Parser/Converter.pl
lib/Automake/Parser/Lexer.pm
lib/Automake/Parser/Makefile
lib/Automake/Parser/ParserTable.pm
lib/Automake/Parser/Tree.pm
lib/Automake/Parser/automake.y
lib/Automake/Parser/input.txt
lib/Automake/Parser/parser.pl
lib/Automake/Parser/t/.gitignore [new file with mode: 0644]
lib/Automake/Parser/t/automakecomment.txt [new file with mode: 0644]
lib/Automake/Parser/t/conditional.txt [new file with mode: 0644]
lib/Automake/Parser/t/multiline.txt [new file with mode: 0644]
lib/Automake/Parser/t/multilinecoment.txt [new file with mode: 0644]
lib/Automake/Parser/t/primaries.txt [new file with mode: 0644]
lib/Automake/Parser/test.sh [new file with mode: 0644]

index fa83ea49701b71220b0aa48291c9e61cafb0add1..db764bc80e5862a346b31aada8e6f5f914677612 100644 (file)
@@ -2,3 +2,4 @@
 *.png
 *.dot
 *.tab.c
+*.output
index ab21844866bfc2adf671efe1d310c3d274f0eafb..a4419a08dc1d463468cff71ff9e26a0454855679 100644 (file)
@@ -1,6 +1,16 @@
 #!/usr/bin/perl
 use strict;
 
+my %hashx;
+
+while ( <> )
+{
+       last if m/^Terminals, with /o;
+       $hashx{$1}=$2 if m/^\s+(\d+) (.*?): %empty\n/;
+}
+
+close ARGV;
+
 #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 
@@ -62,6 +72,10 @@ while( <> )
                        $table[ $state_number ] = {};
                        $acceptstate = $state_number;
                }
+               elsif($1 eq $1+0)
+               {
+                       $table[$state_number]{reduce}=[0," \\&$hashx{$production_number}"];
+               }
                else
                {
                        $table[ $state_number ]{ reduce } = [scalar( split( /\s+/ , $2 )) , " \\&$1" ];
index 7446e811421b40bf408ed68f7b5f40f68a193890..d4190eedd741b03b575a45c29170c615164a9f30 100644 (file)
@@ -39,10 +39,7 @@ sub lex($$)
                                {
                                        if($val =~ m/^##/)
                                        {
-                                               if($vals[ -1 ] eq '\\')
-                                               {
-                                                       $multiline = 'automake_comment';
-                                               }
+                                               $multiline = 'automake_comment' if $vals[ -1 ] eq '\\';
                                                $_ = undef;
                                                last;
                                        }
@@ -55,10 +52,7 @@ sub lex($$)
                                                $comment .= " ".$val;
                                        }
                                }
-                               if( $comment )
-                               {
-                                       push @tokens, [ "comment" , $comment ];
-                               }
+                               push @tokens, [ "comment" , $comment ] if $comment;
                                if($vals[ -1 ] ne '\\')
                                {
                                        $multiline = undef;
@@ -80,27 +74,18 @@ sub lex($$)
                        {
                                if( $val =~ m/^##/ )
                                {
-                                       if($vals[ -1 ] eq '\\' )
-                                       {
-                                               $multiline = 'automake_comment';
-                                       }
+                                       $multiline = 'automake_comment' if $vals[ -1 ] eq '\\';
                                        $_ = undef;
                                        last;
                                }
                                elsif( $val =~ m/^#(.*)/ )
                                {
-                                       if($vals[ -1 ] eq '\\' )
-                                       {
-                                               $multiline = 'comment';
-                                       }
+                                       $multiline = 'comment' if $vals[ -1 ] eq '\\';
                                        $comment .= " ".$1;
                                }
                                elsif( $val =~ m/\\/ )
                                {
-                                       if( !$multiline )
-                                       {
-                                               $multiline = 'rhsval';
-                                       }
+                                       $multiline = 'rhsval' if !$multiline;
                                }
                                elsif( $comment )
                                {
@@ -111,14 +96,8 @@ sub lex($$)
                                        push @tokens, [ "rhsval" , $val];
                                }
                        }
-                       if( $comment )
-                       {
-                               push @tokens, [ "comment" , $comment];
-                       }
-                       if( !$multiline )
-                       {
-                               push @tokens, [ "newline" ];
-                       }
+                       push @tokens, [ "comment" , $comment] if $comment;
+                       push @tokens, [ "newline" ] if !$multiline;
                        $_ = undef;
                }
                elsif( s/^##.*\n$//o )
@@ -138,7 +117,7 @@ sub lex($$)
                                push @tokens, [ "newline" ];
                        }
                }
-               elsif( s/^(PROGRAMS|LIBRARIES|LTLIBRARIES|LISP|PYTHON|JAVA|SCRIPTS|DATA|HEADERS|MASN|TEXINFOS)//o)
+               elsif( s/^(PROGRAMS|LIBRARIES|LTLIBRARIES|LISP|PYTHON|JAVA|SCRIPTS|DATA|HEADERS|MASN|TEXINFOS|if|else|endif)//o)
                {
                        push @tokens, [$1];
                }
index 9e1c41322be27d655b9ddcede7dee93e71c85789..84c1ca9e204ed491b9a26ee86e33a873dc056310 100644 (file)
@@ -2,12 +2,12 @@
 all: ast.png
 
 ast.png: Lexer.pm Tree.pm ParserTable.pm parser.pl input.txt
-       perl -I. parser.pl
+       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 ast1.gv
-
-build: automake.dot ParserTable.pm
+       rm ast.gv ast1.gv       
+       
+build: ParserTable.pm
 
 automake.dot: automake.y
        bison --graph automake.y
@@ -15,6 +15,13 @@ automake.dot: automake.y
        unflatten -f -l 16 -c 9 -o automake1.dot automake.dot
        dot -Tpng automake1.dot > automake.png
        rm automake1.dot
+       
+automake.output: automake.y
+       bison --report=all automake.y
+       rm automake.tab.c
+
+ParserTable.pm: automake.dot automake.output Converter.pl
+       perl -I. Converter.pl automake.output automake.dot > ParserTable.pm
 
-ParserTable.pm: automake.dot Converter.pl
-       perl -I. Converter.pl < automake.dot > ParserTable.pm
+test:
+       sh test.sh
index d215a0a7dff6bac6197fb6c9039d3cb2da51aed6..907a9a9efc55f30e82f7872d6dcdb95b3067dfd7 100644 (file)
@@ -6,26 +6,34 @@ use Tree;
 our @ISA=qw(Exporter);
 our @Export=qw(@table $accept);
 
-our $accept=11;
+our $accept=17;
 
 our @table=(
-               {commentlist => 7, optionlist => 8, stmts => 4, comment => 2, value => 1, stmt => 5, lhs => 6, input => 3},
-               {'_' => 10, ':' => 9},
+               {commentlist => 12, if => 3, lhs => 11, value => 1, makerule => 8, optionlist => 13, comment => 2, input => 4, automakerule => 7, stmt => 6, stmts => 5, conditional => 9, ifblock => 10},
+               {reduce => [1,  \&lhs], ':' => 14, '_' => 15},
                {reduce => [1,  \&commentlist]},
-               {end => 11},
-               {lhs => 6, reduce => [1,  \&input], comment => 2, commentlist => 7, value => 1, optionlist => 8, stmt => 12},
-               {newline => 13},
-               {'=' => 14},
-               {reduce => [1,  \&stmt], comment => 15},
-               {PYTHON => 21, HEADERS => 25, JAVA => 22, LTLIBRARIES => 19, PROGRAMS => 17, primaries => 28, MASN => 26, value => 16, SCRIPTS => 23, LISP => 20, DATA => 24, LIBRARIES => 18, TEXINFOS => 27},
-               {rhs => 30, rhsval => 29},
+               {value => 16},
+               {end => 17},
+               {value => 1, lhs => 11, if => 3, commentlist => 12, automakerule => 7, comment => 2, optionlist => 13, makerule => 8, reduce => [1,  \&input], stmt => 18, ifblock => 10, conditional => 9},
+               {newline => 19},
+               {reduce => [1,  \&stmt]},
+               {reduce => [1,  \&stmt]},
+               {reduce => [1,  \&stmt]},
+               {optionalelse => 21, reduce => [0,  \&optionalelse], else => 20},
+               {'=' => 22},
+               {comment => 23, reduce => [1,  \&stmt]},
+               {JAVA => 30, PROGRAMS => 25, TEXINFOS => 35, DATA => 32, primaries => 36, HEADERS => 33, LTLIBRARIES => 27, LISP => 28, PYTHON => 29, SCRIPTS => 31, value => 24, MASN => 34, LIBRARIES => 26},
+               {rhs => 38, rhsval => 37},
                {reduce => [2,  \&optionlist]},
+               {newline => 39},
                {},
-               {newline => 31},
+               {newline => 40},
                {reduce => [2,  \&stmts]},
-               {rhsval => 29, rhs => 32},
+               {newline => 41},
+               {endif => 42},
+               {rhsval => 37, rhs => 44, optionalrhs => 43, reduce => [0,  \&optionalrhs]},
                {reduce => [2,  \&commentlist]},
-               {reduce => [1,  \&primaries], '_' => 33},
+               {'_' => 45, reduce => [1,  \&primaries]},
                {reduce => [1,  \&primaries]},
                {reduce => [1,  \&primaries]},
                {reduce => [1,  \&primaries]},
@@ -39,10 +47,20 @@ our @table=(
                {reduce => [1,  \&primaries]},
                {reduce => [2,  \&lhs]},
                {reduce => [1,  \&rhs]},
-               {reduce => [3,  \&stmt], rhsval => 34},
+               {reduce => [3,  \&makerule], rhsval => 46},
+               {automakerule => 48, optionlist => 13, lhs => 11, value => 47},
                {reduce => [3,  \&stmts]},
-               {commentlist => 35, reduce => [3,  \&stmt], comment => 2, rhsval => 34},
+               {lhs => 11, value => 47, automakerule => 49, optionlist => 13},
+               {reduce => [3,  \&conditional]},
+               {optionalcomments => 50, comment => 2, commentlist => 51, reduce => [0,  \&optionalcomments]},
+               {reduce => [1,  \&optionalrhs], rhsval => 46},
                {reduce => [3,  \&optionlist]},
                {reduce => [2,  \&rhs]},
-               {reduce => [4,  \&stmt], comment => 15}
+               {reduce => [1,  \&lhs], '_' => 15},
+               {newline => 52},
+               {newline => 53},
+               {reduce => [4,  \&automakerule]},
+               {comment => 23, reduce => [1,  \&optionalcomments]},
+               {reduce => [5,  \&ifblock]},
+               {reduce => [4,  \&optionalelse]}
 );
\ No newline at end of file
index 92aa7673a531c469d5f35019c553b138097dba74..6e7a4079c27a99888b16a38c93ca7a14199387ce 100644 (file)
@@ -3,7 +3,9 @@ package Tree;
 use Exporter;
 
 our @ISA = qw(Exporter);
-our @EXPORT = qw(input stmt stmts lhs rhs primaries optionlist commentlist traverse printgraph);
+our @EXPORT = qw(input stmts stmt automakerule makerule conditional ifblock 
+optionalelse optionalrhs optionalcomments lhs rhs commentlist primaries 
+optionlist traverse printgraph);
 
 # Grammar Rule : (1) input => stmts
 # Create a node having child as stmts.
@@ -14,66 +16,151 @@ sub input($)
        return \%node;
 }
 
-# Grammar Rule : (1) stmt => lhs '=' rhs
-# Create a node for Automake rule having lhs and rhs as its childs.
-#                               (2) stmt => lhs '=' rhs commentlist
-# Create a node for Automake rule having lhs, rhs and comments as its child.
-#                               (3) stmt => value ':' rhs
-# Create a node for Make rule having lhs and rhs as its childs.
-#                               (4) stmt => commentlist
-# Create a node for comments.
-sub stmt($;$$;$)
+# Grammar Rule : (1) stmts=> stmt '\n'
+# Creates a node having a child as stmt
+#                               (2) stmts=> stmts stmt '\n'
+# Creates a node having a child as stmt. Insert the created node into 
+# the childs array of the stmts(First Argument).
+sub stmts($$;$)
+{
+       my ( $val1, $val2, $val3) = @_;
+       if($val3 == undef)
+       {
+               my %node=(name=>stmts,childs=>[$val1]);
+               return \%node;
+       }
+       else
+       {
+               push @{$val1->{childs}},$val2;
+               return $val1;
+       }
+}
+
+
+# Grammar Rule : (1) stmt => automakerule
+#                               (2) stmt => makerule
+#                               (3) stmt => commentlist
+#                               (4) stmt => conditional
+# Create a node with corresponding child node.
+sub stmt($)
+{
+       my ( $val1) = @_;
+       my %node = ( name => stmt , childs => [ $val1 ]);
+       return \%node;
+}
+
+# Grammar Rule : (1) automakerule => lhs '=' optionalrhs optionalcomments
+# Create a node for automake rule.
+sub automakerule($$$$)
 {
        my ( $val1, $val2, $val3, $val4 ) = @_;
-       my %node;
-       if( !$val2 )
+       my %node = (name => automakerule, childs => [ $val1,$val3 ]);
+       push @{ $node{ childs }}, $val4 if $val4;
+       return \%node;
+}
+
+# Grammar Rule : (1) makerule => value ':' rhs
+# Create a node for make rule.
+sub makerule($$$)
+{
+       my ( $val1, $val2, $val3 ) = @_;
+       my %node = (name => makerule, childs => [ $val1,$val3 ]);
+       return \%node;
+}
+
+# Grammar Rule : (1) optionalrhs =>
+# Create an empty node.
+#                               (2) optionalrhs => rhs
+# Create a node with rhs as child.
+sub optionalrhs(;$)
+{
+       my ( $val ) = @_;
+       my %node = ( name => optionalrhs );
+       if( $val == undef )
        {
-               %node = (name => stmt, childs => [ $val1 ], type => comment);
+               $node{ empty } = 1;
        }
-       elsif( $val2 -> [0] eq '=' )
+       else
        {
-               %node = (name => stmt, childs => [ $val1,$val3 ],type => automake);
-               if( $val4 )
-               {
-                       push @{ $node{ childs }}, $val4;
-               }
+               $node{ childs } = [ $val ];
+       }
+       return \%node;
+}
+
+# Grammar Rule : (1) optionalcomments => 
+# Create an empty node.
+#                               (2) optionalcomments => commentlist
+# Create a node with commentlist as child.
+sub optionalcomments(;$)
+{
+       my ( $val ) = @_;
+       my %node = ( name => optionalcomments );
+       if( $val == undef )
+       {
+               $node{ empty } = 1;
        }
        else
        {
-               %node = (name => stmt, childs => [ $val1,$val3 ],type => make);
-       } 
+               $node{ childs } = [ $val ];
+       }
        return \%node;
 }
 
-# Grammar Rule : (1) stmts=> stmt '\n'
-# Creates a node having a child as stmt
-#                               (2) stmts=> stmts stmt '\n'
-# Creates a node having a child as stmt. Insert the created node into 
-# the childs array of the stmts(First Argument).
-sub stmts($$;$)
+# Grammar Rule : (1) conditional => ifblock optionalelse endif
+# Create a node for conditional statement.
+sub conditional($$$)
 {
-       my ( $val1, $val2, $val3) = @_;
-       if($val3 == undef)
+       my ( $val1, $val2, $val3 ) = @_;
+       my %node = ( name => conditional, childs => [ $val1, $val2]);
+       return \%node;
+}
+
+# Grammar Rule : (1) ifblock => if value newline automakerule newline
+# Create a node for if block.
+sub ifblock($$$$$)
+{
+       my ( $val1, $val2, $val3, $val4, $val5) = @_;
+       my %node = ( name => ifblock, condition => $val2 -> [1], childs => [$val4]);
+       return \%node;
+}
+
+# Grammar Rule : (1) optionalelse =>
+# Create an empty node.
+#                               (2) optionalelse => else newline automakerule newline
+# Create a node with child as automakerule.
+sub optionalelse(;$$$$)
+{
+       my ( $val1, $val2, $val3, $val4 ) = @_;
+       my %node = ( name => optionalelse );
+       if( $val1 == undef )
        {
-               my %node = (name => stmts, childs => [ $val1 ]);
-               my %nodeval = (name => stmts, childs => [ \%node ]);
-               return \%nodeval;
+               $node{ empty } = 1;
        }
        else
        {
-               my %node = (name => stmts,childs => [ $val2 ]);
-               push @{ $val1 -> { childs }}, \%node;
-               return $val1;
+               $node{ childs } = [ $val3 ];
        }
+       return \%node;
 }
 
 # Grammar Rule : (1) lhs => optionlist primaries
 # Create a node for left hand side of variable defination consisting of 
 # option list and primary.
-sub lhs($$)
+#                (2) lhs => value
+# Create a node for left hand side of variable defination having a simple
+# variable defination.
+sub lhs($;$)
 {
        my ( $val1, $val2 ) = @_;
-       my %node = (name => lhs, childs => [ $val1, $val2 ]);
+       my %node = ( name => lhs);
+       if( $val2 == undef )
+       {
+               $node{ value } = $val1 -> [1];
+       }
+       else
+       {
+               $node{ childs } = [ $val1, $val2 ];
+       }
        return \%node;
 }
 
@@ -103,7 +190,7 @@ sub rhs($;$)
 sub commentlist($;$)
 {
        my ( $val1, $val2 ) = @_;
-       if($val2 == undef)
+       if( $val2 == undef )
        {
                my %node = ( name => commentlist, value => [ $val1 -> [1]]);
                return \%node;
@@ -131,14 +218,14 @@ sub commentlist($;$)
 sub primaries($)
 {
        my ( $val ) = @_;
-       my %node;
+       my %node = ( name => primaries );
        if( $val -> [0] eq 'value')
        {
-               %node = ( name => primaries, val=> $val -> [1]);
+               $node{value}= $val -> [1];
        }
        else
        {
-               %node = ( name => primaries, val => $val);
+               $node{value}= $val;
        }
        return \%node;
 }
@@ -163,32 +250,29 @@ sub optionlist($$;$)
 }
 
 # printgraph(Hash)
-# prints the AST 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($)
 {
-       my $FH;
-       open( $FH, '>', 'ast.gv' ) or die $!;
-       print $FH "graph graphname {\n";
+       print "graph graphname {\n";
        my ( $ref ) = @_;
-       print $FH "0 [label=\"Root\"];";
-       traverse( $ref, $FH, 0);
-       print $FH "}\n";
-       close $FH;
+       print "0 [label=\"Root\"];";
+       traverse( $ref, 0);
+       print "}\n";
 }
 
 #Stores the next id to be alloted to new node.
 my $id=0;
 
-# traverse(Hash, File Handle, Parent Id)
-# Traverses the tree recursively. Prints the information about the current 
-# node to file. Call all its child with Parent Id equal to current Node Id.
-sub traverse($$$)
+# 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.
+sub traverse($$)
 {
-       my ( $ref,$FH,$parent ) = @_;
+       my ( $ref,$parent ) = @_;
+       my %node = %$ref;
+       return if $node{empty};
        $id++;
        my $curr_id = $id;
-       my %node = %$ref;
-       print $FH "$parent--$id;\n";
+       print "$parent--$id;\n";
        my $label = "";
        @keys = sort grep {!/^childs/} keys %node;
        foreach $key ( @keys )
@@ -203,13 +287,13 @@ sub traverse($$$)
                        $label .= $node{$key}." ";
                }
        }
-       print $FH "$curr_id [label=\"$label\"];";
+       print "$curr_id [label=\"$label\"];";
        if( $node{childs} )
        {
                my $val1 = $node{childs};
                foreach $child (@$val1)
                {
-                       traverse($child,$FH,$curr_id);
+                       traverse($child,$curr_id);
                }
        }
 }
index 45fdc15984fd6448f84fd55cf937f2d66a94a536..41f0e6aa6a2a1d722e770c9e72c1418ca1adefa3 100644 (file)
@@ -1,4 +1,4 @@
-%token value rhsval comment PROGRAMS LIBRARIES LTLIBRARIES LISP PYTHON JAVA SCRIPTS DATA HEADERS MASN TEXINFOS newline
+%token value rhsval comment PROGRAMS LIBRARIES LTLIBRARIES LISP PYTHON JAVA SCRIPTS DATA HEADERS MASN TEXINFOS newline if else endif
 %%
 
 input : stmts
@@ -6,12 +6,30 @@ input : stmts
 stmts : stmt newline
                | stmts stmt newline
 ;
-stmt  : lhs '=' rhs
-               | lhs '=' rhs commentlist
-               | value ':' rhs
+stmt  : automakerule
+               | makerule
                | commentlist
-;              
+               | conditional
+;
+automakerule : lhs '=' optionalrhs optionalcomments
+;
+makerule : value ':' rhs
+;
+conditional : ifblock optionalelse endif
+;
+ifblock : if value newline automakerule newline
+;
+optionalelse:
+                       | else newline automakerule newline
+;
+optionalrhs : 
+                   | rhs
+;
+optionalcomments : 
+                             | commentlist
+;
 lhs   : optionlist primaries
+               | value
 ;
 rhs   : rhsval
                | rhs rhsval
index fe3ca91ea2bd281cd60ae4749d1c5097a0699849..b09e7ef8c3fc8ec8cfa3f92ef99e908250c2a46f 100644 (file)
@@ -3,11 +3,18 @@ dist_bin_PROGRAMS = server \
 client
 server_SOURCES = server.c db.c   ## Server Files \
 Database Files  
-#Comment Testing Here \
-Same here
-client_SOURCES = client.c dep.c #Multiline comment \
+#Comment Testing Here
+#a
+#b
+#c
+#END
+client_SOURCES =  #Multiline comment \
 Client dependencies
-noinst_LIBRARIES = libfoo.a
+if installed
+noinst_LIBRARIES = foolib.b
+else
+noinst_LIBRARIES = 
+endif
 noinst_LTLIBRARIES = foolib.a
 files_JAVA = a.java b.java
 files_PYTHON = chk.py app.py test.py
index 4a3386d149577d9dd711eca5fff60679f6a0fb9b..64cace1d17cc549c01b20269e479547785dfcd2e 100644 (file)
@@ -6,37 +6,44 @@ use ParserTable;
 
 my $debug = 0;
 
-#Input file for conversion
-my $data;
-open ( $data, "<input.txt" );
-
 #Stores the list of tokens generated by lexer.
 my @tokens; 
 
 my $multiline = 0;
 my $curr_tokens;
-while ( <$data> )
+
+#Read input from file specified in Arguements or STDIN.
+while ( <> )
 {
-       ( $curr_tokens, $multiline) = lex($_ , $multiline);
+       ( $curr_tokens, $multiline ) = lex($_ , $multiline);
        push @tokens,@$curr_tokens;
 }
+
+#Prints to STDERR if Debug mode is on.
 if( $debug )
 {
-       print "Lexer Output\n";
+       print STDERR "Lexer Output\n";
        foreach my $token ( @tokens )
        {
-               print join(" ", @{$token}), "\n";
+               print STDERR join(" ", @{$token}), "\n";
        }
 }
+
+#Push a newline token if last token is not newline
+if( $tokens[-1][0] ne "newline" )
+{
+       push @tokens,["newline"];
+}
+
 push @tokens, [ "end" ];
 my @stack = (0);
-print "Parser Output\n" if $debug;
+print STDERR "Parser Output\n" if $debug;
 
 while ( @stack )
 {
        if($stack[-1] == $ParserTable::accept)
        {
-               print "Complete\n";
+               print STDERR "Complete\n";
                printgraph( $stack[-4] );
                last;
        }
@@ -70,5 +77,5 @@ while ( @stack )
        {
                die "Unexpected Token ". @curr_token."\n";
        }
-       print @stack, "\n" if $debug;
+       print STDERR @stack, "\n" if $debug;
 }
\ No newline at end of file
diff --git a/lib/Automake/Parser/t/.gitignore b/lib/Automake/Parser/t/.gitignore
new file mode 100644 (file)
index 0000000..aab52d9
--- /dev/null
@@ -0,0 +1 @@
+*.png
\ No newline at end of file
diff --git a/lib/Automake/Parser/t/automakecomment.txt b/lib/Automake/Parser/t/automakecomment.txt
new file mode 100644 (file)
index 0000000..330e772
--- /dev/null
@@ -0,0 +1,4 @@
+## Process this file with automake to produce Makefile.in
+bin_PROGRAMS = ball
+ball_SOURCES = ball.c ## C file
+##End of File
diff --git a/lib/Automake/Parser/t/conditional.txt b/lib/Automake/Parser/t/conditional.txt
new file mode 100644 (file)
index 0000000..3708d80
--- /dev/null
@@ -0,0 +1,6 @@
+bin_PROGRAMS = server
+if windows
+server_SOURCES = winserver.c
+else
+server_SOURCES = unixserver.c
+endif
\ No newline at end of file
diff --git a/lib/Automake/Parser/t/multiline.txt b/lib/Automake/Parser/t/multiline.txt
new file mode 100644 (file)
index 0000000..da5cfe8
--- /dev/null
@@ -0,0 +1,4 @@
+bin_PROGRAMS = apple \
+ball
+apple_SOURCES = apple.c
+ball_SOURCES = ball.c
\ No newline at end of file
diff --git a/lib/Automake/Parser/t/multilinecoment.txt b/lib/Automake/Parser/t/multilinecoment.txt
new file mode 100644 (file)
index 0000000..9788fbe
--- /dev/null
@@ -0,0 +1,7 @@
+bin_PROGRAMS = apple \
+ball
+apple_SOURCES = apple.c ## Comment on \
+Multiple line
+ball_SOURCES = # No file \
+Multiple line1 \
+Multiple line2
diff --git a/lib/Automake/Parser/t/primaries.txt b/lib/Automake/Parser/t/primaries.txt
new file mode 100644 (file)
index 0000000..6de4478
--- /dev/null
@@ -0,0 +1,3 @@
+dist_bin_PROGRAMS = server client
+server_SOURCES = server.c db.c
+client_SOURCES = client.c
\ No newline at end of file
diff --git a/lib/Automake/Parser/test.sh b/lib/Automake/Parser/test.sh
new file mode 100644 (file)
index 0000000..f20e009
--- /dev/null
@@ -0,0 +1,23 @@
+
+testfile()
+{
+       filename=$1
+       echo $filename
+       perl -I. 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
+}
+
+if [ $# -eq 0 ]
+then
+       for entry in t/*.txt
+       do
+               testfile $entry
+       done
+else
+       for entry in $@
+       do
+               testfile $entry
+       done
+fi