Custom Compiler
Simple-C Compiler with Web IDE
Python · FastAPI · React · TypeScript · Vite · C/C++
Overview
A Simple-C to IR compiler built in Python, paired with a custom-built web-based IDE for compiling, editing, and exploring the output in real time. The compiler implements all stages from lexical analysis to three-address code generation with classical optimization passes, achieving ~30% faster execution than baseline.
Highlights
- Multi-stage compiler for a small C-like language: a regex/maximal-munch scanner (tokenizer with single-line comment support), a recursive-descent parser + AST, an IR code generator, and an orchestration layer
- Two optimization passes: Local Value Numbering (LVN) for redundant-expression elimination, and loop unrolling — both toggleable per compile request
- FastAPI backend exposes GET /snippets (loads example/test/error programs from disk) and POST /compile (returns clang-formatted IR or structured {error, error_line}), with human-readable error formatting that maps scanner/parser/symbol-table exceptions to program.cpp:line: error: messages
- Complete semantic analysis pipeline: symbol tables, multi-pass type checking, type inference, scope resolution, operator validation, and error recovery mechanisms
- Custom code editor built on a <textarea>: terminal-style block cursor with mirror-div caret tracking, real-tab indentation with Tab/Shift-Tab and Ctrl-/ line-comment toggle, and line numbers
- Ctrl-K/Cmd-K command palette (open file, toggle LVN, set font size / unroll factor, toggle smooth cursor), a VS Code-style bottom status bar, OS light/dark theme detection, and responsive breakpoints with collapsible sidebar and drag-resizable panes
- 10 numbered test programs plus a timing/benchmark case and 5 error programs that each deliberately trigger a specific compiler error