debug parameter

$parser->YYParse() にパラメーターを渡す

%%
input:    #empty
        | input line
;

line:     '\n'
        | 'a' '\n'    { print "$_[1]\n" }
        | error '\n'  { $_[0]->YYErrok  }
;

%%

sub _Error {
        exists $_[0]->YYData->{ERRMSG}
    and do {
        print  $_[0]->YYData->{ERRMSG};
        delete $_[0]->YYData->{ERRMSG};
        return;
    };
    print "Syntax error.\n";
}

sub _Lexer {
    my($parser)=shift;

        $parser->YYData->{INPUT}
    or  $parser->YYData->{INPUT} = <STDIN>
    or  return('',undef);

    $parser->YYData->{INPUT}=~s/^[ \t]//;

    for ($parser->YYData->{INPUT}) {
        s/^(.)//s
                and return($1,$1);
    }
}

sub Run {
    my($self)=shift;
    $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error, yydebug => 0x1f);
}

my($t)=new Test;
$t->Run;

で、「a」「改行」「C-d」を入力

----------------------------------------
In state 0:
Stack:[0]
Don't need token.
Reduce using rule 1 (input,0): Back to state 0, then go to state 1.
----------------------------------------
In state 1:
Stack:[0,1]
a
Need token. Got >a<
Shift and go to state 3.
----------------------------------------
In state 3:
Stack:[0,1,3]
Need token. Got ><0A><
Shift and go to state 7.
----------------------------------------
In state 7:
Stack:[0,1,3,7]
Don't need token.
Reduce using rule 4 (line,2): a
Back to state 1, then go to state 6.
----------------------------------------
In state 6:
Stack:[0,1,6]
Don't need token.
Reduce using rule 2 (input,2): Back to state 0, then go to state 1.
----------------------------------------
In state 1:
Stack:[0,1]
Need token. Got ><
Shift and go to state 2.
----------------------------------------
In state 2:
Stack:[0,1,2]
Don't need token.
Accept.