How sanjusree09/own-compiler works
Main Components
• Input (Source Code): This represents the user’s source code that needs to be compiled or interpreted.
• Lexer Component (lexer.js): Responsible for reading the input source code and splitting it into tokens.
• Interpreter Component (interpreter.js): Acts on the tokens—either parsing them into a form suitable for execution or directly interpreting/compiling them.
• Entry Point (main.js): The main script that ties everything together by invoking the lexer and interpreter. It orchestrates the compilation/interpreter process.
• The Project Metadata and Package Configuration: Represented by package.json and package-lock.json, indicating dependencies and environmental setup (though not part of runtime flow, they are essential for build/deployment).
Relationships and Interactions
• Flow starts at the Entry Point (main.js) which receives the source code.
• main.js then calls the Lexer (lexer.js) to tokenize the source code.
• The tokens output by the Lexer are fed into the Interpreter (interpreter.js) for processing.
• Finally, the Interpreter produces the result (this could be executed output, bytecode, or another intermediate representation).
• Dependencies and runtime configurations from package.json manage the environment.
Architectural Patterns
• Modular Component Design: Each file (lexer.js, interpreter.js, main.js) is organized by function, demonstrating separation of concerns.
• Pipeline Data Flow: The design follows a linear data processing pipeline—from source input to tokens to interpretation.
• Emphasis on simplicity: With minimal files and clear responsibility boundaries, the project adheres to a minimalist compiler architecture.
• At the top or left side, mark “User Source Code Input.”
• Optionally, include a note that package.json and package-lock.json support the necessary dependencies for running this system.