Synopsislemon2yapp.pl < input.y > output.yp
DescriptionLemon is a parser generator maintained as part of the SQLite project. This perl script takes a lemon grammar file on stdin (input.y) and prints out an equivalent grammar file suitable for use with the Parse::Yapp perl parser generator
... [More]
module (output.yp). This output can be used with the yapp command line tool to produce a perl parser for the grammar. The output is also good for making a skeletal grammar file for use with yacc, as yapp and yacc have pretty much the same grammar file format.
DependenciesTo use this script to simply produce a yapp grammar file, all you will need is perl (version > 5). However, in order to generate your perl parser from this grammar file you will need the Parse::Yapp perl module. You can get it from CPAN by doing something like perl -MCPAN -e 'install Parse::Yapp'. Optionally, if you wish to build the script from source you will also need make. And finally, you will need some sort of unixy operating system with a shell.
Note:If your perl executable is not located at /usr/bin/perl then you will need to edit the prebuilt script (or the Makefile if you are building the script from source) to reflect the correct path.
Incidentally, if you make this stuff work with Windows or something, please describe what you did in the wiki about it so that others can benefit. Thanks!
CaveatsThis script makes no attempt to do anything with rule actions---it simply removes them. Same goes for comments in the source file. Also, the %fallback directive is not understood by yapp, so it is ignored, as are the %ifdef / %ifndef directives. In fact, the only directives used by this script are the precedence directives (%left, %right, etc.) The best thing to do is to scan the source file and manually extract anything inside an %ifdef / %ifndef block that you don't want, as everything else will be put into the output. Then you can manually define an nonterminal that does what the %fallback directive would have done.
Build and Installation NotesThe prebuilt perl script is available in the downloads section, but if you wish to build it from the source you may use the provided Makefile. Just copy the lemon2yapp.yp and Makefile files to an empty directory, and then run make. It will produce the lemon2yapp.pl script for you.
See AlsoRunning yapp -h will produce usage info for the yapp tool. The perldoc provided with the Parse::Yapp module describe its minor deviations from the yacc standard grammar file format. The best reference for the lemon grammar file format is on the main lemon site and in the source lemon.c file itself. [Less]