> This is a good lesson for most of us: portable code is subtly difficult > to write. I feel bad enough about what I did in my a2p front-end, > but I don't see much choice. FYI: Larry says that once we have yacc, > we should rewrite a2p completely in Perl and merge in my awk front end's > functionality so it is all one process and doesn't need C. My horrible `py' hack works well enough to use for projects like this. You run `bison -v' on your yacc grammar, and it examines the bison diagnostic output and constructs a yacc-style parser, in Perl, for the language you specified. The person who actually *runs* your program doesn't need to have Bison; you only need that to construct the parser program, which is in Perl and can be run anywhere that Perl is available. In fact, the current version generates parsers that will run under perl 4. If someone wants to use this for something I can provide help or a more efficient version that generates code that takes advantage of perl 5 features. This would only take a couple of hours, because I wrote most of the necessary things in the process of writing my PPT `units' program. http://www.plover.com/~mjd/perl/py/ This is how I was planning to bootstrap a perl version of `yacc'. Here is an explanation for how `yacc' works. A `yacc' implementation has two important parts: 1. A canned driver that reads input and parses it based on the contents of some state tables. (`yaccpar') 2. The program that reads the grammar and generates the tables for the canned driver. (`yacc') You run `yacc' on your grammar, and it generates the tables, yacctables.pl. Then your program says require 'yacctables.pl'; # Tables implement your language require 'yaccpar.pl'; # Canned driver is the same for everyone yyparse(); The `yyparse' function is in `yaccpar.pl'; it reads the tables that you loaded from `yacctables.pl' and makes calls to your `yylex' function when it wants a new token. Now, to *write* yacc you need #1 and #2. #2 needs to have a parser already, because it needs to parse the grammar you supply, and there is a YACC-style grammar for these grammars in the manual. #1 is already written: There is one version in `py', and another version in `units'. So the procedure would be something like this: 1. Run `py' on the grammar from the yacc manual to generate a parser for yacc grammars. 2. Write the interesting part of `yacc' that figures out how to build the parser and write out the tables. This is the only hard part. 3. Get the yaccpar from py, and put it together with the yacc from step 2. You now have a working yacc in Perl. 4. Dispense with py and use yacc to analyze its own grammar from now on. Whoever does this should look at Parse::YAPP first to find out what it does, becayse it might be a much better plan to use that instead.