This is a to-be compiler for GoLang with Python as the implementation language and MIPS as the target language.
In order to run the lexer, follow these steps:
1. cd asgn1
2. make
3. bin/lexer test/test1.go
In order to generate tokens for other input files, just replace the file being passed to the lexer.
In order to run the Parser, follow these steps:
1. cd asgn3
2. make
3. bin/parser test/test1.go
4. /path/to/browser test1.html
In order to generate output for other input files, just replace the file being passed to the parser
In order to run the Intermediate Code Generator, follow these steps:
1. cd asgn4
2. make
3. bin/irgen test/test1.go
In order to generate assembly code for other input files, just replace the file being passed to the code generator.
In order to run the Assembly Code Generator, follow these steps:
1. cd asgn2
2. make
3. bin/codegen test/test01.ir
In order to generate assembly code for other input files, just replace the file being passed to the code generator.
Note:
- The src folder consists of the following files:
- code.py: It defines the data structure of the code and also for the derived class of it which is the 3AC.
- codegen.py: It takes 3AC as input file, which then parses it to find the leaders. The leaders are then added into a list. This is followed by the creation of the symbol table and the generation of the assembly code. In this file, we have dealt with translation of each operator individually.
- lexer.py: This file uses ply.lex as lexical analyser which in turn generates the stream of tokens which are required for parsing.
- parser.py: This file contains the parser for the source language. It uses PLY and hence yacc (yet another compiler compiler) implementation
- registers.py: It contains the list of all the registers which are available to us in MIPS. It has "reg_dis" dictionary which maps the registers to variables. The functions such as getnextuse and getemptyreg are implemented using the algorithm discussed in the class. It also contains some auxillary functions for different purposes. "last_use" is used for storing the line number where this register was last used, this is crucial since we don't want to empty the register which is being used in the same line.
- symbol_table.py: It defines the symbol table, and maintains the list of variables as dictionary. It containes the get_variables function which used the keywords generated by the lexer as varibales. We have populated the symbol table as per the algorithm which was discussed in the class.
Remarks:
- The lexer and parser were created using PLY (Python Lex-Yacc).
- The general format of the ThreeAddressCode is as follows:
- LineNo, Operand, destination, Source1, Source2 (without spaces)
- We have taken an implicit assumption that the 3AC will have 5 arguments. So, if let say one of them is not present, we define the entity to be empty. Eg: 1,print_int,aa,,
Authors: