How ai-r-ia/compiler works
Main Components
• Input Module: Represent the “testcase” file(s) (e.g., testcase.txt) that is fed into the compiler.
• Driver/Main Module: Represented by driver.c, main.c, and possibly the “stage1exe” executable. This module handles command‐line arguments and orchestrates the flow.
• Lexer (Lexical Analysis): Capture files like lexer.c, lexer.h, lexical_token.c/h, and lexerDef.h. This component reads the source file and converts it into a stream of lexemes/tokens.
• Parser (Syntactic Analysis): Use parser.c, parser.h, parserDef.h, and supporting modules (grammar.txt, rules.c/h, rulesDef.h). This component takes the token stream from the lexer and builds the parse tree.
• Parse Tree Representation: Indicated by files such as parse_tree.txt and parseTreeOutFile.txt. This module represents the syntactic structure produced by the parser. Components like tree.c, tree.h, and treeDef.h support this.
• Utility Modules: Include additional support modules like strings, vectors (vectors.c/h, vectorDef.h), symbol table (symbol_table.c/h and symbol_tableDef.h), and utils. They play a role in managing memory, data structures, and additional computation.
• Testing & Debugging: The Test_Cases directory, as well as the “test” folder, indicate support for various test inputs and unit tests for discrete parts of the system (lexer, parser, etc.).
• Output of the Lexer to the Parser, indicating that the parser consumes tokens and builds the parse tree.
• From the Parser, show the production of the Parse Tree which is stored/output in files like parseTreeOutFile.txt.
• Interconnections from Utility Modules (such as the symbol_table and vector modules) to both the Lexer and Parser if they are used to manage dynamic data or support error handling.
• Link the Driver module to these core components to illustrate the overall control flow from input execution to output generation.
• Optionally, represent the Test modules as separate components that interact with the core components to validate their correctness.
Architectural Patterns and Design Principles
• Layered/Modular Architecture: Emphasize that the project is broken down into distinct components (lexer, parser, utilities, etc.), each in its own module with clear interfaces.
• Separation of Concerns: The design separates lexical analysis from parsing and from utility functions, resulting in improved maintainability.
• Testing as an Integral Part: The presence of separate testing directories reinforces that unit tests are a first-class citizen in the build process, ensuring each component’s correctness.
• Use of Header Files: Indicate that each major component is encapsulated with corresponding header files, enforcing module boundaries.
Relevant Technologies, Frameworks, and Artifacts
• Makefile: Include a “Build” or “Compilation” component that uses the Makefile, which drives the building of the entire compilation pipeline.
• Test Cases: Clearly detail the paths of the provided test cases and how they integrate into system testing.
• Documentation: Reference external documents like “Language specifications (1).pdf” and “coding details.pdf” as supporting artifacts shaping the design specs.