https://github.com/ejurgensen/bison-boilerplate
Boilerplate .l, .y, .am and .ac for multiple Bison/flex parsers-lexers in a C project
https://github.com/ejurgensen/bison-boilerplate
autotools bison flex parser
Last synced: 5 months ago
JSON representation
Boilerplate .l, .y, .am and .ac for multiple Bison/flex parsers-lexers in a C project
- Host: GitHub
- URL: https://github.com/ejurgensen/bison-boilerplate
- Owner: ejurgensen
- License: mit
- Created: 2021-12-22T18:38:33.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-15T21:01:05.000Z (over 1 year ago)
- Last Synced: 2025-01-21T11:14:23.671Z (over 1 year ago)
- Topics: autotools, bison, flex, parser
- Language: Yacc
- Homepage:
- Size: 182 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bison-boilerplate
This is minimal flex/bison boilerplate for a C project with the following
requirements:
- Use autotools (automake/autoconf)
- Parse strings (not files)
- Allow for multiple parsers/lexers
- Clean interface to main program i.e., no bison/flex constructs in main program
- Clear separation between boilerplate and real parsing/lexing
The goal of the boilerplate is to be neat and tidy. That means using thread safe
Bison/flex, creating proper lex headers, using a consistent naming schema,
eschewing compiler warnings etc.
It includes a configure check that specifically checks for flex and bison, not
accepting lex nor yacc.
The boilerplate implements two identical calculator parsers to test with. Run
`autoreconf -vi && ./configure && make`, and then run with `./src/boilerplate`.
The interface between the example parsers and the main program can be seen in
main.c.
To create a parser with the boilerplate, search and replace "calc1_" with your
name, and write your lexing and parsing implementation in the sections of the .l
and .y files marked as non-boilerplate.
You can also check the [owntone1](https://github.com/ejurgensen/bison-boilerplate/tree/owntone1)
branch if you want to see the actual parsers I use the boilerplate code for.
Credit to the following for useful info/input:
* https://begriffs.com/posts/2021-11-28-practical-parsing.html
* https://github.com/meyerd/flex-bison-example
* https://github.com/5nord/bison-example
* https://lloydrochester.com/post/autotools/flex-bison-project/
* https://www.gnu.org/software/automake/manual/html_node/Yacc-and-Lex.html