%{
=head1 SYNOPSIS
This example is here only for historical reasons.
The method C<YYRestoreLRAction> is deprecated.
See section 'SOLVING CONFLICTS WITH THE POSTPONED CONFLICT STRATEGY' in
http://search.cpan.org/perldoc?Parse::Eyapp::debuggingtut
This example illustrates how to dynamically
change the behavior of the parser for a shift-reduce conflict
Be sure C<DebugTail.pm> is reachable
compile it with
eyapp -b '' DynamicallyChangingTheParser2.eyp
execute the generated modulino with the option C<-t>:
./DynamicallyChangingTheParser2.pm -t
=head1 See instead
DynamicallyChangingTheParser.eyp
=cut
our $VERSION = '0.01';
use base q{DebugTail};
%}
%token D S
%tree bypass
%expect 1
%%
p: %name PROG
block +
;
block:
%name BLOCK
'{' ds ';' ss '}'
| %name SS
'{' ss '}'
;
ds:
%name MORE_Ds
D conflict ';' ds
| %name LAST_D
D conflict
{
# Recover former LALR action
$_[0]->YYRestoreLRAction('conflict', ';');
# Do whatever you want
goto &Parse::Eyapp::Driver::YYBuildAST;
}
;
ss:
%name SS
S ';' ss
| %name S
S
;
conflict:
/* empty. Just for dynamic precedence */
{
my $self = shift;
$self->YYSetReduce(';', 'LAST_D' ) if (${$self->input()} =~ m{^\s*;\s*S});
undef; # skip this node in the AST
}
;
%%
__PACKAGE__->lexer( \&DebugTail::lex);
my $prompt = 'Provide a statement like "{D; S} {D; D; S}" and press <CR><CTRL-D>: ';
__PACKAGE__->main($prompt) unless caller;