A compiler that translates Pascal syntax into MIPS assembly language using Bison and Flex, implemented in Lex, Yacc, and C.
- Pascal to MIPS assembly translation
- Lexical analysis using Flex
- Syntax parsing using Bison
- Error detection and reporting
- MIPS code generation
- GCC compiler
- Flex (lexical analyzer generator)
- Bison (parser generator)
- Make (optional, for automated building)
makebison -d CPM.y
flex CPM.lex
gcc -o CPM.exe lex.yy.c y.tab.c- Built compiler executable (CPM.exe)
- Pascal source files to compile
-
Open Command Prompt and navigate to the directory where you extracted the compiler files
-
Select Input Files - Follow the interface shown below to choose your Pascal source files:
-
Execute Compilation - Press Enter to start the compilation process
- Success: If no errors occur, a MIPS assembly file will be generated
- Error: If compilation fails, an error text file will be created with details
-
Compilation Process:
-
Successful Output:
The compiler provides comprehensive error reporting. Below are examples of different error scenarios:
- Success:
.mipsfile containing the translated assembly code - Error:
.txtfile containing detailed error messages and line numbers
Mips_Compiler/
├── CPM.lex # Lexical analyzer specification
├── CPM.y # Grammar specification (Bison)
├── CPM.exe # Compiled executable
├── examples/ # Test cases
├── Makefile # Build automation
├── README.md # This file
├── WorkingExample.txt # Valid Pascal code
└── NotWorkingExample.txt # Invalid Pascal code (for testing)
The examples/ directory contains sample Pascal programs:
basic_arithmetic.txt- Arithmetic operationscontrol_flow.txt- If/else and while loops
- Flex: Lexical analyzer generator
- Bison: Parser generator (successor to Yacc)
- C: Implementation language
- Pascal: Source language
- MIPS: Target assembly language
make clean
makemake test # Test with working example
make test-error # Test with error exampleThis project is licensed under the MIT License - see the LICENSE file for details.






