How kovalmaksym/ifj works
Main Components
• Entry Point and I/O Handling:
• Main Component (main.c): Acts as the driver that accepts the input (source code file) and output file names.
• Lexical Analysis:
• Scanner (scanner.c and scanner.h): Reads the input file character-by-character and produces a stream of tokens.
• Syntax Analysis:
• Parser (parser.c and parser.h): Processes the token stream using the grammar rules defined (see doc/Grammar.txt and doc/GramToLL.txt) and checks the validity of the code.
• Precedence Handling (precedence.h): Likely assists in managing operator precedence during parsing or expression evaluation.
• Expression Evaluation:
• Expression Module (expression.c and expression.h): Works on recognizing, evaluating, or converting expressions.
• Semantic Analysis and State Management:
• Symbol Table (symtable.c and symtable.h): Manages symbol definitions, variable scopes, and type checking.
• Stack (stack.c and stack.h): Provides data structures to support parsing (perhaps during expression evaluation) and managing runtime states.
• Code Generation:
• Code Generation Module (codegen.c and codegen.h): Responsible for generating the output code or intermediary representation based on the parsed input.
• Documentation & Auxiliary Files:
• Documentation (doc/ directory): Includes grammar definitions and tables (doc/tables.txt) which can be referenced for in-depth understanding of the grammar and parsing process.
• Additional files (like Makefile and xkratk17.rar) serve build/deployment or submission-related roles.
Relationships and Interactions
• The application starts in Main, which handles input file reading and output file writing.
• Main calls the Scanner to convert the input file into a token stream.
• The Parser receives the token stream. It likely leverages the Precedence definitions to process expressions correctly.
• The Expression module operates within the parser to handle arithmetic or logical expressions.
• During parsing, the Symbol Table is used to store and look up variables/symbols.
• The Stack module is invoked by both the Parser and Expression modules to manage intermediate states or operator precedence as needed.
• Once the source program is parsed and its semantics verified, the Code Generation module constructs the output code or an intermediate representation which is then written to the output file.
Architectural Patterns and Design Principles
• Separation of Concerns: Each module (scanner, parser, codegen, etc.) has a distinct responsibility, making the project modular.
• Layered Architecture: The system processes the input in stages (lexical analysis → syntax analysis → semantic analysis → code generation).
• Reusability: Utility libraries such as the stack and symbol table could be designed for reuse in other parts of the project or similar projects.
Final Checklist
• Nodes/blocks for each main component: Main, Scanner, Parser (including its reliance on precedence/grammar files), Expression Evaluator, Symbol Table, Stack, and Code Generator.
• Blocks with file names and short descriptions to contextualize their roles.