# $Id: README,v 1.2 1998/04/29 06:34:46 jake Exp $
Perl 5 Byacc Patches 0.6
------------------------
This is a set of patches to perl-byacc1.8.2 which cause it to generate a Perl 5 class implementing a parser (instead of a file full of global data and procedures). It's nice if you want to be squeaky clean, and very nice if you have a need for multiple parsers or multiple instances of a parser in one program.
http://www.perl.com/CPAN/src/misc/perl-byacc1.8.2.tar.gz
2. Patch byacc with
cd perl-byacc1.8.2
patch < ../perl5-byacc-patches-0.6/patch
3. Compile perl-byacc1.8.2 as usual.
You invoke byacc a little differently:
You must write your parser a little differently:
And you must write the code that uses the parser differently too:
$p = Parser->new($yylex, $yyerror, $yydebug);
The first two arguments are references to your &yylex and &yyerror procedures, respectively. The third is true or false to enable or disable debugging output.
Although you may wind up sticking your &yylex and &yyerror in the parser package in most cases, this is more composable if you want to do something weird.
$val = $p->yyparse($s);
Here $s is an optional "stream" argument which represents the state of the text you're scanning. Depending on what you want to do, this could be a filehandle reference, a string, some object you cooked up, or whatever.
The argument is passed down to &yylex and &yyerror. &yylex should use it to get characters, and &yyerror should examine it to generate a meaningful message.
I've include two examples: an ultra-simple calculator and a random text generator. Type 'make' to build the parsers.
This code is in the public domain--use it and redistribute it as you like. I would appreciate acknowledgement of some kind (or at the very least an email) if you use it in something that is widely used or distributed.
Send them to Jake Donham (donham@linex.com). I'd love to hear from you if you find these patches useful.