How antoniiolpzzz/comp-miniccompiler works
The MiniC Compiler project is a dedicated educational compiler developed for a university compilers course. It is designed to compile a simplified C-like language (miniC) through the common compilation phases: lexical analysis, syntactic analysis, and semantic analysis. The project uses C as its core language, augmented by Flex for tokenizing source code and Bison for parsing according to defined grammar rules.
Main Components
• Compiler Main (miniCCompilerMain.c): Acts as the entry point of the application.
• Lexical Analysis Module (Directory: Lexical):
• File: miniCLexical.l
• Role: Uses Flex to generate tokens from the input miniC source file.
• Syntactic Analysis Module (Directory: Syntactic):
• File: miniCSyntactic.y
• Role: Uses Bison to parse the token stream and enforce language grammar rules.
• Semantic Analysis Module (Directory: Semantic):
• Files: miniCCodeList.c/h, miniCSymbolTable.c/h
• Role: Manages the symbol table and possibly intermediate code (or code list creation) to form the semantic (or later code generation) part of compiling.
• Build/Execution Components:
• Makefile: Orchestrates the build process.
• testFile.mc: Serves as an example input file for demonstration/testing.
Relationships and Interactions
• The process begins with the execution of the compiler (invoked via the Makefile or directly running miniCCompilerMain).
• The compiler reads the input file (e.g., testFile.mc) and passes it to the Lexical Analyzer.
• The Lexical Analyzer (via miniCLexical.l) tokenizes the input and sends a stream of tokens to the Syntactic Analyzer.
• The Syntactic Analyzer (through miniCSyntactic.y) uses these tokens to build a parse tree according to the miniC grammar and, during this process, invokes routines from the Semantic Analysis module.
• The Semantic Analysis module (using components like miniCSymbolTable and miniCCodeList) validates correct semantic usage (e.g., symbol declarations, code lists for further processing) and likely prepares the compiled output.
• Finally, the compiler produces an output (an executable or an assembly file, as indicated in the README via redirection to compiledfile.s).
Architectural Patterns and Technologies
• Pipeline Pattern: The compiler’s modules are organized in a sequential pipeline (Lexical → Syntactic → Semantic) which is typical for compiler design.
• Separation of Concerns: Each major phase (lexical, syntactic, semantic) has its own dedicated module/folder.
• Use of Industry-standard Tools: Flex handles tokenization whereas Bison manages the parsing phase.
• Integration via Build System: The Makefile coordinates the build process, demonstrating a simple but effective continuous integration mechanism within the project.
Final Recommendations
• Be as detailed as possible to capture all key interactions.