compilers
Design and implement compilers and interpreters — lexer, parser, AST, type checking, code generation, optimization — with correctness and modularity.
Goals
- Build a correct front-end (lexer → parser → AST)
- Implement type checking or interpretation
- Generate valid output (bytecode, IR, machine code)
- Structure the compiler for extension and testing
Contract
Input
A language to compile or interpret: source language, target, feature set.
Output
A compiler design with:
- Language grammar (EBNF or BNF)
- Module breakdown (lexer, parser, type checker, codegen)
- IR design or bytecode specification
- Test plan for each phase
Compiler Phases
Source → Lexer → Tokens → Parser → AST
↓
Semantic Analysis (type check)
↓
Optimization (optional)
↓
Code Generation → Target
Steps
- Define the grammar — EBNF, ensure it is unambiguous
- Implement the lexer — token stream, handle lexing errors
- Implement the parser — recursive descent, LL(1), or LR
- Build the AST — visitor pattern for traversal
- Add semantic analysis — scope, type checking, symbol table
- Generate output — bytecode, IR, or native code
- Add optimization passes — dead code elimination, constant folding
- Write tests — golden tests, fuzzing, property-based testing
References
../os/SKILL.md — system calls for code execution
../../cs/cs-algorithms/SKILL.md — parsing algorithms
../../math/math-formal-proof/SKILL.md — correctness proofs
1---2name: compilers3description: Design and implement compilers and interpreters — lexer, parser, AST, type checking, code generation, optimization — with correctness and modularity.4---56# compilers78Design and implement compilers and interpreters — lexer, parser, AST, type checking, code generation, optimization — with correctness and modularity.910## Goals11- Build a correct front-end (lexer → parser → AST)12- Implement type checking or interpretation13- Generate valid output (bytecode, IR, machine code)14- Structure the compiler for extension and testing1516## Contract1718### Input19A language to compile or interpret: source language, target, feature set.2021### Output22A compiler design with:23- Language grammar (EBNF or BNF)24- Module breakdown (lexer, parser, type checker, codegen)25- IR design or bytecode specification26- Test plan for each phase2728## Compiler Phases2930```31Source → Lexer → Tokens → Parser → AST32 ↓33 Semantic Analysis (type check)34 ↓35 Optimization (optional)36 ↓37 Code Generation → Target38```3940## Steps41421. **Define the grammar** — EBNF, ensure it is unambiguous432. **Implement the lexer** — token stream, handle lexing errors443. **Implement the parser** — recursive descent, LL(1), or LR454. **Build the AST** — visitor pattern for traversal465. **Add semantic analysis** — scope, type checking, symbol table476. **Generate output** — bytecode, IR, or native code487. **Add optimization passes** — dead code elimination, constant folding498. **Write tests** — golden tests, fuzzing, property-based testing5051## References52- `../os/SKILL.md` — system calls for code execution53- `../../cs/cs-algorithms/SKILL.md` — parsing algorithms54- `../../math/math-formal-proof/SKILL.md` — correctness proofs