deprecated/buildtools/buildsystemtools/lib/Parse/Yapp/Driver.pm
author lorewang
Thu, 11 Nov 2010 11:26:32 +0800
changeset 677 44e49837144a
parent 655 3f65fd25dfd4
permissions -rw-r--r--
update release info
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     1
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     2
# Module Parse::Yapp::Driver
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     3
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     4
# This module is part of the Parse::Yapp package available on your
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     5
# nearest CPAN
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     6
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     7
# Any use of this module in a standalone parser make the included
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     8
# text under the same copyright as the Parse::Yapp module itself.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     9
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    10
# This notice should remain unchanged.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    11
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    12
# (c) Copyright 1998-2001 Francois Desarmenien, all rights reserved.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    13
# (see the pod text in Parse::Yapp module for use and distribution rights)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    14
#
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    15
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    16
package Parse::Yapp::Driver;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    17
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    18
require 5.004;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    19
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    20
use strict;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    21
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    22
use vars qw ( $VERSION $COMPATIBLE $FILENAME );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    23
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    24
$VERSION = '1.05';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    25
$COMPATIBLE = '0.07';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    26
$FILENAME=__FILE__;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    27
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    28
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    29
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    30
#Known parameters, all starting with YY (leading YY will be discarded)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    31
my(%params)=(YYLEX => 'CODE', 'YYERROR' => 'CODE', YYVERSION => '',
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    32
			 YYRULES => 'ARRAY', YYSTATES => 'ARRAY', YYDEBUG => '');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    33
#Mandatory parameters
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    34
my(@params)=('LEX','RULES','STATES');
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    35
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    36
sub new {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    37
    my($class)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    38
	my($errst,$nberr,$token,$value,$check,$dotpos);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    39
    my($self)={ ERROR => \&_Error,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    40
				ERRST => \$errst,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    41
                NBERR => \$nberr,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    42
				TOKEN => \$token,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    43
				VALUE => \$value,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    44
				DOTPOS => \$dotpos,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    45
				STACK => [],
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    46
				DEBUG => 0,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    47
				CHECK => \$check };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    48
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    49
	_CheckParams( [], \%params, \@_, $self );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    50
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    51
		exists($$self{VERSION})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    52
	and	$$self{VERSION} < $COMPATIBLE
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    53
	and	croak "Yapp driver version $VERSION ".
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    54
			  "incompatible with version $$self{VERSION}:\n".
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    55
			  "Please recompile parser module.";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    56
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    57
        ref($class)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    58
    and $class=ref($class);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    59
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    60
    bless($self,$class);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    61
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    62
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    63
sub YYParse {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    64
    my($self)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    65
    my($retval);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    66
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    67
	_CheckParams( \@params, \%params, \@_, $self );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    68
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    69
	if($$self{DEBUG}) {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    70
		_DBLoad();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    71
		$retval = eval '$self->_DBParse()';#Do not create stab entry on compile
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    72
        $@ and die $@;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    73
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    74
	else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    75
		$retval = $self->_Parse();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    76
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    77
    $retval
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    78
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    79
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    80
sub YYData {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    81
	my($self)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    82
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    83
		exists($$self{USER})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    84
	or	$$self{USER}={};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    85
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    86
	$$self{USER};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    87
	
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    88
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    89
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    90
sub YYErrok {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    91
	my($self)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    92
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    93
	${$$self{ERRST}}=0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    94
    undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    95
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    96
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    97
sub YYNberr {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    98
	my($self)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    99
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   100
	${$$self{NBERR}};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   101
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   102
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   103
sub YYRecovering {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   104
	my($self)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   105
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   106
	${$$self{ERRST}} != 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   107
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   108
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   109
sub YYAbort {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   110
	my($self)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   111
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   112
	${$$self{CHECK}}='ABORT';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   113
    undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   114
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   115
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   116
sub YYAccept {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   117
	my($self)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   118
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   119
	${$$self{CHECK}}='ACCEPT';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   120
    undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   121
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   122
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   123
sub YYError {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   124
	my($self)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   125
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   126
	${$$self{CHECK}}='ERROR';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   127
    undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   128
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   129
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   130
sub YYSemval {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   131
	my($self)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   132
	my($index)= $_[0] - ${$$self{DOTPOS}} - 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   133
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   134
		$index < 0
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   135
	and	-$index <= @{$$self{STACK}}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   136
	and	return $$self{STACK}[$index][1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   137
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   138
	undef;	#Invalid index
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   139
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   140
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   141
sub YYCurtok {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   142
	my($self)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   143
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   144
        @_
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   145
    and ${$$self{TOKEN}}=$_[0];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   146
    ${$$self{TOKEN}};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   147
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   148
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   149
sub YYCurval {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   150
	my($self)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   151
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   152
        @_
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   153
    and ${$$self{VALUE}}=$_[0];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   154
    ${$$self{VALUE}};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   155
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   156
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   157
sub YYExpect {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   158
    my($self)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   159
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   160
    keys %{$self->{STATES}[$self->{STACK}[-1][0]]{ACTIONS}}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   161
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   162
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   163
sub YYLexer {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   164
    my($self)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   165
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   166
	$$self{LEX};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   167
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   168
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   169
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   170
#################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   171
# Private stuff #
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   172
#################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   173
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   174
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   175
sub _CheckParams {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   176
	my($mandatory,$checklist,$inarray,$outhash)=@_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   177
	my($prm,$value);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   178
	my($prmlst)={};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   179
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   180
	while(($prm,$value)=splice(@$inarray,0,2)) {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   181
        $prm=uc($prm);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   182
			exists($$checklist{$prm})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   183
		or	croak("Unknow parameter '$prm'");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   184
			ref($value) eq $$checklist{$prm}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   185
		or	croak("Invalid value for parameter '$prm'");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   186
        $prm=unpack('@2A*',$prm);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   187
		$$outhash{$prm}=$value;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   188
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   189
	for (@$mandatory) {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   190
			exists($$outhash{$_})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   191
		or	croak("Missing mandatory parameter '".lc($_)."'");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   192
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   193
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   194
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   195
sub _Error {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   196
	print "Parse error.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   197
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   198
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   199
sub _DBLoad {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   200
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   201
		no strict 'refs';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   202
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   203
			exists(${__PACKAGE__.'::'}{_DBParse})#Already loaded ?
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   204
		and	return;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   205
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   206
	my($fname)=__FILE__;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   207
	my(@drv);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   208
	open(DRV,"<$fname") or die "Report this as a BUG: Cannot open $fname";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   209
	while(<DRV>) {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   210
                	/^\s*sub\s+_Parse\s*{\s*$/ .. /^\s*}\s*#\s*_Parse\s*$/
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   211
        	and     do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   212
                	s/^#DBG>//;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   213
                	push(@drv,$_);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   214
        	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   215
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   216
	close(DRV);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   217
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   218
	$drv[0]=~s/_P/_DBP/;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   219
	eval join('',@drv);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   220
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   221
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   222
#Note that for loading debugging version of the driver,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   223
#this file will be parsed from 'sub _Parse' up to '}#_Parse' inclusive.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   224
#So, DO NOT remove comment at end of sub !!!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   225
sub _Parse {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   226
    my($self)=shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   227
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   228
	my($rules,$states,$lex,$error)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   229
     = @$self{ 'RULES', 'STATES', 'LEX', 'ERROR' };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   230
	my($errstatus,$nberror,$token,$value,$stack,$check,$dotpos)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   231
     = @$self{ 'ERRST', 'NBERR', 'TOKEN', 'VALUE', 'STACK', 'CHECK', 'DOTPOS' };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   232
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   233
#DBG>	my($debug)=$$self{DEBUG};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   234
#DBG>	my($dbgerror)=0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   235
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   236
#DBG>	my($ShowCurToken) = sub {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   237
#DBG>		my($tok)='>';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   238
#DBG>		for (split('',$$token)) {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   239
#DBG>			$tok.=		(ord($_) < 32 or ord($_) > 126)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   240
#DBG>					?	sprintf('<%02X>',ord($_))
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   241
#DBG>					:	$_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   242
#DBG>		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   243
#DBG>		$tok.='<';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   244
#DBG>	};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   245
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   246
	$$errstatus=0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   247
	$$nberror=0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   248
	($$token,$$value)=(undef,undef);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   249
	@$stack=( [ 0, undef ] );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   250
	$$check='';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   251
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   252
    while(1) {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   253
        my($actions,$act,$stateno);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   254
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   255
        $stateno=$$stack[-1][0];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   256
        $actions=$$states[$stateno];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   257
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   258
#DBG>	print STDERR ('-' x 40),"\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   259
#DBG>		$debug & 0x2
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   260
#DBG>	and	print STDERR "In state $stateno:\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   261
#DBG>		$debug & 0x08
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   262
#DBG>	and	print STDERR "Stack:[".
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   263
#DBG>					 join(',',map { $$_[0] } @$stack).
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   264
#DBG>					 "]\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   265
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   266
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   267
        if  (exists($$actions{ACTIONS})) {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   268
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   269
				defined($$token)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   270
            or	do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   271
				($$token,$$value)=&$lex($self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   272
#DBG>				$debug & 0x01
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   273
#DBG>			and	print STDERR "Need token. Got ".&$ShowCurToken."\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   274
			};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   275
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   276
            $act=   exists($$actions{ACTIONS}{$$token})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   277
                    ?   $$actions{ACTIONS}{$$token}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   278
                    :   exists($$actions{DEFAULT})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   279
                        ?   $$actions{DEFAULT}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   280
                        :   undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   281
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   282
        else {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   283
            $act=$$actions{DEFAULT};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   284
#DBG>			$debug & 0x01
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   285
#DBG>		and	print STDERR "Don't need token.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   286
        }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   287
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   288
            defined($act)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   289
        and do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   290
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   291
                $act > 0
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   292
            and do {        #shift
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   293
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   294
#DBG>				$debug & 0x04
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   295
#DBG>			and	print STDERR "Shift and go to state $act.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   296
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   297
					$$errstatus
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   298
				and	do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   299
					--$$errstatus;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   300
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   301
#DBG>					$debug & 0x10
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   302
#DBG>				and	$dbgerror
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   303
#DBG>				and	$$errstatus == 0
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   304
#DBG>				and	do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   305
#DBG>					print STDERR "**End of Error recovery.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   306
#DBG>					$dbgerror=0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   307
#DBG>				};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   308
				};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   309
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   310
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   311
                push(@$stack,[ $act, $$value ]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   312
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   313
					$$token ne ''	#Don't eat the eof
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   314
				and	$$token=$$value=undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   315
                next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   316
            };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   317
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   318
            #reduce
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   319
            my($lhs,$len,$code,@sempar,$semval);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   320
            ($lhs,$len,$code)=@{$$rules[-$act]};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   321
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   322
#DBG>			$debug & 0x04
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   323
#DBG>		and	$act
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   324
#DBG>		and	print STDERR "Reduce using rule ".-$act." ($lhs,$len): ";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   325
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   326
                $act
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   327
            or  $self->YYAccept();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   328
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   329
            $$dotpos=$len;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   330
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   331
                unpack('A1',$lhs) eq '@'    #In line rule
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   332
            and do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   333
                    $lhs =~ /^\@[0-9]+\-([0-9]+)$/
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   334
                or  die "In line rule name '$lhs' ill formed: ".
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   335
                        "report it as a BUG.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   336
                $$dotpos = $1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   337
            };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   338
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   339
            @sempar =       $$dotpos
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   340
                        ?   map { $$_[1] } @$stack[ -$$dotpos .. -1 ]
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   341
                        :   ();
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   342
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   343
            $semval = $code ? &$code( $self, @sempar )
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   344
                            : @sempar ? $sempar[0] : undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   345
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   346
            splice(@$stack,-$len,$len);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   347
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   348
                $$check eq 'ACCEPT'
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   349
            and do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   350
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   351
#DBG>			$debug & 0x04
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   352
#DBG>		and	print STDERR "Accept.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   353
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   354
				return($semval);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   355
			};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   356
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   357
                $$check eq 'ABORT'
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   358
            and	do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   359
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   360
#DBG>			$debug & 0x04
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   361
#DBG>		and	print STDERR "Abort.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   362
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   363
				return(undef);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   364
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   365
			};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   366
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   367
#DBG>			$debug & 0x04
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   368
#DBG>		and	print STDERR "Back to state $$stack[-1][0], then ";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   369
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   370
                $$check eq 'ERROR'
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   371
            or  do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   372
#DBG>				$debug & 0x04
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   373
#DBG>			and	print STDERR 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   374
#DBG>				    "go to state $$states[$$stack[-1][0]]{GOTOS}{$lhs}.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   375
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   376
#DBG>				$debug & 0x10
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   377
#DBG>			and	$dbgerror
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   378
#DBG>			and	$$errstatus == 0
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   379
#DBG>			and	do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   380
#DBG>				print STDERR "**End of Error recovery.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   381
#DBG>				$dbgerror=0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   382
#DBG>			};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   383
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   384
			    push(@$stack,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   385
                     [ $$states[$$stack[-1][0]]{GOTOS}{$lhs}, $semval ]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   386
                $$check='';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   387
                next;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   388
            };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   389
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   390
#DBG>			$debug & 0x04
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   391
#DBG>		and	print STDERR "Forced Error recovery.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   392
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   393
            $$check='';
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   394
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   395
        };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   396
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   397
        #Error
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   398
            $$errstatus
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   399
        or   do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   400
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   401
            $$errstatus = 1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   402
            &$error($self);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   403
                $$errstatus # if 0, then YYErrok has been called
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   404
            or  next;       # so continue parsing
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   405
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   406
#DBG>			$debug & 0x10
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   407
#DBG>		and	do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   408
#DBG>			print STDERR "**Entering Error recovery.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   409
#DBG>			++$dbgerror;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   410
#DBG>		};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   411
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   412
            ++$$nberror;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   413
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   414
        };
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   415
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   416
			$$errstatus == 3	#The next token is not valid: discard it
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   417
		and	do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   418
				$$token eq ''	# End of input: no hope
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   419
			and	do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   420
#DBG>				$debug & 0x10
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   421
#DBG>			and	print STDERR "**At eof: aborting.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   422
				return(undef);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   423
			};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   424
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   425
#DBG>			$debug & 0x10
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   426
#DBG>		and	print STDERR "**Dicard invalid token ".&$ShowCurToken.".\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   427
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   428
			$$token=$$value=undef;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   429
		};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   430
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   431
        $$errstatus=3;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   432
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   433
		while(	  @$stack
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   434
			  and (		not exists($$states[$$stack[-1][0]]{ACTIONS})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   435
			        or  not exists($$states[$$stack[-1][0]]{ACTIONS}{error})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   436
					or	$$states[$$stack[-1][0]]{ACTIONS}{error} <= 0)) {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   437
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   438
#DBG>			$debug & 0x10
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   439
#DBG>		and	print STDERR "**Pop state $$stack[-1][0].\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   440
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   441
			pop(@$stack);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   442
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   443
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   444
			@$stack
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   445
		or	do {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   446
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   447
#DBG>			$debug & 0x10
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   448
#DBG>		and	print STDERR "**No state left on stack: aborting.\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   449
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   450
			return(undef);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   451
		};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   452
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   453
		#shift the error token
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   454
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   455
#DBG>			$debug & 0x10
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   456
#DBG>		and	print STDERR "**Shift \$error token and go to state ".
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   457
#DBG>						 $$states[$$stack[-1][0]]{ACTIONS}{error}.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   458
#DBG>						 ".\n";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   459
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   460
		push(@$stack, [ $$states[$$stack[-1][0]]{ACTIONS}{error}, undef ]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   461
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   462
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   463
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   464
    #never reached
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   465
	croak("Error in driver logic. Please, report it as a BUG");
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   466
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   467
}#_Parse
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   468
#DO NOT remove comment
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   469
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   470
1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   471