How airbus5717/rotate works
Project Overview & Main Components
• Project Type: This is a compiler written in C++ with a largely C-style approach using only standard C libraries (apart from language-specific syntax sugar).
• High-Level Pipeline:
• Main Entrypoint (main.cpp) that initializes the compiler.
• Lexical Analysis (Lexer in src/fe): Tokenization of the source code.
• Parsing (planned): Construction of an Abstract Syntax Tree (AST) based on token stream.
• Type Checking, Semantic Analysis, and further phases like Optimization and Code Generation (planned).
• Test Suite: Files under the test directory indicate that the compiler will be tested against various source files (with a .vr extension).
Breaking Down the File Structure
• Top-Level Files:
• Build and configuration files (CMakeLists.txt, Makefile, .clang-format, .clang-tidy, etc.) show how the project is assembled.
• LICENSE, README, and docs provide documentation and project context.
• src Directory:
• main.cpp: Entry point to the application.
• src/fe: Contains components for the front-end (currently the lexer is implemented).
• src/include: Contains header files for shared definitions and functionality (e.g., defines, arrays, logging).
• Utility functions and common code are in src/utl.
• Test Directory:
• Contains sample .vr source files, suggesting that these files are used to validate different language constructs.
Relationships and Interactions
• Flow of Data:
• Begin at the Compiler Driver, which reads a source file.
• Data flows to the Lexer (which converts characters into tokens).
• The supposed parser will then consume these tokens to build syntax trees.
• Subsequent compiler phases (type checking, semantic analysis, optimization, and code generation) use these trees.
• Utility and header libraries as supporting each core component.
• Tests as providing input and verification of the outputs from each stage.
Architectural Patterns & Design Principles
• Pipeline Architecture: Use a sequential pipeline approach to show compilation phases.
• Modularity / Separation of Concerns: Each component (lexer, parser, type checker, etc.) should be visually separated, with clear interfaces (e.g., token streams, ASTs) between them.
Practical Steps
1. Lexical Analysis (source: src/fe)
2. Parsing (planned)
3. Type Checking (planned)
4. Semantic Analysis / Analyzer (planned)
5. (Optional) Optimizer (possible future work)
6. Code Generation (planned for a custom architecture)
• At the bottom or as a parallel component: outline the testing infrastructure (test directory).
• Supporting components like build configurations (Makefile, CMakeLists.txt) and documentation (docs folder).
Final Recommendations
• Clarity: Each component should be clearly defined with proper annotations regarding status (implemented vs. planned).