How wisenheim/yarmin works
Project type and purpose
• Type: A compiler‐style project—specifically an interpreter for an imperative (and functional) toy language written in OCaml.
• Purpose: To parse source strings or files into an AST, then evaluate that AST in a denotational (functional) style using dynamic local and static non‐local environments. It also supports reflection by re‐parsing strings at runtime.
File structure
Top level:
• README.md – project overview and build/run instructions
• YarminDocs/ – LaTeX documentation source (design choices, parsing & lexing, testing, glossary)
• src/ – all OCaml source and build scripts
src/ contains:
• Lexing (YarminLexer.{mll,ml,cm*})
• Parsing (YarminParser.{mly,ml,cm*,mli})
• AST definition (Ast.{mli,cmi})
• Environments & store (Funenv.{ml,mli,cm*}; Funstore.{ml,mli,cm*})
• Core interpreter (yarmin.ml, yarminBasic.ml, loadAll.ml)
• Test harness (YarminTest.ml)
• Scripts (compileAll.sh)
README for additional insights
• Uses Menhir for parsing, ocamllex for lexing
• Denotational interpreter with distinct environment layers
• REPL interaction via rlwrap + OCaml toplevel, loading loadAll.ml
• Automated tests via #use "YarminTest.ml"
Components
a. Main components
1. User / REPL Frontend (rlwrap + OCaml toplevel)
2. Build Layer (compileAll.sh)
3. Lexer (YarminLexer)
4. Parser (YarminParser / Menhir)
5. AST Module (Ast)
6. Semantic Modules
• Environment Manager (Funenv)
• Store Manager (Funstore)
7. Interpreter Core (yarmin.ml, yarminBasic.ml)
8. Reflection Mechanism (invokes Lexer+Parser at runtime)
9. Test Harness (YarminTest.ml)
10. Documentation (YarminDocs) – secondary
b. Relationships & data flows
• The user types code or tests in the REPL, #use "loadAll.ml".
• loadAll.ml loads all compiled modules into memory.
• Interpreter Core calls the Lexer to tokenize input, then Parser to build an AST.
• AST is handed off to the denotational evaluator in Interpreter Core.
• The evaluator uses Funenv for local/static environment lookups and Funstore for mutable state.
• Reflection calls back into the Lexer+Parser pipeline at runtime.
• Test Harness invokes Interpreter Core on predefined test scripts.
c. Architectural patterns / design principles
• Pipelined architecture: clear stages (lexing → parsing → AST → evaluation).
• Modular design: each concern in separate module (lexer, parser, AST, env, store, core).
• Denotational semantics: interpreter functions map AST nodes to semantic values.
• Reflection: self‐hosted parsing at runtime.
• Scripted build: compileAll.sh ensures all modules are built before REPL usage.
d. Key technologies / frameworks
• OCaml (core language)
• Menhir (parser generator)
• ocamllex (lexer generator)
• rlwrap + OCaml toplevel for REPL
• Bash (compileAll.sh)