How kaushalrijal/lipi works
Project Type and Purpose
• This is a compiler for a high‑level, Nepali‐inspired programming language (“Lipi”).
• Core goal: read a .lipi source file, lex and parse it into an AST, perform semantic analysis, generate code, then execute it.
• Language elements: variables, expressions, control flow, functions (all with Nepali keywords).
File Structure
• Top‑level:
• main.cpp – orchestrates the compiler pipeline.
• CMakeLists.txt – build configuration.
• grammar/ – the BNF grammar file (byakaran.bnf).
• include/ – public headers for AST, lexer, parser, semantic analyzer, symbol table, code generator, executor.
• src/ – implementation of those components.
• examples/ – sample .lipi programs (input for the compiler).
• test/ – unit tests for each stage (lexer, parser, AST).
• docs/ – user documentation.
• Pattern: A classical single‐executable compiler pipeline. No microservices, but well‐modularized stages.
README for Additional Insights
• Dependencies: C++17, CMake 3.10+, compiler (g++, clang++).
• Build steps produce Lipi.exe (or Linux binary).
• Running: lipi path/to/source.lipi invokes the compiler+executor.
a. Main Components
1. Source Input (examples/*.lipi or user file)
2. Lexer (include/lexer.hpp + src/lexer.cpp)
3. Parser (include/parser.hpp + src/parser.cpp)
4. AST (include/ast.hpp + src/ast.cpp)
5. Symbol Table (include/symbol_table.hpp + src/symbol_table.cpp)
6. Semantic Analyzer (include/semantic_analyzer.hpp + src/semantic_analyzer.cpp)
7. Code Generator (include/code_generator.hpp + src/code_generator.cpp)
8. Executor (include/executer.hpp + src/executer.cpp)
9. Optional: Grammar file (grammar/byakaran.bnf) feeding into Parser design.
10. Test Suite (test/*.cpp) – verifies individual components.
b. Relationships and Interactions
• Data flow is strictly linear: Source → Lexer → Parser → AST → Semantic Analyzer (which uses Symbol Table) → Code Generator → Executor → Program Output.
• The main.cpp module ties all these stages together.
• Tests invoke components in isolation for unit testing.
c. Architectural Patterns & Principles
• Pipeline pattern: each compiler stage transforms intermediate representation.
• Modular separation: headers in include/, implementation in src/.
• Single responsibility: each class handles one stage (lexing, parsing, code gen, etc.).
• Test‑driven design evident from test/ directory.
d. Key Technologies, Frameworks, Libraries
• C++17 (standard library data structures).
• CMake (build orchestration).
• BNF grammar for parser design.
• Native in‑process execution (no external VM).