When your C project requires a custom parser or scanner — for a configuration file format, a command language, or a domain-specific language — the framework handles the code generation step automatically. BisonDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/fernandodanielmaqueda/gcc-bison-flex-GNUmakefile/llms.txt
Use this file to discover all available pages before exploring further.
.y files are processed into .tab.c, .tab.h, and .output files; Flex .l files are processed into .lex.yy.c files. Both sets of generated files are placed in obj/ and compiled alongside your handwritten C code.
When to use this approach
Use this setup whenever your project includes Bison grammar files (.y) or Flex scanner files (.l). The framework detects their presence in _SOURCES and automatically:
- Invokes
bisonwith-d -vto produce the parser implementation and header - Invokes
flexto produce the scanner implementation - Adds
-lyand/or-lfltoLDLIBSat link time - Adds the
obj/subdirectory that contains the generated header to-Iflags
Generated file locations
| Input file | Generated files |
|---|---|
src/grammar.y | obj/src/grammar.tab.c, obj/src/grammar.tab.h, obj/src/grammar.output |
src/scanner.l | obj/src/scanner.lex.yy.c |
obj/ mirroring the source directory hierarchy. The .output file contains the Bison state report (enabled via --report=state --report=itemset --report=lookahead by default).
Do not list generated files such as
*.tab.c or *.lex.yy.c in _SOURCES — the framework produces them itself. The _FIND_SOURCES FIND expression explicitly excludes them with ! -name '*.tab.c' ! -name '*.lex.yy.c'.Project layout
Setting up the GNUmakefile
Include main.mk and declare the program
Start with the standard framework include and program declaration:
Set the source directory and discover all source types
The With
_FIND_SOURCES FIND expression discovers .c, .y, and .l files together while excluding already-generated files:src/main.c, src/grammar.y, and src/scanner.l present, _FIND_SOURCES will produce:Add -I flags including the YACC header directory
When The second
.y files are present, the generated *.tab.h header lives in obj/src/ (not src/). The framework’s _FIND_-I_FLAGS expression automatically includes that directory:$(if $(filter %.y,...)) block evaluates only when .y files are in _SOURCES. It adds -I'obj/src/' so that #include "grammar.tab.h" resolves correctly from both handwritten and generated C files.Set per-program flags
LDLIBS already includes -lm. The framework appends -ly and -lfl automatically when .y or .l files appear in _SOURCES.Complete GNUmakefile example
How -ly and -lfl are added
When the framework processes your program’s link rule, it checks whether any.y or .l files appear in _SOURCES and appends the corresponding library flags:
-ly or -lfl yourself. If the linker cannot find liby.a or libfl.a, add an explicit -L path to LDFLAGS.
Enabling YACC debug mode
SettingYACC_DEBUG=X passes -t to Bison and defines YYDEBUG=1 when compiling the generated .tab.c file. This compiles in Bison’s tracing machinery. To activate tracing at runtime, set yydebug = 1 in your C source before calling yyparse():
VERBOSE=X is active and YACC_DEBUG is set, the framework prints a reminder with the exact code snippet to add.
Enabling LEX debug mode
SettingLEX_DEBUG=X passes -d to Flex, which causes the generated scanner to print tracing messages for every rule it matches:
Controlling warnings
YACC_WARNINGS=X (default on) passes -Wall to Bison. LEX_WARNINGS=X is available but has no flags assigned by default — you can extend it in main.mk if needed:
Building and running
Next steps
Pure C project
Set up a project without parser or scanner generation.
Libraries
Build static and shared libraries alongside programs.
Running and debugging
All GDB and Valgrind targets the framework provides.
Compiler options
Full reference for CFLAGS, YFLAGS, LFLAGS, and debug options.