How kartik-balaji/compiler-design-lab-kartik works
Project type & purpose (from file tree + README)
This repository is not a “system” in the web/service sense; it’s a set of standalone C programs (Experiment1.c … Experiment8.c) for a Compiler Design Lab. Each file is likely an independent “experiment” implementing one compiler-construction concept (e.g., lexical analysis, parsing, FIRST/FOLLOW, symbol tables, intermediate code, etc.). The README provides only the title, so the **actual architecture must be inferred by inspecting each Experiment*.c**.
How to analyze the file structure (what matters here)
Top level:
• Experiment1.c … Experiment8.c: likely independent executables (each compiled separately).
• README.md: minimal documentation.
There are no obvious shared modules (no src/, include/, lib/, tests/). That implies:
• No shared build system in-repo (no Makefile/CMake); compilation is likely manual: gcc ExperimentX.c -o expX.
• Each experiment probably contains its own main() and internal helper functions.
Concept-level: how each experiment maps onto a typical compiler pipeline stage.
Before drawing, open each ExperimentN.c and capture:
• Inputs: stdin vs file input (fopen, command-line args), grammar files, token lists, etc.
• Core functions: e.g., lexer(), parse(), computeFirst(), computeFollow(), reduce(), generateICG().
• Data structures: token struct, parse stack, symbol table (hash table/array), parse table (2D array), AST nodes.
• Outputs: printed tokens, parse result, parse tree, intermediate code, errors.
• External dependencies: typically just C standard library (stdio.h, ctype.h, string.h), unless something special appears.
Repository / Execution-Level Architecture (high level)
Purpose: show how the repo is used and what runs.
Recommended components:
• Developer/Student
• Compiler toolchain (GCC/Clang) used to compile each .c
• 8 independent executables (one per experiment)
• Input source (stdin / input file)
• Console output / result artifacts (stdout; maybe generated files if any)
Relationships:
• Developer compiles each ExperimentN.c with GCC → produces expN binary
• User runs expN → consumes input → produces output
Purpose: show how the experiments relate to a canonical compiler pipeline even if implemented separately.
A canonical compiler pipeline:
• Source Program
→ Lexical Analysis
→ Syntax Analysis (Parsing)
→ Semantic Analysis
→ Intermediate Representation (IR) / ICG
→ Optimization (maybe absent)
→ Code Generation
→ Target Code
• “Experiment1 → Lexical Analyzer” (if true)
• “Experiment2 → FIRST/FOLLOW / parsing utilities” (if true)
• …
• Tokens
• Parse tree / AST
• Symbol table
• IR (three-address code)
• Errors/warnings
• Input (file/stdin)
• Main (main())
• Major internal modules (functions grouped by responsibility)
• Core data structures
• Output
• main()
→ readInput() (or direct file read)
→ tokenize() / scan() (if lexer)
→ processTokens() / parse() / buildTable() etc.
→ printResult() / writeOutputFile()
This is where you “separate the project into as many components as possible” without inventing non-existent folders/services.
Because these are single-process C programs, the interactions are mostly:
• Function call flow (main → subsystems)
• Data flow (input buffer → tokens array → parse stack → output)
• Stateful structures (symbol table updated during scan/parse)
• “reads” (file → buffer)
• “produces” (lexer → token stream)
• “consumes” (parser consumes token stream)
• “updates” (semantic analyzer updates symbol table)
• “emits” (ICG emits TAC)
Even in simple C labs, common patterns appear:
• Pipeline / staged processing (scan → parse → generate)
• Table-driven logic (parse tables, FIRST/FOLLOW sets)
• “Grammar/Table” as a data component feeding the parser.
• State machine (lexer DFA-like logic)
• “Lexer (FSM)” with input chars flowing through.
Only include these if the code reflects them (e.g., explicit tables, stacks, FSM transitions).
Technologies/frameworks/libraries to mention explicitly
From the repo, it’s almost certainly:
• C language
• Standard C library headers
• GCC/Clang (external compiler used to build the experiments)
• OS shell/terminal for execution
If any experiment uses:
• file I/O (fopen, fprintf) → add “Input file” / “Output file” nodes
• regex/lex/yacc tools (unlikely given plain .c) → add those tools if present
Key point for this repo
• treat each ExperimentN.c as a separately runnable component
• A conceptual pipeline to show how the lab exercises relate