How abdelkaderce/oker works
Project type and purpose
• Oker is a full‐stack interpreted programming language project.
• It combines a C++ compiler/interpreter backend (compiler pipeline + VM) with a web‐based frontend for interactive editing and testing.
File structure
• Top-level directories and files:
– OkerCompiler/src: C++ source for compiler pipeline (lexer, parser, semantic, codegen, VM, built-ins).
– OkerCompiler/tests: Unit tests for each compiler component.
– OkerCompiler/web: Frontend assets (HTML, CSS, JS) and Python HTTP server.
– Build scripts/config: CMakeLists.txt, build.sh.
– Examples and attached assets: sample .oker files, demos.
• Pattern: classic compiler pipeline on the backend + REST API microservice + SPA on the frontend.
README for additional insights
• Backend: C++17, CMake, pipeline stages (Lexer → Parser → Semantic → CodeGen → VM).
• Frontend: Vanilla JS SPA, served by Python HTTP server providing compilation endpoints.
• Data flows: user code → tokens → AST → bytecode → VM → output → JSON → UI.
• Testing: CMake‐integrated unit tests, integration via web interface.
a. Main components
1. Web Browser (User Interface)
– HTML/CSS/JS (web/index.html, style.css, app.js)
2. Python HTTP Server (web/server.py)
– Exposes REST endpoints for compile/run
3. Compiler Binary (built via CMake)
– CLI executable produced from src/main.cpp, invoked by server.py
4. Compiler Pipeline
– Lexer (lexer.cpp/.h)
– Parser (parser.cpp/.h)
– Semantic Analyzer (semantic.cpp/.h)
– Code Generator (codegen.cpp/.h)
– Virtual Machine (vm.cpp/.h)
– Built-ins (builtins.cpp/.h)
5. Test Framework
– Unit tests (tests/*.cpp)
– Build scripts (CMakeLists.txt, build.sh)
6. Examples and Assets
– test programs (.oker files), demos, attached_assets
b. Relationships and interactions
– User writes code in the browser → triggers app.js
– app.js issues HTTP POST to server.py
– server.py calls the compiler binary with source path
– Compiler binary runs pipeline: lex → parse → semantic → codegen → VM
– VM executes bytecode and returns stdout or JSON result
– server.py packages results (tokens, AST, bytecode, output) into JSON → HTTP response
– app.js parses JSON → updates UI
– Tests interact directly with compiler binary via CMake test targets
c. Architectural patterns and design principles
– Compiler pipeline pattern
– Separation of concerns: frontend SPA vs backend REST vs compiler core
– Modular design: each compiler stage is its own module
– Testability: unit tests for each stage, integration via SPA
– Build reproducibility: CMake + scripted build.sh
d. Key technologies and frameworks
– C++17, CMake, Address Sanitizer
– Python 3 HTTP server
– Vanilla JavaScript, HTML5, CSS3
– REST API over HTTP