How anjeleee/bnf-ast-converter works
BNFgen is an educational compiler syntax analyzer and tree visualizer. A user enters C++-subset source in the web UI; the client submits it through its API module to FastAPI, which invokes the parser. The parser tokenizes input, validates it with LL(1) parsing, and produces BNF derivations plus CST/AST results. The client then displays trees, grammar information, and metrics, with graph/chip and ASCII tree views. Backend and frontend calls are evidenced by the README and sampled source; internal parser stages follow documented capabilities where implementation detail was not excerpted.
Main entry points: app.js UI coordinator · parser.py LL(1) parser · main.py FastAPI endpoints · index.html Source editor
Components 15
Web interface
- Source editor
frontend/index.html - UI coordinator
frontend/js/app.js - API client
frontend/js/api.js
API service
- FastAPI endpoints
backend/main.py
Compiler analysis
- Tokenizer
backend/lexer.py - LL(1) parser
backend/parser.py - BNF derivations
backend/parser.py - Concrete syntax tree
backend/parser.py - Abstract syntax tree
backend/parser.py
Results and grammar
- Grammar presets
frontend/js/grammar.js - Tree utilities
frontend/js/treeUtils.js - Tree and ASCII views
frontend/js/app.js - Tree metrics
frontend/js/treeUtils.js
Other components
- User
- Web browser
Connections 15
- User → Source editor: enters source
README.md - Source editor → UI coordinator: handles input
frontend/js/app.js - UI coordinator → API client: requests parse
frontend/js/app.js - API client → FastAPI endpoints: POSTs source
frontend/js/api.js - FastAPI endpoints → LL(1) parser: calls parse_code
backend/main.py - LL(1) parser → Tokenizer: tokenizes source
backend/parser.py - LL(1) parser → BNF derivations: generates derivations
README.md - LL(1) parser → Concrete syntax tree: builds tree
README.md - LL(1) parser → Abstract syntax tree: synthesizes tree
README.md - FastAPI endpoints → UI coordinator: returns JSON
README.md - UI coordinator → Grammar presets: loads rules
frontend/js/app.js - UI coordinator → Tree utilities: uses tree helpers
frontend/js/app.js - UI coordinator → Tree and ASCII views: renders results
frontend/js/app.js - UI coordinator → Tree metrics: calculates metrics
frontend/js/app.js - Web browser → UI coordinator: displays interface
README.md