How mikhailwahib/ra works
Project Type & Purpose
• The project is an interpreted programming language called “Ra,” built in Go.
• Its purpose is to demonstrate language development by providing components such as a lexer, parser, evaluator, and a REPL. It is intended for learning and experimentation (not production-grade).
Analyzing the File Structure
• The top-level organization splits largely into two parts:
• The “docs” directory holds documentation built with Docusaurus, including configuration, static assets, and a full documentation site for the language (e.g., basic syntax, control flow, etc.).
• The “src” directory contains the core language implementation. It includes subfolders for:
▸ ast – Abstract Syntax Tree definitions and tests.
▸ evaluator – The interpreter’s evaluation logic with builtins and test cases.
▸ lexer – Token generation and testing modules.
▸ parser – Parsing logic for converting tokens to AST with associated tests.
▸ object – Representation of language objects and environments.
▸ repl – Implementation of the interactive Read-Eval-Print Loop.
▸ examples – Sample Ra source files.
• Other files like “ra.go” and “go.mod” indicate entry-point code and dependency management.
Main Components of the System
a. Input Source Code:
• Examples or interactive input via the REPL.
b. Lexer:
• Tokenizes raw code into tokens.
• Files: src/lexer/lexer.go, lexer_test.go.
c. Parser:
• Converts tokens into an AST.
• Files: src/parser/parser.go, parser_test.go.
d. AST:
• Data structures that model the code’s syntax.
• Files: src/ast/ast.go, ast_test.go.
e. Evaluator:
• Walks through the AST and evaluates expressions.
• Files: src/evaluator/evaluator.go and evaluator tests.
f. Object System & Environment:
• Manages runtime objects and variable bindings.
• Files: src/object/object.go, environment.go.
g. REPL:
• Provides an interactive shell for execution.
• Files: src/repl/repl.go.
h. Documentation:
• Visualization and usage guidelines with Docusaurus (for external viewers).
Relationships and Interactions
• Input (via file execution or REPL) → Lexer → Parser → AST creation → Evaluator → Output/Result.
• How tokens flow from the lexer into the parser, and how the AST is used by the evaluator.
• REPL which sits on top of this evaluation pipeline, providing an interactive interface.
• Optionally, show testing components (unit tests for lexer, parser, evaluator, etc.) as verification points.
Architectural Design Patterns & Principles
• Modular design: Each component (lexer, parser, AST, evaluator, REPL) is organized in its own package.
• Separation of concerns: The responsibilities of tokenizing, parsing, and evaluating are clearly separated.
• Extensibility & Testing: Several test files (.go tests in ast, lexer, parser, and evaluator) serve as modular checkpoints for each component.
• For the documentation system (Docusaurus), a clear separation between the user documentation and code is maintained.