%semantic token 'a' 'b' %tree bypass %% S: %name EMPTY /* empty */ | %name SA S A.f { $f->{attr} = "A"; $f; } A | %name SB S B.f { $f->{attr} = "B"; $f; } 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; $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error, #yydebug => 0x1F ); }