Full-featured language support for GNU Bison (.y, .yy) and Flex/RE-flex (.l, .ll) in Visual Studio Code.
Build parsers and lexers with confidence — get syntax highlighting with embedded C/C++, real-time error detection, intelligent autocompletion, and inline documentation for every directive.
Section-aware highlighting that understands the structure of Bison and Flex files: declarations, rules, and epilogue/user code sections are each highlighted differently.
- Bison: directives (
%token,%type,%define,%code...), rule definitions,$$/$1/@$semantic values,<type>annotations,%prec,|alternatives - Flex: directives (
%option,%x,%s),<SC_NAME>start conditions,{abbreviation}references,<<EOF>>, regex character classes[a-z], escape sequences - Embedded C/C++: full C++ highlighting inside
%{ %},%code { },%top{ %},%class{ }, and action blocks{ ... }— powered by VS Code's built-in C++ grammar
Real-time error detection as you type:
| Bison | Flex |
|---|---|
| Undeclared tokens used in grammar rules | Undefined start conditions (<SC_NAME> not declared with %x/%s) |
%type declarations for non-existent rules |
Undefined abbreviation references ({name} not in definitions) |
Missing %% section separator |
Missing %% section separator |
Unclosed %{ %} code blocks |
Unclosed %{ %} code blocks |
Missing %type with variant semantic values |
Unused start conditions and abbreviations |
| Unused grammar rules (unreachable from start symbol) | Inaccessible rules (catch-all before specific pattern, or duplicate) |
| Unused tokens (declared but never referenced) | Unknown/invalid directive |
| Shift/reduce conflict heuristic | |
| Unknown/invalid directive |
Context-aware suggestions triggered as you type:
- All Bison directives (30+):
%token,%type,%define,%left,%right,%nonassoc,%precedence,%code,%skeleton,%glr-parser,%expect,%require,%language,%locations,%printer,%destructor,%param... - All
%definevariables:api.value.type,api.token.prefix,api.namespace,api.parser.class,api.token.constructor,parse.error,parse.lac,lr.type... - All Flex
%optionvalues (20+):noyywrap,bison-complete,bison-cc-parser,bison-locations,reentrant,debug,yylineno,stack... - Token and non-terminal names from your declarations (in the rules section)
- Semantic values:
$$,$1–$9,@$,@1–@9 - Start conditions and abbreviation names (Flex, in rules)
- Code snippets: full grammar/scanner skeletons, rule templates, comment/string handlers
Hover over any directive or keyword to see its documentation:
- Signature, description, and usage example for every Bison directive
- Documentation for all
%defineconfiguration variables - Explanation of semantic value references (
$$,$1,@$,@1) - Flex
%optionvalue descriptions (including RE-flex-specific options) - Built-in function docs:
start(),text(),BEGIN,ECHO,REJECT,<<EOF>> - Token and non-terminal info from your own declarations
Ready-to-use templates to speed up your workflow:
Bison (14 snippets):
bison-skeleton— Complete grammar file templaterule— Grammar rule with action%token,%type,%code requires,%define,%left,%right,%nonassoc%empty,%prec,%{
Flex (12 snippets):
flex-skeleton— Complete Flex scanner templatereflex-skeleton— Complete RE-flex scanner templatecomment-handler— Nested comment handler with start conditionsstring-handler— String literal handler with escape sequencesrule,rule-sc,%option,%x,%top,%class,eof-handler
Reference counts and entry-point indicators appear above every Bison rule and Flex start condition:
- N reference(s) — click to open Find All References at that symbol
- ⬪ entry point — marks the grammar's start symbol
Toggle with bisonFlex.enableCodeLens.
- Outline (
Ctrl+Shift+O): collapsible tree of declarations, rules, and epilogue for Bison; definitions, patterns, and user code for Flex - Workspace Symbols (
Ctrl+T): fuzzy search across all open Bison and Flex files — tokens, rules, start conditions, abbreviations
Inline type annotations for $$, $1, @$, etc. resolved from %type and %token declarations. Toggle with bisonFlex.showInlayHints.
The extension detects CMakeLists.txt files up to 6 directories above the current file:
- Diagnostic warning when a
.y/.lfile has noBISON_TARGET/FLEX_TARGETreferencing it - Bison/Flex: Add CMake Target command — appends the correct CMake snippet automatically
Toggle with bisonFlex.enableCmakeDiagnostics.
- Bison: Show Grammar Graph — interactive D3.js force-directed graph of the grammar; click a node to navigate to the rule; left/right recursive rules highlighted
- Bison: Show Parse Table — displays the Bison
.outputparse table in a side panel - Bison: Explain Conflict — detailed shift/reduce conflict analysis with derivations and fix suggestions
- Bison: Generate AST Skeleton — generates a complete C++ AST header with visitor pattern
- Flex: Test Rule — interactive regex tester for the pattern on the current line
- Bison: Compile / Flex: Compile — run the compiler on the current file and surface errors as VS Code diagnostics
- Bison/Flex: Initialize tasks.json — auto-generates
.vscode/tasks.jsonwith problem matchers; detects CMake and Makefile projects
| Language | Extensions | Aliases |
|---|---|---|
| Bison | .y, .yy, .ypp, .bison |
Bison, Yacc |
| Flex | .l, .ll, .lex, .flex |
Flex, Lex, RE-flex |
Search for "Bison/Flex Language Support" in the VS Code Extensions panel (Ctrl+Shift+X).
code --install-extension bison-flex-lang-1.1.0.vsixgit clone https://github.com/theodevelop/bison-flex-lang.git
cd bison-flex-lang
npm install
npm run compileThen press F5 in VS Code to launch the Extension Development Host.
| Setting | Type | Default | Description |
|---|---|---|---|
bisonFlex.enableDiagnostics |
boolean |
true |
Enable/disable real-time error detection |
bisonFlex.maxDiagnostics |
number |
100 |
Maximum number of diagnostics per file |
bisonFlex.bisonPath |
string |
"bison" |
Path to the Bison executable (must be in PATH or absolute) |
bisonFlex.flexPath |
string |
"flex" |
Path to the Flex executable (must be in PATH or absolute) |
bisonFlex.showInlayHints |
boolean |
true |
Show inline type hints for $$/$1/@$ semantic values |
bisonFlex.enableCodeLens |
boolean |
true |
Show reference counts and entry-point badges above rules |
bisonFlex.enableCmakeDiagnostics |
boolean |
true |
Warn when a .y/.l file is not referenced in CMakeLists.txt |
Drop this .vscode/tasks.json into your Bison/Flex project to get Ctrl+Shift+B build support with problem matchers:
{
"version": "2.0.0",
"tasks": [
{
"label": "Build (Bison + Flex + Make)",
"type": "shell",
"command": "make",
"group": { "kind": "build", "isDefault": true },
"presentation": { "reveal": "always", "panel": "shared" },
"problemMatcher": [
{
"owner": "bison",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^(.+?):(\\d+)(?:\\.(\\d+))?:\\s+(warning|error):\\s+(.+)$",
"file": 1, "line": 2, "column": 3, "severity": 4, "message": 5
}
},
{
"owner": "flex",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^(.+?):(\\d+):\\s+(warning|error):\\s+(.+)$",
"file": 1, "line": 2, "severity": 3, "message": 4
}
}
]
},
{
"label": "Bison: Compile current file",
"type": "shell",
"command": "bison",
"args": ["-d", "-v", "${file}"],
"group": "build",
"problemMatcher": []
},
{
"label": "Flex: Compile current file",
"type": "shell",
"command": "flex",
"args": ["-o", "${fileBasenameNoExtension}.c", "${file}"],
"group": "build",
"problemMatcher": []
}
]
}Tip:
bison -dgenerates the.tab.hheader;-vproduces the.outputreport with the parse table.
The extension uses a Language Server Protocol (LSP) architecture:
- Client (
client/): thin VS Code extension that starts the language server - Server (
server/): Node.js process that provides diagnostics, completion, and hover- Hand-written parsers for Bison and Flex files (line-by-line, section-aware)
- Document model cached per file, re-parsed on every change
- Grammars (
syntaxes/): TextMate grammars with embedded C++ delegation
| 💬 General | Usage tips, feedback, anything goes |
| 💡 Ideas | Feature proposals and brainstorming |
| 🙏 Q&A | Questions about the extension |
| 📣 Announcements | Releases and important updates |
Contributions are welcome! See CONTRIBUTING.md for full details.
Quick start:
- Fork the repository and branch off
dev npm install && npm run compile- Press
F5to test in the Extension Development Host - Add or update tests, then open a PR against
dev
npx ts-node --project server/tsconfig.json tests/test-parsers.ts
TS_NODE_PROJECT=tsconfig.base.json npx ts-node tests/test-diagnostic-codes.ts
TS_NODE_PROJECT=tsconfig.base.json npx ts-node tests/test-version-settings.ts
TS_NODE_PROJECT=tsconfig.base.json npx ts-node tests/test-fix-it-hints.tsnpm run compile
npx vsce package # Create .vsix file- Diagnostics are based on static analysis of the grammar file structure, not on running Bison/Flex. Some valid constructs may trigger warnings.
- Embedded C/C++ highlighting relies on VS Code's built-in C++ grammar. Complex template expressions may occasionally confuse the highlighter.
- Brace depth tracking in action blocks uses a simplified scanner that does not fully parse C++ strings and comments — deeply nested code blocks with unbalanced braces in string literals may cause highlighting drift.




