How levi178u/c-compiler works
This repository is a small compiler for a teaching language. The principal workflow is source-file input through scanning and parsing into a tree, then backend semantic checks and assembly generation, followed by optimization of the generated assembly. The README also documents variables and local scopes, arithmetic, input/output, conditionals, loops, and comments; these are language capabilities rather than separate runtime services. Some backend internals were not excerpted, so their documented responsibilities are shown without asserting unshown call details.
Main entry points: compiler.cpp Compile orchestration · scanner.cpp Scanner · parser.cpp Parser · backend.cpp Static semantics
Components 14
Frontend
- Compiler CLI
src/main.cpp - Compile orchestration
src/compiler/compiler.cpp - Scanner
src/compiler/frontend/scanner/scanner.cpp - Transition table
src/compiler/frontend/scanner/state_transition_table/state_transition_table.cpp - Parser
src/compiler/frontend/parser/parser.cpp
Language model
- Token types
src/compiler/token - Parse tree
src/compiler/node/node.cpp
Backend
- Static semantics
src/compiler/backend/backend.cpp - Variable scopes
src/compiler/backend/var_stack/var_stack.cpp - Code generation
src/compiler/backend/code_generator/code_generator.cpp - Assembly optimizer
src/compiler/backend/optimizer/optimizer.cpp
Output and execution
- Assembly output
- Assembly interpreter
Other components
- Programmer
Connections 14
- Programmer → Compiler CLI: supplies source
src/main.cpp - Compiler CLI → Compile orchestration: invokes compile
src/main.cpp - Compile orchestration → Parser: parses source
src/compiler/compiler.cpp - Parser → Scanner: reads tokens
src/compiler/frontend/parser/parser.cpp - Scanner → Transition table: uses transitions
src/compiler/frontend/scanner/scanner.cpp - Scanner → Token types: produces tokens
- Parser → Parse tree: builds tree
src/compiler/frontend/parser/parser.cpp - Compile orchestration → Static semantics: traverses tree
src/compiler/compiler.cpp - Static semantics → Variable scopes: tracks variables
- Static semantics → Code generation: generates assembly
- Compile orchestration → Assembly optimizer: optimizes assembly
src/compiler/compiler.cpp - Code generation → Assembly output: emits assembly
- Assembly optimizer → Assembly output: rewrites assembly
- Assembly output → Assembly interpreter: runs program