How gyu-chul/hab-legacy works
Project type and purpose
• HAB is an open-source, desktop GUI tool for visualizing and interactively debugging Python program execution.
• It combines a compiler-style pipeline (lexical, syntax, semantic analysis, runtime) with a graphical interface and code-editing surface.
File structure
• Top-level build and config: CMakeLists.txt, .env, .gitignore, LICENSE, main.cpp, script.py
• & lib folders hold C++ headers and helper libraries
• src/ folder subdivides into:
• code-editor (GUI text editor component)
• window (application window management)
• lexical-analyzer (Scanner submodule)
• syntax-analyzer
• semantic-analyzer
• runtime (executes interpreted instructions, steps through code)
• datas (data model for runtime, includes Object/number types)
• graphic-maker (builds visual scene)
• graphic-utility (drawing primitives, helper routines)
README for additional insights
• Core goal: “visually expose the execution process of the source code”
• Interactive: “allows source code modification with a mouse in a GUI area”
• Written in C++ with a Python-execution backend (driven by script.py)
Main components and their relationships
a. Components:
• Code Editor (src/code-editor)
• GUI Window Manager (src/window)
• Compiler Pipeline:
• Lexical Analyzer (src/lexical-analyzer)
• Syntax Analyzer (src/syntax-analyzer)
• Semantic Analyzer (src/semantic-analyzer)
• Runtime Engine (src/runtime)
• Data Model (src/datas)
• Visualization Engine:
• Graphic Utility (src/graphic-utility)
• Graphic Maker (src/graphic-maker)
• Orchestration Script (script.py)
• External Python Interpreter
• Build System (CMake)
b. Interactions and data flow:
1. User types or edits code in the Code Editor.
2. On compile/step command, editor sends source text to Lexical Analyzer.
3. Tokens flow into Syntax Analyzer → AST.
4. AST is checked by Semantic Analyzer → annotated IR.
5. IR is handed to Runtime Engine, which interfaces with the Python Interpreter or executes an internal bytecode.
6. Runtime Engine emits state changes (stack, heap, variable values) into the Data Model.
7. Data Model updates feed into the Graphic Utility for drawing primitives.
8. Graphic Maker composes those primitives into visual elements (e.g., call stacks, variable tables).
9. Visualization frames are rendered inside the GUI Window.
10. script.py can launch or reload the interpreter session, manage hot-reload of code.
c. Architectural patterns & design principles:
• Compiler pipeline (lex → parse → semantic check → runtime)
• Model-View-Controller (Model = Data Model, View = Graphic Maker/Utility + Window, Controller = Code Editor + Runtime events)
• Event-driven GUI (user actions trigger analysis & visualization updates)
• Modular separation (each analyzer in its own directory, clear data flows)
d. Key technologies & libraries:
• C++17 (assumed) with CMake build
• Python 3 interpreter integration via script.py
• GUI toolkit (e.g., Qt, SDL, or custom canvas – inspect CMake for actual choice)
• Custom Scanner, Parser, Semantic modules in C++
• Runtime engine with hooks into Data Model objects
Details to capture
• Directory/module names next to each block (e.g., “Lexical Analyzer (src/lexical-analyzer)”).
• Build integration via CMake if relevant for deployment.