Code Optimization using Finite Automata
In this collaborative project, groups of three students will collaboratively design and implement a
code optimization tool based on finite automata and regular expressions. The primary goal is to
develop a system that takes code written in a simple programming language and optimizes it by
identifying and applying various code transformations. The project will involve multiple stages,
including lexical and syntax analysis, code optimization using finite automata-based algorithms,
and the generation of an optimized intermediate code.
Project Components
1. Lexical Analysis: Develop a lexical analyser using finite automata to tokenize the input
code.
i. Define regular expressions for various token types (identifiers, keywords, operators).
ii. Implement a finite automaton for each regular expression to perform tokenization.
2. Syntax Analysis: Create a syntax analyser using context-free grammar to capture the
language's syntax.
i. Design and implement context-free grammar rules.
ii. Develop a finite automaton-based syntax analyser to ensure proper code structure.
3. Code Optimization Techniques: Implement finite automata-based algorithms for common
code optimization techniques (constant folding, dead code elimination, common
subexpression elimination).
i. Explore and understand the theory behind finite automata-based optimization
techniques.
ii. Develop algorithms to identify and apply optimizations during code analysis.
4. Intermediate Code Generation: Generate an intermediate representation of the code for
further optimization.
i. Develop a finite automaton-based intermediate code representation.
ii. Integrate intermediate code generation into the overall code optimization process.
Page 1 of 3
5. Real-world Applications: Discuss and implement optimizations relevant to real-world
compilers.
i. Research and identify optimizations commonly used in practical scenarios.
ii. Implement these optimizations and evaluate their impact on code efficiency.
6. Documentation and Reporting: Provide comprehensive documentation and a report on the
project.
i. Document design choices, algorithms, and the architecture of the code optimization
tool.
ii. Include a report on the effectiveness of optimizations in different code scenarios.