How giedriusj1/g1 works
Main Components
• Main Application: Represented by src/main.rs, it is the entry point that ties together all components.
• Lexer Module: src/lex.rs handles the tokenization of the input source code.
• Parser / S-Expression Module: src/sexp.rs likely converts token streams into S-expressions or an AST representing the code’s structure.
• Evaluator Module: src/eval.rs implements the evaluation strategy based on the parsed structure.
• Built-in Functions and Intrinsics: The directory built-in (with files such as intrinsics.g1 and test-harness.g1) provide definitions or implementations of the language’s built-in functionality.
• Test Suites: The tests directory (and files with extension .g1) provide examples and unit/integration tests that illustrate how different language constructs should behave. They validate lexing, parsing, evaluation, and built-in behavior.
Relationships and Interactions
• Data Flow:
a. A source program (written in the toy elisp dialect) is fed into the system.
b. The Lexer (src/lex.rs) breaks the input into tokens.
c. Tokens are passed to the Parser (src/sexp.rs) which builds a higher-level structure (e.g., S-expressions).
d. The Evaluator (src/eval.rs) processes these S-expressions, using the built-in definitions (from built-in/) as a runtime library.
e. The evaluated result is then output or returned by the system (controlled in src/main.rs).
• The tests further validate these logical flows by feeding example code to the system and ensuring the output matches expectations.
Architectural Patterns and Design Principles
• Pipeline Pattern: The design closely follows a linear, step-by-step processing pipeline (lexing → parsing → evaluation).
• Modular Design: Each core functionality (lexer, parser, evaluator) is isolated in its own module, promoting separation of concerns.
• Extensibility: The presence of a built-in directory indicates that new intrinsic or built-in functions can be added modularly, and the test suite is comprehensive, covering many language features.