Subject: | YYExpect() dies when parser is generated with -v option |
In one particular program, YYExpect() dies when the parser is generated
with the -v option, but works OK when the parser is generated without
that option.
The error seams related to the empty rule 'sos' below: if the rule is
removed, the exception does not occur.
I have stripped down the program to the minimum:
-------- START bug_YYExpect.eyp --------
%{
my $stmt;
%}
%%
prg: stmt * ;
sos: { $stmt++ } ;
stmt: '\n' | sos 'nop' '\n' ;
%%
my @input = ("nop", "\n", "org", "\n");
sub my_lexer {
my $t = shift(@input);
($t, $t);
}
sub my_error {
my($self) = @_;
my $t = $self->YYCurval || "eof";
my @expected = $self->YYExpect();
die("Statement $stmt: Syntax error at $t. Expected @expected.\n");
}
sub test_main {
bug_YYExpect->new->YYParse( yylex => \&my_lexer, yyerror => \&my_error
);
}
-------- END bug_YYExpect.eyp --------
When the parser is generated whith -v, and called as below:
Show quoted text
> eyapp -v bug_YYExpect.eyp
> perl -Mbug_YYExpect -e "bug_YYExpect->test_main"
the result is: Modification of non-creatable array value attempted,
subscript -1 at C:/Perl/site/lib/Parse/Eyapp/Driver.pm line 1015
When the parser is generated whithout -v, and called as below:
Show quoted text> eyapp bug_YYExpect.eyp
> perl -Mbug_YYExpect -e "bug_YYExpect->test_main"
the result is as expected: Statement 2: Syntax error at org. Expected
nop.
The state description for State 1 is different when generated with and
without -v (in the generated .pm file):
-------- bug_YYExpect.pm generated without -v --------
...
{#State 1
ACTIONS => {
'' => -3,
"\n" => 5
},
DEFAULT => -4,
GOTOS => {
'stmt' => 3,
'sos' => 4
}
},
...
-------- bug_YYExpect.pm generated with -v --------
...
{#State 1
ACTIONS => {
'' => -3,
"nop" => -4,
"\n" => 5
},
GOTOS => {
'stmt' => 3,
'sos' => 4
}
},
...
--------
I do not know if this is the cause of the problem, but when tracing into
Parse::Eyapp::Driver.pm, function YYSymbolicSim(), there are two strange
things:
line 1012: "if (@STACK > length)" --> shouldn't it be $length?
line 1013: splice @STACK, -$length;" --> when $length is 0, the whole
@STACK is emptied; is this intended?
I've tried to replace line 1012 by "if ($length < 0 && @STACK >
$length)", and YYExpect() no longer dies, but returns a list with
("\n"), which is not expected; it should return ("nop").
I hope this lengthy description helps pin-point the bug. For now I will
stop using -v, unless there is a conflict in the grammar.
Best regards,
Paulo
P.S.:
Show quoted text> perl -v
This is perl, v5.10.1 built for MSWin32-x86-multi-thread
(with 2 registered patches, see perl -V for more detail)
Copyright 1987-2009, Larry Wall
Binary build 1006 [291086] provided by ActiveState
http://www.ActiveState.com
Built Aug 24 2009 13:48:26