An open API service indexing awesome lists of open source software.

https://github.com/erfaniaa/compilers-course-project

Converting a pseudo-C source code to a pseudo-assembly code
https://github.com/erfaniaa/compilers-course-project

compilers cpp grammar lalr-parser lark-parser parser python3

Last synced: 10 months ago
JSON representation

Converting a pseudo-C source code to a pseudo-assembly code

Awesome Lists containing this project

README

          

# Compilers Course Project
> Converting a pseudo C source code to a pseudo assembly code

For more information, read the PDF files which are located in this repository (they're in Persian language).

## Dependencies

pip3 install -r requirements.txt


## Usage

python3 run.py input_file_name.c

**Sample input (pseudo C source code):**

Check out [sample.c](https://github.com/Erfaniaa/compilers-course-project/blob/master/sample.c) in the repository (to see the language features).

python3 run.py sample.c

**Sample output (pseudo assembly codes):**

No syntax errors
line number 0: jmp 15
line number 1: mov 0 #0
line number 2: pop 10000
line number 3: mov 4 #47
line number 4: push 4
line number 5: jmp 10000
line number 6: push #0
line number 7: jmp 10000
line number 8: pop 4
line number 9: pop 10000
line number 10: add 4 #47 4
...

## Notes

- This project was done by [Ali Mirjahani](https://github.com/alimirjahani7) and [Erfan Alimohammadi](https://github.com/erfaniaa) in 2019 for the [Shahid Beheshti University](http://en.sbu.ac.ir) Compilers Course project.
- You can modify the codes and produce your own programming language. There are not much hard-codes, so editing the language grammar would be easy. Grammar rules files have ".in" extension in the repository.
- There are no switch-case statements in the scanner finite-state machine part. Just draw your DFA graph on a paper, and enter the graph nodes and edges in the scanner; it will work for you! So, modifying scanner DFA (adding and removing edges) doesn't take time from you.
- This project uses a LL(1) parser (which is implemented by us) and a LALR parser (which is lark-parser, for parsing the boolean expressions). It switches between these two parsers, according to its state.