-
Notifications
You must be signed in to change notification settings - Fork 209
Home
Victor Rodriguez edited this page Apr 27, 2026
·
1 revision
This guide explains how to install and validate Lex/Yacc tooling on:
- Linux
- WSL (Windows Subsystem for Linux)
- macOS
Modern equivalents:
- Flex → lexical analyzer generator
- Bison → Yacc-compatible parser generator
sudo apt update
sudo apt install -y flex bison gcc make
sudo dnf install -y flex bison gcc make
brew install flex bison
Add to PATH if needed:
# Apple Silicon
echo 'export PATH="/opt/homebrew/opt/bison/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/flex/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
flex --version
bison --version
gcc --version
This only confirms installation—not correctness of the toolchain.
This step ensures your full pipeline actually works:
- Flex → C code generation
- GCC → compilation
- Runtime → execution
cat > test.l <<'EOF'
%{
#include <stdio.h>
%}
%%
hello { printf("OK: FLEX WORKS\n"); }
.|\n { }
%%
int main(void) {
yylex();
return 0;
}
int yywrap(void) { return 1; }
EOF
flex test.l
gcc lex.yy.c -o test
echo "hello" | ./test
OK: FLEX WORKS
Symptom | Likely Cause | Fix
-- | -- | --
flex: command not found | Not installed / PATH issue | Reinstall or fix PATH
gcc: command not found | Compiler missing | Install build-essential
undefined reference to yywrap | Missing symbol | Add yywrap() or link -lfl
No output | Rule not matching | Check regex or input
- Integrate Flex with Bison
- Build a parser (calculator example)
- Generate AST and semantic checks
The validation step (Section 4) is the most important addition:
✔ Confirms toolchain integrity
✔ Eliminates environment issues early
✔ Guarantees Flex → GCC → runtime pipeline works