%tree
%semantic token 'a' 'b'
%%
S:    %name EMPTY
        /* empty */
    | %name AES 
        S A
    | %name BES 
        S B
;
A : %name A 
      'a' 
;
B : %name B
      'b' { }
;
%%

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\n]//;

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

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