https://github.com/abaksy/golang-mini-compiler
A compiler front-end for Golang implemented using Python Lex and YACC that handles the switch and loop constructs
https://github.com/abaksy/golang-mini-compiler
compiler-design golang lex mini-compiler ply yacc
Last synced: about 1 year ago
JSON representation
A compiler front-end for Golang implemented using Python Lex and YACC that handles the switch and loop constructs
- Host: GitHub
- URL: https://github.com/abaksy/golang-mini-compiler
- Owner: abaksy
- Created: 2021-02-09T16:17:33.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-30T16:52:44.000Z (about 5 years ago)
- Last Synced: 2025-03-29T04:23:17.732Z (about 1 year ago)
- Topics: compiler-design, golang, lex, mini-compiler, ply, yacc
- Language: Python
- Homepage:
- Size: 641 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# golang-mini-compiler
A compiler front-end for Golang implemented using Python Lex and YACC (PLY) that handles the switch and loop constructs of Golang
## Optimizations implemented:
* Constant folding and constant propagation
* Packing temporaries (removing all unnecesary temp variables from TAC)
## Code Structure
* src/lexer.py - Generates Lex tokens from the input source file
* src/parser.py - Takes a stream of tokens as input from ```lexer.py``` and runs the LALR parser logic (rules and actions) on the tokens (outputs the three address code)
* src/optimize_tac.py - Runs the above mentioned optimizations on the generated Three Address Code from the parser
* src/code.py - Contains class definitions for Three Address Code and AST nodes
* src/symboltable.py - Contains class definition for SymbolTable
Command to run till IC Optimization Step:
```
export PATH=$PATH:/your-path-here/golang-mini-compiler
go-compile
```