|
|
||
|---|---|---|
| parse-gram.c | Explain code. | |
| parse-gram.h | Initial commit. | |
| parse-gram.y | Initial commit. | |
| README.md | Add README. | |
GNU Bison boostrapping path
To compile GNU Bison you need GNU Bison, because GNU Bison requires itself to compile its own grammar. This is a problem for boostrapping it (actually, GNU Bison's source distribution already contains pre-compiled C files to avoid this problem, but this is clearly not satisfying: it is impossible to verify the correctness of those machine-generated files).
The code in this repository basically provides a handwritten implementation of the parser for the Bison grammar description language, or at least for a subset of it, just enough to be able to recompile Bison with it. After a few rounds of compilation, as described below, you will have a fully functional Bison executable, compiled without resorting to a previous Bison executable or to machine-generated files (generated by Bison, see below).
This project only addresses the dependence of Bison on itself. Bison also depends on Flex to generate its lexer, but since it is possible to compile Flex without using Bison this issue is not addressed here.
How to use it
This work is based on Bison 3.4.1. It might not work with other versions, because it depends on the specific grammar used by that version.
Download and extract Bison 3.4.1:
$ wget https://ftp.gnu.org/gnu/bison/bison-3.4.1.tar.gz
$ sha256sum bison-3.4.1.tar.gz
7007fc89c216fbfaff5525359b02a7e5b612694df5168c74673f67055f015095 bison-3.4.1.tar.gz
$ tar xzf bison-3.4.1.tar.gz
Save the original Bison grammar and overwrite it with a slightly simplified version of it. Overwrite the machine-generated implementation of Bison's parser with our custom handwritten one. It is important to copy the C files after the grammar file, otherwise the build script will immediately try to regenerate the C files and it will fail because it doesn't already have a Bison executable (it won't try to use the system-provieded one).
$ cp bison-3.4.1/src/parse-gram.y parse-gram.y.orig
$ cp parse-gram.y bison-3.4.1/src/
$ cp parse-gram.c parse-gram.h bison-3.4.1/src/
Compile Bison for the first time.
$ cd bison-3-4.1/
$ ./configure
$ make
Now we have a Bison executable. It's quite crippled, though, because it uses the handwritten parser which is not complete. However, it is good enough to recompile Bison's own grammar.
$ touch src/parse-gram.y
$ make
Now we have a better Bison executable. Still, the grammar file we used is slightly simplified with respect to the original one, so that the handwritten implementation could be simpler. Let's reinstate the original grammar and compile again.
$ cp ../parse-gram.y.orig src/parse-gram.y
$ make
Ok, this should finally be a fully functional Bison executable! Let's check it!
$ make check
All checks should pass.
License
This code was written by Giovanni Mascellani gio@debian.org. It is of course based on the GNU Bison code and therefore licensed with the same license, which is the GNU General Public License version 3 or later.