How shamsparvezarka/bmo works
Main Components
• BMO Front-End Components:
• Lexer (source/Lexer.java): Responsible for reading raw input text and outputting tokens.
• Parser (source/Parser.java): Transforms tokens into an Abstract Syntax Tree (AST) consisting of expression nodes (source/Expr.java) and statement nodes (source/Stmt.java).
• Resolver (source/Resolver.java): Performs variable and scope resolution to validate semantics before interpretation.
• Interpreter & Environment:
• Interpreter (source/Interpreter.java): Executes the AST by evaluating expressions and executing statements.
• Environment (source/Environment.java): Manages variable scopes and runtime context.
• Error Handling:
• RuntimeError (source/RuntimeError.java) and Return (source/Return.java): Handle exceptions and control flow during execution.
• Supporting Functionality:
• BMO.java, BMOCallable.java, BmoFunction.java: Likely represent the main entry point and provide support for functions/callable objects.
• AST Generation:
• Tool component (tool/GenerateAst.java): A utility for generating or transforming the AST classes for the language.
• Build and Documentation:
• build.ps1 and related build scripts indicate a script-driven build process generating class files, while DOCUMENTATION.md documents the language.
• Input Source Code (BMO code from test/main.bmo or user input) →
• Lexer: A component that tokenizes the input.
• Parser: Consumes tokens to produce the AST (represented by Expr and Stmt nodes).
• Resolver: Analyzes the AST to resolve variable scopes, linking identifiers to definitions.
• Interpreter: Executes the AST based on the current Environment, performing runtime logic.
• Supporting function modules such as BMOCallable and BmoFunction which are used when the AST includes function calls.
• Error handling via RuntimeError and the control flow flag Return.
Architectural Patterns
• The project uses the Interpreter design pattern, employing separate classes for each language processing stage.
• There is a clear separation between the lexing/parsing (front-end) and execution (back-end) phases.
• The AST generation tool exemplifies a meta-programming approach that eases AST class expansion/modification.