Skip to content

gurbaaz27/Group_26_CS335_Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CS335A Compiler Design: Course Project

Our SIT triplet is (Go, Python, MIPS).

Table of Contents

  1. Salient Features
  2. Timeline
  3. Usage Guidelines
  4. Group Members
  5. Acknowledgement

Salient Features

  • Native Data types (integer, float, bool, string).
  • Variables and Expressions
  • Control structures
    • Conditionals (if, if-else, switch)
    • Loops (for).
  • Input/Output statements (scanf, printf)
  • Arrays (multidimensional array supported)
  • Functions (Recursion is supported)
  • User defined types (struct)
    • Nested structs are also supported
  • Pointers/References
  • Short declarations using :=
  • Automatic type inference
  • Short-circuit evaluation
  • String concatenation with "+" (memory allocated to string from heap)
  • Evaluation of compile-time constant expressions
  • Multi level Pointers
  • Multi level Break

i. Timeline

  • Milestone 1 : Specs
    • Due on: 24.01.2022
    • In this milestone, we had to provide the details of our Compiler.
    • Deliverables
      • docs/specs.pdf
  • Milestone 2 : Scanner
    • Due on: 01.02.2022
    • In this milestone, we had to construct a scanner for the source language to output the tokens in a tabular form.
    • Deliverables
      • src/lexer.py
      • tests/scanner/
      • docs/lexer.md
      • Makefile
  • Milestone 3 : Parser
    • Due on: 18.02.2022
    • In this milestone, you have to develop a parser for the source language that outputs the Parser Automaton in a graphical form.
    • Deliverables
      • src/parser.py
      • src/dot.py
      • tests/parser/
      • docs/parser.md
      • Makefile
  • Milestone 4 : Semantic Analysis
    • Due on: 28.03.2022
    • In this milestone, you extend the project to perform semantic analysis. The goal is to convert your program into an AST Representation to be used by later stages (Intermediate and Final code generation, optimization, etc.).
    • Deliverables
      • src/parser.py
      • src/utils.py
      • src/ast_plot.png
      • src/ast.dot
      • Makefile
  • Milestone 5: Activation Record and Intermediate Code Generation
    • Due on: 10.04.2022
    • Now that you can create AST and Symbol Table for a semantically meaningful program, it is time to generate Intermediate code (3-address code, 3AC) with support for run-time activations.
    • Deliverables
      • src/parser.py
      • src/utils.py
      • src/classes.py
      • Makefile
  • Milestone 6: The Destination
    • Due on: 25.04.2022
    • In this last part of the project, you will generate code for the target assembly.
    • Deliverables
      • src/compiler.py
      • src/constants.py
      • src/classes.py
      • src/tests.py
      • Makefile

ii. Usage Guidelines

Clone the repository, navigate into the directory and install the dependencies

git clone git@github.com:gurbaaz27/CS335-Course-Project.git
cd CS335-Course-Project/
pip install -r requirements.txt ## or pip3, according to your system

a. Milestone 2: Scanner

There are 5 test-cases present in tests/scanner/ directory. To run the test cases, simply run

make scanner test=<test_num>
## For example,
make scanner test=2

In case no test variable is mentioned,make defaults to test=1, i.e.

make scanner ## is equivalent to
make scanner test=1

In case you want to run all test-cases at once, run

make scanner-all

If you do not have make installed, you can simply run the python script using

python src/lexer.py tests/scanner/<test_num>.go ## or python3, according to your system
## For example,
python src/lexer.py tests/scanner/2.go

NOTE 1 : We do not print COMMENT and NEWLINE in our output, since they have no role in parser.

NOTE 2 : We have purposely added an illegal character in 5th test-case, which should result our lexer throw an error message on encountering that character(s).

b. Milestone 3: Parser

There are 5 test-cases present in tests/parser/ directory. To run the test cases, simply run

make parser test=<test_num>
## For example,
make parser test=2

In case no test variable is mentioned,make defaults to test=1, i.e.

make parser ## is equivalent to
make parser test=1

If you do not have make installed, you can simply run the python script using

python src/parser.py tests/parser/<test_num>.go ## or python3, according to your system
## For example,
python src/parser.py tests/parser/2.go

This will generate src/parser.out and src/parsetab.py files and generate dot file named <test_num>.dot

Before moving to next test case, make sure to clean the src/ folder using

make clean ## or
rm -rf src/parser.out
rm -rf src/parsetab.py

To generate graph from dot file, install graphviz. For Ubuntu, you can use

sudo apt install graphviz

and make graph using

make graph test=<test_num> ## or
dot -Tpdf <test_num>.dot -o <test_num>.pdf

NOTE : We have purposely added an illegal syntx in 5th test-case, which should result our parser throw an error message.

c. Milestone 4: Semantic Analysis

There are 5 test-cases present in tests/semantic/ directory. To run the test cases, simply run

make semantic test=<test_num>
## For example,
make semantic test=2

In case no test variable is mentioned,make defaults to test=1, i.e.

make semantic ## is equivalent to
make semantic test=1

If you do not have make installed, you can simply run the python script using

python src/parser.py tests/semantic/<test_num>.go ## or python3, according to your system
## For example,
python src/parser.py tests/semantic/2.go

NOTE : We have purposely added wrong semantic in 3rd testcase, which should result our semantic analyser throw an error message.

d. Milestone 5: Activation Record and Intermediate Code Generation

There are 5 test-cases present in tests/3ac/ directory. To run the test cases, simply run

make ir test=<test_num>
## For example,
make ir test=2

In case no test variable is mentioned,make defaults to test=1, i.e.

make ir ## is equivalent to
make ir test=1

If you do not have make installed, you can simply run the python script using

python src/parser.py tests/3ac/<test_num>.go ## or python3, according to your system
## For example,
python src/parser.py tests/3ac/2.go

e. Milestone 6: The Destination

The test-cases are present in tests/final/ directory. To run the test cases, simply run

make final test=<test_name>
## For example,
make final test=print_literal

In case no test variable is mentioned,make defaults to test=print_literal, i.e.

make final ## is equivalent to
make final test=print_literal

If you do not have make installed, you can simply run the python script using

python src/compiler.py tests/final/<test_name>.go ## or python3, according to your system
## For example,
python src/compiler.py tests/final/print_literal.go

iii. Group Members

Group Number: 26

iv. Acknowledgement