Skip to content

SinghCoder/Compiler-Construction

Repository files navigation

Compiler Construction

The repository contains the compiler implementation for a custom language as a part of course work for CS F363 - Compiler Construction at BITS Pilani under instructor Vandana Agarwal.

The language supports features such as

  • Static scoping of variables
  • Assignment, I/O, Declarative, Iterative, Conditional, Function call statements.
  • Returning multiple values from a function
  • Arithmetic and boolean expressions
  • Strongly typed language

The language specifications can be found here

Note

All files on this repository are for educational purpose with no intentions of promoting unfair means in any evaluative component.

How to run

In the Code directory, run the following commands

    make
    ./a.out testcase_file code_output_file
    nasm -felf64 code.asm && gcc -no-pie code.o -o code && ./code

where testcase_file is input test case file (Some semantically correct testcases can be found under Code/code_gen_tcs and Code/Sample_Programs), and code_output_file is the output file in which the asm code will be generated (like code.asm)

The asm code is compatible with NASM, version 2.14.02

Dependencies

  1. You should have NASM, version 2.14.02 installed on your machine. On ubuntu you can do so by running following command
    sudo apt install nasm
  1. You should have gcc, version 5.0 or above installed on your machine.

Sample run for testcase Code/Sample_Programs/Binary_search_dyn_arr.txt

Some additional information

  • To visualise parse tree/ abstract syntax tree, initialize parse_tree_file_ptr inside driver.c by opening a file and then call print_tree_for_tool(tree_ptr); where tree_ptr is corresponding tree pointer (ast / parse tree).

  • Then go to Tree visualizer and paste there the contents of the file you opened.

  • To generate Intermediate representation of a code call print_quadruples() after calling generate_ir() in driver.

Some snapshots

Known Problems / Future Scope

  • Ranges of the dynamic array input variable are stored in current scope's symbol table. This has following problems
    • Offsets get shifted accordingly.
    • testcases containing more than one dynamic array with same range lexemes won't work because ranges will be overwritten by the last array input parameter. 😢

Team Members

  1. Vishal Mittal Profile
  2. Harpinder Jot Singh Profile
  3. Yash Vijay Profile
  4. Jaladi Lakshmi Teja Profile
  5. Aditya Upadhyay Profile

Current Contributors

Made with contributors-img.

Commit History Visualizer

GIF

video

  • Above video is made using Visual Source

About

Compiler in C for a custom language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages