https://github.com/anaskhan96/r2ic
A front end compiler to compile basic constructs in Rust to an intermediate code (quadruples) with optimizations
https://github.com/anaskhan96/r2ic
abstract-syntax-tree intermediate-code intermediate-representation lexer parser quadruple rust
Last synced: 10 months ago
JSON representation
A front end compiler to compile basic constructs in Rust to an intermediate code (quadruples) with optimizations
- Host: GitHub
- URL: https://github.com/anaskhan96/r2ic
- Owner: anaskhan96
- License: mit
- Created: 2018-02-07T15:08:20.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-28T11:30:44.000Z (over 7 years ago)
- Last Synced: 2025-03-24T07:48:53.590Z (about 1 year ago)
- Topics: abstract-syntax-tree, intermediate-code, intermediate-representation, lexer, parser, quadruple, rust
- Language: Python
- Homepage:
- Size: 55.7 KB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# r2ic
`r2ic` converts a rust program (containing only its basic constructs - `if`, `else`, `for`, `while`, and `loop`, along with variable declarations with `let`) to an intermediate code in the form of quadruples. It also generates an abstract syntax tree for expressions and assignments. The intermediate code generated has three kinds of code optimizations:
+ Constant folding
+ Constant propagation
+ Loop unrolling
The tool is built using Python's PLY framework for scanning tokens and parsing the input.
### How to run it
Test cases can be added inside `src/test-cases` with the format specified. The test case number can then be provided as a command line argument to `main.py` inside the src directory. For eg, to run the test case `src/test-cases/case2.txt`, the command would be as given:
```bash
cd src
python3 main.py 2
```
---
This project was built under the course *Compiler Design Laboratory* in *PES University*.