####################################################################
#
#    This file was generated using Parse::Yapp version 1.21.
#
#        Don't edit this file, use source file instead.
#
#             ANY CHANGE MADE HERE WILL BE LOST !
#
####################################################################
package Grammar::DAG::Parser;
use vars qw ( @ISA );
use strict;

@ISA= qw ( Parse::Yapp::Driver );
use Parse::Yapp::Driver;

#line 1 "lib/Grammar/DAG/Parser.yp"

=head1 NAME

Grammar::DAG::Parser - this module implements the parser for the DAG grammar

=head1 VERSION

Version 0.01

=cut

our $VERSION = '0.02';

=head1 DESCRIPTION

TODO

=head1 FUNCTIONS

TODO

=cut


sub new {
        my($class)=shift;
        ref($class)
    and $class=ref($class);

    my($self)=$class->SUPER::new( yyversion => '1.21',
                                  yystates =>
[
	{#State 0
		DEFAULT => -3,
		GOTOS => {
			'dag_file' => 1,
			'preamble' => 2
		}
	},
	{#State 1
		ACTIONS => {
			'' => 3
		}
	},
	{#State 2
		ACTIONS => {
			'AGOD_ID' => 4,
			'AGOD_PRE' => 5
		},
		GOTOS => {
			'rule' => 6,
			'rules' => 7
		}
	},
	{#State 3
		DEFAULT => 0
	},
	{#State 4
		ACTIONS => {
			";" => 8,
			'AGOD_ARROW' => 9,
			'MINI_PERL' => 10
		}
	},
	{#State 5
		ACTIONS => {
			'AGOD_ID' => 11
		}
	},
	{#State 6
		DEFAULT => -16,
		GOTOS => {
			'attrs' => 12
		}
	},
	{#State 7
		ACTIONS => {
			'AGOD_FINAL' => 13,
			'AGOD_ID' => 4
		},
		GOTOS => {
			'rule' => 14
		}
	},
	{#State 8
		DEFAULT => -8
	},
	{#State 9
		ACTIONS => {
			'AGOD_ID' => 15
		},
		GOTOS => {
			'quantifier' => 16,
			'rhs' => 17
		}
	},
	{#State 10
		ACTIONS => {
			";" => 18
		}
	},
	{#State 11
		ACTIONS => {
			'AGOD_ID' => 19,
			'MINI_PERL' => 20
		},
		GOTOS => {
			'list_rec' => 21,
			'pre_rule' => 22
		}
	},
	{#State 12
		ACTIONS => {
			'AGOD_FOUR_DOTS' => 23
		},
		DEFAULT => -7,
		GOTOS => {
			'attr' => 24
		}
	},
	{#State 13
		DEFAULT => -1
	},
	{#State 14
		DEFAULT => -16,
		GOTOS => {
			'attrs' => 25
		}
	},
	{#State 15
		ACTIONS => {
			'AGOD_QUANTIFIER' => 26
		},
		DEFAULT => -15
	},
	{#State 16
		DEFAULT => -13
	},
	{#State 17
		ACTIONS => {
			";" => 27,
			'AGOD_ID' => 15,
			'MINI_PERL' => 28
		},
		GOTOS => {
			'quantifier' => 29
		}
	},
	{#State 18
		DEFAULT => -9
	},
	{#State 19
		DEFAULT => -24
	},
	{#State 20
		DEFAULT => -5
	},
	{#State 21
		ACTIONS => {
			"," => 30
		},
		DEFAULT => -4
	},
	{#State 22
		DEFAULT => -2
	},
	{#State 23
		ACTIONS => {
			'AGOD_ID' => 31,
			'AGOD_PERL' => 32
		}
	},
	{#State 24
		DEFAULT => -17
	},
	{#State 25
		ACTIONS => {
			'AGOD_FOUR_DOTS' => 23
		},
		DEFAULT => -6,
		GOTOS => {
			'attr' => 24
		}
	},
	{#State 26
		DEFAULT => -14
	},
	{#State 27
		DEFAULT => -10
	},
	{#State 28
		ACTIONS => {
			";" => 33
		}
	},
	{#State 29
		DEFAULT => -12
	},
	{#State 30
		ACTIONS => {
			'AGOD_ID' => 34
		}
	},
	{#State 31
		ACTIONS => {
			"[" => 35
		},
		DEFAULT => -22,
		GOTOS => {
			'list' => 36
		}
	},
	{#State 32
		DEFAULT => -21
	},
	{#State 33
		DEFAULT => -11
	},
	{#State 34
		DEFAULT => -25
	},
	{#State 35
		ACTIONS => {
			'AGOD_ID' => 19
		},
		GOTOS => {
			'list_rec' => 37
		}
	},
	{#State 36
		ACTIONS => {
			"&" => 38,
			"=" => 39,
			'AGOD_ATTRIB' => 40
		}
	},
	{#State 37
		ACTIONS => {
			"," => 30,
			"]" => 41
		}
	},
	{#State 38
		ACTIONS => {
			'AGOD_PERL' => 42
		}
	},
	{#State 39
		ACTIONS => {
			'AGOD_PERL' => 43
		}
	},
	{#State 40
		ACTIONS => {
			'AGOD_PERL' => 44
		}
	},
	{#State 41
		DEFAULT => -23
	},
	{#State 42
		DEFAULT => -19
	},
	{#State 43
		DEFAULT => -18
	},
	{#State 44
		DEFAULT => -20
	}
],
                                  yyrules  =>
[
	[#Rule 0
		 '$start', 2, undef
	],
	[#Rule 1
		 'dag_file', 3,
sub
#line 30 "lib/Grammar/DAG/Parser.yp"
{ +{'%PRE'=>$_[1],'%DAG'=>$_[2],'%TAIL'=>$_[3]} }
	],
	[#Rule 2
		 'preamble', 4,
sub
#line 33 "lib/Grammar/DAG/Parser.yp"
{ unshift @{$_[1]},{$_[3]=>$_[4]}; $_[1] }
	],
	[#Rule 3
		 'preamble', 0,
sub
#line 34 "lib/Grammar/DAG/Parser.yp"
{ +[] }
	],
	[#Rule 4
		 'pre_rule', 1,
sub
#line 37 "lib/Grammar/DAG/Parser.yp"
{ @{$_[1]}==1 ? @{$_[1]}[0] : $_[1] }
	],
	[#Rule 5
		 'pre_rule', 1,
sub
#line 38 "lib/Grammar/DAG/Parser.yp"
{ $_[1] }
	],
	[#Rule 6
		 'rules', 3,
sub
#line 41 "lib/Grammar/DAG/Parser.yp"
{ +{%{$_[1]},$_[2]->[0]=>{%{$_[3]},%{$_[2]->[1]}}} }
	],
	[#Rule 7
		 'rules', 2,
sub
#line 42 "lib/Grammar/DAG/Parser.yp"
{ +{         $_[1]->[0]=>{%{$_[2]},%{$_[1]->[1]}}} }
	],
	[#Rule 8
		 'rule', 2,
sub
#line 45 "lib/Grammar/DAG/Parser.yp"
{[$_[1], {'%RHS' => []    }]}
	],
	[#Rule 9
		 'rule', 3,
sub
#line 46 "lib/Grammar/DAG/Parser.yp"
{[$_[1], {'%MONO' => $_[2] }]}
	],
	[#Rule 10
		 'rule', 4,
sub
#line 47 "lib/Grammar/DAG/Parser.yp"
{[$_[1], {'%RHS' => $_[3] }]}
	],
	[#Rule 11
		 'rule', 5,
sub
#line 48 "lib/Grammar/DAG/Parser.yp"
{[$_[1], {'%RHS' => $_[3], '%MONO' => $_[4] }]}
	],
	[#Rule 12
		 'rhs', 2,
sub
#line 51 "lib/Grammar/DAG/Parser.yp"
{ push @{$_[1]}, $_[2]; $_[1] }
	],
	[#Rule 13
		 'rhs', 1,
sub
#line 52 "lib/Grammar/DAG/Parser.yp"
{             [ $_[1] ]  }
	],
	[#Rule 14
		 'quantifier', 2,
sub
#line 55 "lib/Grammar/DAG/Parser.yp"
{+{$_[1] => $_[2]}}
	],
	[#Rule 15
		 'quantifier', 1,
sub
#line 56 "lib/Grammar/DAG/Parser.yp"
{+{$_[1] => 1    }}
	],
	[#Rule 16
		 'attrs', 0,
sub
#line 59 "lib/Grammar/DAG/Parser.yp"
{+{                 }}
	],
	[#Rule 17
		 'attrs', 2,
sub
#line 60 "lib/Grammar/DAG/Parser.yp"
{+{%{$_[1]},%{$_[2]}}}
	],
	[#Rule 18
		 'attr', 5,
sub
#line 63 "lib/Grammar/DAG/Parser.yp"
{ +{$_[2] => { NEEDS=>$_[3], RETURNS=>$_[5] }}}
	],
	[#Rule 19
		 'attr', 5,
sub
#line 64 "lib/Grammar/DAG/Parser.yp"
{+{$_[2] => { NEEDS=>$_[3], EXECUTE=>$_[5] }}}
	],
	[#Rule 20
		 'attr', 5,
sub
#line 65 "lib/Grammar/DAG/Parser.yp"
{+{$_[2] => { NEEDS=>$_[3], ATTRIB=>$_[5] }}}
	],
	[#Rule 21
		 'attr', 2,
sub
#line 66 "lib/Grammar/DAG/Parser.yp"
{+{'%BEGIN' => $_[2]}}
	],
	[#Rule 22
		 'list', 0,
sub
#line 69 "lib/Grammar/DAG/Parser.yp"
{ []    }
	],
	[#Rule 23
		 'list', 3,
sub
#line 70 "lib/Grammar/DAG/Parser.yp"
{ $_[2] }
	],
	[#Rule 24
		 'list_rec', 1,
sub
#line 73 "lib/Grammar/DAG/Parser.yp"
{ [$_[1]]                     }
	],
	[#Rule 25
		 'list_rec', 3,
sub
#line 74 "lib/Grammar/DAG/Parser.yp"
{ push @{$_[1]}, $_[3]; $_[1] }
	]
],
                                  @_);
    bless($self,$class);
}

#line 76 "lib/Grammar/DAG/Parser.yp"


=head2 yylex

Function used to tokenize source code.

=cut

use Regexp::Common qw /balanced/;
our $rt;

sub yylex {
  my $text = shift;

  $text = $rt if defined $rt;
  $text =~ s!^(\s|#.*)*!!;
  my $word = '(\!?(\.\w|\w\d+|\w|<\w+>)+)';
  for ($text) {
    if (/^$word/)                 { $rt = $'; return ('AGOD_ID', $&); }
    #if (/^([\w,]+)/)            { $rt = $'; return ('MY_LIST', $1); }
    if (/^--->/)                  { $rt = $'; return ('AGOD_ARROW', $&); }
    if (/^[*+?]/)                 { $rt = $'; return ('AGOD_QUANTIFIER', $&); }
    if (/^::/)                    { $rt = $'; return ('AGOD_FOUR_DOTS', $&); }
    if (/^(\[|\])/)               { $rt = $'; return ($&, $&); }
    if (/^do\b/)                  { $rt = $'; return ('&','&'); }
    if (/^:=/)                    { $rt = $'; return ('AGOD_ATTRIB', $&); }
    if (/^[,;&=]/)                { $rt = $'; return ($&, $&); }
    if (/^%%(.*)/s)                { $rt = $'; return ('AGOD_FINAL', $1); }
    if (/^%/)                     { $rt = $'; return ('AGOD_PRE', $&); }
    if (/^($RE{balanced}{-parens=>'{}'})/) { $rt = $'; return ('MINI_PERL', $&); }
    if (/^(\{(\n|.)*?\})(\s|\n)*\n(%%|::|\s*($word\s*(--->|;(\s|\n)*($word\s*;(\s|\n)*)*(::|%%))))/) {
      ### WEIRD, but works
      $rt = $4.$';
      return ('AGOD_PERL', $1);
    }
    $rt = $';
    return undef
  }
}

=head2 yyerror

Fuction used to report errors.

=cut

sub yyerror {
	my $msg =shift;
	die ("my error: $msg ($rt)");
}

1;
__END__

1;
