How tgw314/lion works
Main Components
• Lexical Analyzer: Represented by tokenize.c – this module handles scanning the source code input and converting it into tokens.
• Parser: Shown by parse.c – it takes the token stream and builds the syntactic structure (likely an abstract syntax tree).
• Type System/Semantic Analysis: Indicated by type.c – responsible for handling type checking and possibly other semantic validations.
• Code Generation: Carved out in codegen.c – generates target code from the processed AST.
• Core Entry Point: main.c – coordinates compiler execution and integrates the various phases.
• Additional Support/Test Components: Include test.c and test_common.c, which are used to validate the compiler's functionality.
• Utility/Supporting Files: lion.h for function prototypes and shared definitions, Makefile for build instructions, .clang-format for code style, and .gitignore to manage version control artifacts.
• Self-compilation or auxiliary functionality: The self.py file likely serves as a script to facilitate some self-hosting or testing behavior.
Relationships and Interactions
• Lexical analysis: main.c directs the input stream into the tokenizer (tokenize.c), where source text is split into tokens.
• Parsing: Tokens are then passed to the parser (parse.c) which creates the AST.
• Semantic Analysis: The AST is then processed by type.c for type checking and semantic validation.
• Code Generation: Once validated, the code generator (codegen.c) is invoked to produce executable or intermediate code.
• Testing: test.c and test_common.c should be depicted as auxiliary components that interact with the compiler modules to ensure correctness.
• Utility: lion.h is shared among most modules, acting as a common interface. The Makefile orchestrates the build process and integration of these components.
• Optionally, self.py represents a scripting tool whose role might be to run tests or even bootstrap some of the compiler’s operations.
Architectural Patterns
• Modular Compiler Phases: Clearly illustrate the separation of concerns by breaking down the compiler into its logical phases (tokenization, parsing, type checking, and code generation).
• Data flow between components is linear (or slightly iterative during test cycles), showing a “pipeline” of transformation from source code to output.
• Integration of Tests: Include how testing utilities plug into the overall workflow.