#################################################################### # # This file was generated using Parse::Yapp version 1.02. # # Don't edit this file, use source file instead. # # ANY CHANGE MADE HERE WILL BE LOST ! # #################################################################### package prfparser; use vars qw ( @ISA ); use strict; @ISA= qw ( Parse::Yapp::Driver ); #Included Parse/Yapp/Driver.pm file---------------------------------------- { # # Module Parse::Yapp::Driver # # This module is part of the Parse::Yapp package available on your # nearest CPAN # # Any use of this module in a standalone parser make the included # text under the same copyright as the Parse::Yapp module itself. # # This notice should remain unchanged. # # (c) Copyright 1998-1999 Francois Desarmenien, all rights reserved. # (see the pod text in Parse::Yapp module for use and distribution rights) # package Parse::Yapp::Driver; require 5.004; use strict; use vars qw ( $VERSION $COMPATIBLE $FILENAME ); $VERSION = '1.02'; $COMPATIBLE = '0.07'; $FILENAME=__FILE__; use Carp; #Known parameters, all starting with YY (leading YY will be discarded) my(%params)=(YYLEX => 'CODE', 'YYERROR' => 'CODE', YYVERSION => '', YYRULES => 'ARRAY', YYSTATES => 'ARRAY', YYDEBUG => ''); #Mandatory parameters my(@params)=('LEX','RULES','STATES'); sub new { my($class)=shift; my($errst,$nberr,$token,$value,$check,$dotpos); my($self)={ ERROR => \&_Error, ERRST => \$errst, NBERR => \$nberr, TOKEN => \$token, VALUE => \$value, DOTPOS => \$dotpos, STACK => [], DEBUG => 0, CHECK => \$check }; _CheckParams( [], \%params, \@_, $self ); exists($$self{VERSION}) and $$self{VERSION} < $COMPATIBLE and croak "Yapp driver version $VERSION ". "incompatible with version $$self{VERSION}:\n". "Please recompile parser module."; ref($class) and $class=ref($class); bless($self,$class); } sub YYParse { my($self)=shift; my($retval); _CheckParams( \@params, \%params, \@_, $self ); if($$self{DEBUG}) { _DBLoad(); $retval = eval '$self->_DBParse()';#Do not create stab entry on compile $@ and die $@; } else { $retval = $self->_Parse(); } $retval } sub YYData { my($self)=shift; exists($$self{USER}) or $$self{USER}={}; $$self{USER}; } sub YYErrok { my($self)=shift; ${$$self{ERRST}}=0; undef; } sub YYNberr { my($self)=shift; ${$$self{NBERR}}; } sub YYRecovering { my($self)=shift; ${$$self{ERRST}} != 0; } sub YYAbort { my($self)=shift; ${$$self{CHECK}}='ABORT'; undef; } sub YYAccept { my($self)=shift; ${$$self{CHECK}}='ACCEPT'; undef; } sub YYError { my($self)=shift; ${$$self{CHECK}}='ERROR'; undef; } sub YYSemval { my($self)=shift; my($index)= $_[0] - ${$$self{DOTPOS}} - 1; $index < 0 and -$index <= @{$$self{STACK}} and return $$self{STACK}[$index][1]; undef; #Invalid index } sub YYCurtok { my($self)=shift; @_ and ${$$self{TOKEN}}=$_[0]; ${$$self{TOKEN}}; } sub YYCurval { my($self)=shift; @_ and ${$$self{VALUE}}=$_[0]; ${$$self{VALUE}}; } sub YYExpect { my($self)=shift; keys %{$self->{STATES}[$self->{STACK}[-1][0]]{ACTIONS}} } sub YYLexer { my($self)=shift; $$self{LEX}; } ################# # Private stuff # ################# sub _CheckParams { my($mandatory,$checklist,$inarray,$outhash)=@_; my($prm,$value); my($prmlst)={}; while(($prm,$value)=splice(@$inarray,0,2)) { $prm=uc($prm); exists($$checklist{$prm}) or croak("Unknow parameter '$prm'"); ref($value) eq $$checklist{$prm} or croak("Invalid value for parameter '$prm'"); $prm=unpack('@2A*',$prm); $$outhash{$prm}=$value; } for (@$mandatory) { exists($$outhash{$_}) or croak("Missing mandatory parameter '".lc($_)."'"); } } sub _Error { print "Parse error.\n"; } sub _DBLoad { { no strict 'refs'; exists(${__PACKAGE__.'::'}{_DBParse})#Already loaded ? and return; } my($fname)=__FILE__; my(@drv); open(DRV,"<$fname") or die "Report this as a BUG: Cannot open $fname"; while() { /^\s*sub\s+_Parse\s*{\s*$/ .. /^\s*}\s*#\s*_Parse\s*$/ and do { s/^#DBG>//; push(@drv,$_); } } close(DRV); $drv[0]=~s/_P/_DBP/; eval join('',@drv); } #Note that for loading debugging version of the driver, #this file will be parsed from 'sub _Parse' up to '}#_Parse' inclusive. #So, DO NOT remove comment at end of sub !!! sub _Parse { my($self)=shift; my($rules,$states,$lex,$error) = @$self{ 'RULES', 'STATES', 'LEX', 'ERROR' }; my($errstatus,$nberror,$token,$value,$stack,$check,$dotpos) = @$self{ 'ERRST', 'NBERR', 'TOKEN', 'VALUE', 'STACK', 'CHECK', 'DOTPOS' }; #DBG> my($debug)=$$self{DEBUG}; #DBG> my($dbgerror)=0; #DBG> my($ShowCurToken) = sub { #DBG> my($tok)='>'; #DBG> for (split('',$$token)) { #DBG> $tok.= (ord($_) < 32 or ord($_) > 126) #DBG> ? sprintf('<%02X>',ord($_)) #DBG> : $_; #DBG> } #DBG> $tok.='<'; #DBG> }; $$errstatus=0; $$nberror=0; ($$token,$$value)=(undef,undef); @$stack=( [ 0, undef ] ); $$check=''; while(1) { my($actions,$act,$stateno); $stateno=$$stack[-1][0]; $actions=$$states[$stateno]; #DBG> print STDERR ('-' x 40),"\n"; #DBG> $debug & 0x2 #DBG> and print STDERR "In state $stateno:\n"; #DBG> $debug & 0x08 #DBG> and print STDERR "Stack:[". #DBG> join(',',map { $$_[0] } @$stack). #DBG> "]\n"; if (exists($$actions{ACTIONS})) { defined($$token) or do { ($$token,$$value)=&$lex($self); #DBG> $debug & 0x01 #DBG> and print STDERR "Need token. Got ".&$ShowCurToken."\n"; }; $act= exists($$actions{ACTIONS}{$$token}) ? $$actions{ACTIONS}{$$token} : exists($$actions{DEFAULT}) ? $$actions{DEFAULT} : undef; } else { $act=$$actions{DEFAULT}; #DBG> $debug & 0x01 #DBG> and print STDERR "Don't need token.\n"; } defined($act) and do { $act > 0 and do { #shift #DBG> $debug & 0x04 #DBG> and print STDERR "Shift and go to state $act.\n"; $$errstatus and do { --$$errstatus; #DBG> $debug & 0x10 #DBG> and $dbgerror #DBG> and $$errstatus == 0 #DBG> and do { #DBG> print STDERR "**End of Error recovery.\n"; #DBG> $dbgerror=0; #DBG> }; }; push(@$stack,[ $act, $$value ]); $$token ne '' #Don't eat the eof and $$token=$$value=undef; next; }; #reduce my($lhs,$len,$code,@sempar,$semval); ($lhs,$len,$code)=@{$$rules[-$act]}; #DBG> $debug & 0x04 #DBG> and $act #DBG> and print STDERR "Reduce using rule ".-$act." ($lhs,$len): "; $act or $self->YYAccept(); $$dotpos=$len; unpack('A1',$lhs) eq '@' #In line rule and do { $lhs =~ /^\@[0-9]+\-([0-9]+)$/ or die "In line rule name '$lhs' ill formed: ". "report it as a BUG.\n"; $$dotpos = $1; }; @sempar = $$dotpos ? map { $$_[1] } @$stack[ -$$dotpos .. -1 ] : (); $semval = $code ? &$code( $self, @sempar ) : @sempar ? $sempar[0] : undef; splice(@$stack,-$len,$len); $$check eq 'ACCEPT' and do { #DBG> $debug & 0x04 #DBG> and print STDERR "Accept.\n"; return($semval); }; $$check eq 'ABORT' and do { #DBG> $debug & 0x04 #DBG> and print STDERR "Abort.\n"; return(undef); }; #DBG> $debug & 0x04 #DBG> and print STDERR "Back to state $$stack[-1][0], then "; $$check eq 'ERROR' or do { #DBG> $debug & 0x04 #DBG> and print STDERR #DBG> "go to state $$states[$$stack[-1][0]]{GOTOS}{$lhs}.\n"; #DBG> $debug & 0x10 #DBG> and $dbgerror #DBG> and $$errstatus == 0 #DBG> and do { #DBG> print STDERR "**End of Error recovery.\n"; #DBG> $dbgerror=0; #DBG> }; push(@$stack, [ $$states[$$stack[-1][0]]{GOTOS}{$lhs}, $semval ]); $$check=''; next; }; #DBG> $debug & 0x04 #DBG> and print STDERR "Forced Error recovery.\n"; $$check=''; }; #Error $$errstatus or do { $$errstatus = 1; &$error($self); $$errstatus # if 0, then YYErrok has been called or next; # so continue parsing #DBG> $debug & 0x10 #DBG> and do { #DBG> print STDERR "**Entering Error recovery.\n"; #DBG> ++$dbgerror; #DBG> }; ++$$nberror; }; $$errstatus == 3 #The next token is not valid: discard it and do { $$token eq '' # End of input: no hope and do { #DBG> $debug & 0x10 #DBG> and print STDERR "**At eof: aborting.\n"; return(undef); }; #DBG> $debug & 0x10 #DBG> and print STDERR "**Dicard invalid token ".&$ShowCurToken.".\n"; $$token=$$value=undef; }; $$errstatus=3; while( @$stack and ( not exists($$states[$$stack[-1][0]]{ACTIONS}) or not exists($$states[$$stack[-1][0]]{ACTIONS}{error}) or $$states[$$stack[-1][0]]{ACTIONS}{error} <= 0)) { #DBG> $debug & 0x10 #DBG> and print STDERR "**Pop state $$stack[-1][0].\n"; pop(@$stack); } @$stack or do { #DBG> $debug & 0x10 #DBG> and print STDERR "**No state left on stack: aborting.\n"; return(undef); }; #shift the error token #DBG> $debug & 0x10 #DBG> and print STDERR "**Shift \$error token and go to state ". #DBG> $$states[$$stack[-1][0]]{ACTIONS}{error}. #DBG> ".\n"; push(@$stack, [ $$states[$$stack[-1][0]]{ACTIONS}{error}, undef ]); } #never reached croak("Error in driver logic. Please, report it as a BUG"); }#_Parse #DO NOT remove comment 1; } #End of include-------------------------------------------------- sub new { my($class)=shift; ref($class) and $class=ref($class); my($self)=$class->SUPER::new( yyversion => '1.02', yystates => [ {#State 0 ACTIONS => { 'LBR' => 1 }, GOTOS => { 'theories' => 2, 'b_theory' => 3 } }, {#State 1 ACTIONS => { 'IDENT' => 5, 'PIPE' => 6 }, GOTOS => { 'ident_or_pipe' => 4 } }, {#State 2 ACTIONS => { '' => 7, 'LBR' => 1 }, GOTOS => { 'b_theory' => 8 } }, {#State 3 DEFAULT => -2 }, {#State 4 ACTIONS => { 'LBR' => 9, 'RBR' => 12 }, GOTOS => { 'proofs' => 10, 'proof' => 11 } }, {#State 5 DEFAULT => -5 }, {#State 6 DEFAULT => -6 }, {#State 7 DEFAULT => -0 }, {#State 8 DEFAULT => -1 }, {#State 9 ACTIONS => { 'IDENT' => 5, 'PIPE' => 6 }, GOTOS => { 'ident_or_pipe' => 13 } }, {#State 10 ACTIONS => { 'LBR' => 9, 'RBR' => 15 }, GOTOS => { 'proof' => 14 } }, {#State 11 DEFAULT => -8 }, {#State 12 DEFAULT => -4 }, {#State 13 ACTIONS => { 'QUOT' => 16 }, GOTOS => { 'path' => 17 } }, {#State 14 DEFAULT => -7 }, {#State 15 DEFAULT => -3 }, {#State 16 ACTIONS => { 'LBR' => 18 }, GOTOS => { 'b_command' => 19 } }, {#State 17 ACTIONS => { 'RBR' => 20 } }, {#State 18 ACTIONS => { 'IDENT' => 21 } }, {#State 19 ACTIONS => { 'LBR' => 22, 'NIL' => 24 }, DEFAULT => -12, GOTOS => { 'b_list_of_paths' => 23 } }, {#State 20 DEFAULT => -9 }, {#State 21 ACTIONS => { 'LBR' => 25, 'QUOT' => 32, 'NIL' => 27, 'IDENT' => 28, 'OPTARG' => 33, 'PIPE' => 34, 'RBR' => 31, 'FNUM' => 30 }, GOTOS => { 'command_argument' => 26, 'command_arguments' => 29 } }, {#State 22 ACTIONS => { 'LBR' => 35 }, GOTOS => { 'list_of_paths' => 36 } }, {#State 23 ACTIONS => { 'NIL' => 37 } }, {#State 24 ACTIONS => { 'NIL' => 38 } }, {#State 25 ACTIONS => { 'LBR' => 25, 'QUOT' => 32, 'NIL' => 27, 'IDENT' => 28, 'OPTARG' => 33, 'PIPE' => 34, 'FNUM' => 30 }, GOTOS => { 'command_argument' => 26, 'command_arguments' => 39 } }, {#State 26 DEFAULT => -19 }, {#State 27 DEFAULT => -25 }, {#State 28 DEFAULT => -26 }, {#State 29 ACTIONS => { 'LBR' => 25, 'QUOT' => 32, 'NIL' => 27, 'IDENT' => 28, 'OPTARG' => 33, 'PIPE' => 34, 'RBR' => 41, 'FNUM' => 30 }, GOTOS => { 'command_argument' => 40 } }, {#State 30 DEFAULT => -24 }, {#State 31 DEFAULT => -16 }, {#State 32 DEFAULT => -21 }, {#State 33 DEFAULT => -23 }, {#State 34 DEFAULT => -22 }, {#State 35 ACTIONS => { 'QUOT' => 16 }, GOTOS => { 'path' => 42 } }, {#State 36 ACTIONS => { 'LBR' => 43, 'RBR' => 44 } }, {#State 37 DEFAULT => -10 }, {#State 38 DEFAULT => -11 }, {#State 39 ACTIONS => { 'LBR' => 25, 'QUOT' => 32, 'NIL' => 27, 'IDENT' => 28, 'OPTARG' => 33, 'PIPE' => 34, 'RBR' => 45, 'FNUM' => 30 }, GOTOS => { 'command_argument' => 40 } }, {#State 40 DEFAULT => -18 }, {#State 41 DEFAULT => -17 }, {#State 42 ACTIONS => { 'RBR' => 46 } }, {#State 43 ACTIONS => { 'QUOT' => 16 }, GOTOS => { 'path' => 47 } }, {#State 44 DEFAULT => -13 }, {#State 45 DEFAULT => -20 }, {#State 46 DEFAULT => -15 }, {#State 47 ACTIONS => { 'RBR' => 48 } }, {#State 48 DEFAULT => -14 } ], yyrules => [ [#Rule 0 '$start', 2, undef ], [#Rule 1 'theories', 2, sub #line 7 "prfparser.yp" { return $_[1] . $_[2]; } ], [#Rule 2 'theories', 1, sub #line 11 "prfparser.yp" { return $_[1]; } ], [#Rule 3 'b_theory', 4, sub #line 17 "prfparser.yp" { return "\n$_[3]\n"; } ], [#Rule 4 'b_theory', 3, sub #line 21 "prfparser.yp" { # empty theory return "\n\n"; } ], [#Rule 5 'ident_or_pipe', 1, undef ], [#Rule 6 'ident_or_pipe', 1, undef ], [#Rule 7 'proofs', 2, sub #line 37 "prfparser.yp" { return $_[1] . $_[2]; } ], [#Rule 8 'proofs', 1, sub #line 41 "prfparser.yp" { return $_[1]; } ], [#Rule 9 'proof', 4, sub #line 47 "prfparser.yp" { return "\n@{$_[3]}[1]\n"; } ], [#Rule 10 'path', 4, sub #line 53 "prfparser.yp" { warn "Strange path label '$_[1]' encountered" unless $_[1] =~ m/^\"\d*\"/; return [$_[1],$_[2] . $_[3]]; } ], [#Rule 11 'path', 4, sub #line 58 "prfparser.yp" { warn "Strange path label '$_[1]' encountered" unless $_[1] =~ m/^\"\d*\"/; return [$_[1],$_[2]]; } ], [#Rule 12 'path', 2, sub #line 63 "prfparser.yp" { warn "Strange path label '$_[1]' encountered" unless $_[1] =~ m/^\"\d*\"/; return [$_[1],$_[2]]; } ], [#Rule 13 'b_list_of_paths', 3, sub #line 70 "prfparser.yp" { if( $#{$_[2]} == 0 ) { # only one subpath encountered, don't print label return @{@{$_[2]}[0]}[1]; } else { # many subpaths return "\n" . join( '', map { "\n@{$_}[1]\n" } @{$_[2]} ) . "\n"; } } ], [#Rule 14 'list_of_paths', 4, sub #line 83 "prfparser.yp" { return [@{$_[1]},$_[3]]; } ], [#Rule 15 'list_of_paths', 3, sub #line 87 "prfparser.yp" { return [$_[2]]; # must start nesting } ], [#Rule 16 'b_command', 3, sub #line 93 "prfparser.yp" { return "$_[2]\n"; } ], [#Rule 17 'b_command', 4, sub #line 97 "prfparser.yp" { return "$_[2] $_[3]\n"; } ], [#Rule 18 'command_arguments', 2, sub #line 103 "prfparser.yp" { return "$_[1] $_[2]"; } ], [#Rule 19 'command_arguments', 1, sub #line 107 "prfparser.yp" { return $_[1]; } ], [#Rule 20 'command_argument', 3, sub #line 113 "prfparser.yp" { #warn "($_[2])"; return "($_[2])"; } ], [#Rule 21 'command_argument', 1, undef ], [#Rule 22 'command_argument', 1, undef ], [#Rule 23 'command_argument', 1, undef ], [#Rule 24 'command_argument', 1, undef ], [#Rule 25 'command_argument', 1, undef ], [#Rule 26 'command_argument', 1, undef ] ], @_); bless($self,$class); } #line 130 "prfparser.yp" sub _Error { exists $_[0]->YYData->{ERRMSG} and do { print $_[0]->YYData->{ERRMSG}; delete $_[0]->YYData->{ERRMSG}; return; }; print "\$_[0]->YYCurtok " . $_[0]->YYCurtok."\n"; print "\$_[0]->YYCurval " . $_[0]->YYCurval."\n"; print "\@\$_[0]->YYExpect " . (join " ", $_[0]->YYExpect )."\n"; print "\$_[0]->YYLexer " . $_[0]->YYLexer."\n"; print "substr(\$_[0]->YYData->{INPUT},0,21) " . substr($_[0]->YYData->{INPUT},0,21) . "\n"; print "Syntax error.\n"; } sub _Lexer { my($parser)=shift; $parser->YYData->{INPUT} = join( ' ', map { chomp; $_ } ) unless defined $parser->YYData->{INPUT}; $parser->YYData->{INPUT}=~ s/^[ \t]+//ms; # skip whitespaces etc. for ($parser->YYData->{INPUT}) { # print "parsing: " . substr($parser->YYData->{INPUT},0,21) . "...\n"; s/^(\"(?:\\\"|[^\"])*\")// and return( 'QUOT', $1 ); s/^(\|(?:\\\||[^\|])*\|)// and return( 'PIPE', $1 ); s/^(:[^ \t\n()]+)// and return( 'OPTARG', $1 ); s/^(-?\d+|-|\+|\*)// and return( 'FNUM', $1 ); s/^nil//i and return( 'NIL', 'NIL' ); s/^([a-zA-Z][^ \t\n()]*)// and return( 'IDENT',$1 ); s/^\)//s and return( 'RBR', ')' ); s/^\(//s and return( 'LBR', '(' ); s/^(.)//s and return($1,$1); } } sub indent { my @A = split "\n", $_[0]; my $result = ''; my $level = 0; for ( @A ) { if( m/^<\/(?:theory|proof|path)/ ) { $level-- } $result .= ("\t" x $level) . $_ . "\n"; if( m/^<(?:theory|proof|path)/ ) { $level++ } } return $result; } sub Run { my($self)=shift; print indent($self->YYParse( yylex => \&_Lexer, yyerror => \&_Error )); } my($calc)=new prfparser; $calc->Run; 1;