This repository showcases a collection of scripts and resources designed to implement basic components of a compiler. The focus is on macro processing, lexical analysis, parsing, intermediate code generation, and code optimization.
Each script in this repository implements a core part of the compilation process, offering examples, explanations, and code snippets. These tools are ideal for anyone looking to learn about or implement foundational concepts in compiler construction.
- 01_pass1_macro_processor.py: Implements the first pass of a macro processor.
- 02_pass2_macro_processor.py: Implements the second pass of a macro processor.
- 03_lexical_analyzer.py: Implements a lexical analyzer to tokenize source code.
- 04_shift_reduce_parser.py: Implements a shift-reduce parser for syntax analysis.
- 05_intermediate_code.py: Generates intermediate code representation of the source program.
- 06_code_optimization.py: Implements basic code optimization techniques.
- notes.txt: Contains additional explanations, theory, and examples for understanding the implemented tools.
- viva_prep.txt: A compilation of notes for viva preparation.
Run each script sequentially to simulate different stages of the compilation process:
bash python 01_pass1_macro_processor.py python 02_pass2_macro_processor.py python 03_lexical_analyzer.py python 04_shift_reduce_parser.py python 05_intermediate_code.py python 06_code_optimization.py
Review notes.txt and viva_prep.txt for more theoretical background and additional examples.
Feel free to fork the repository, make modifications, and submit pull requests if you have improvements or enhancements.
This repository is open-source and available under the MIT License.
For questions or suggestions, feel free to open an issue or contact me at [[email protected]].