Skip to content

Latest commit

 

History

History
164 lines (117 loc) · 5.47 KB

README.md

File metadata and controls

164 lines (117 loc) · 5.47 KB

compiler-construction-lab

example workflow

visitors

This repository holds the code and instructions for the compiler construction lab (Spring 2021).

Contents

Installation for Windows10 or Ubuntu

Windows users need to install Ubuntu on (Windows Subsystem for Linux) WSL. If you have Ubuntu on your machine, you can skip the first step...

  1. Only for Windows 10 Users : Installing WSL and Ubuntu:

    This video demonstrates how to do this:

    How to Install Ubuntu on Windows 10 (WSL)

    You should be able to access an Ubuntu terminal after successfully completing this step. Watch the complete video to understand WSL Ubuntu's File Structure.

    PS: Please choose Ubuntu 20 for following the rest of instructions. Other distributions' steps may vary.

  2. Open the Ubuntu terminal and type the following:

    a. Update/Upgrade your ubuntu packages:

    sudo apt update
    sudo apt upgrade

    Give it the password when prompted and type in "y" when asked to install.

    b. Installing Flex:

    sudo apt install flex

    Installing Lex

    c. Installing Bison:

    sudo apt install bison

    Installing Bison

  3. Do a sanity check and test run of the software: a. First run a sanity check:

    which flex bison

    This should show you the location of installed packages usually:

    /usr/bin/flex
    /usr/bin/bison

    b. Run a Basic check program: On your terminal, copy or type the following:

    git clone https://github.com/theDrake1010/compiler-construction-lab.git
    cd compiler-construction-lab/checks

    Give the Execute permission to the run-check.sh file and run the file:

    chmod 744 ./run-check.sh
    ./run-check.sh

    The output should look like this: If the checks directory is not modified Output of Running Check

Installation For Mac

  1. Install Homebrew : Homebrew is a package manager for MacOS (kind of like what apt is to linux). After Successfull installation move onto next step.

  2. Open terminal :

    a. Update Brew using following commands:

    brew update 
    brew upgrade

    agree with "y" if prompred and it will update brew and all its packages to latest version

    b. Install Flex using following command:

    brew install flex

    Output of Installing Flex

    c. Insall bison using following command :

    brew install bison

    : Output of Installing Flex

  3. Do a sanity check and test run of the software:

    a. First run a sanity check:

    which flex bison

    This should show you the location of installed packages usually:

    /usr/bin/flex
    /usr/bin/bison

    b. Run a Basic check program: On your terminal, copy or type the following:

    git clone https://github.com/theDrake1010/compiler-construction-lab.git
    cd compiler-construction-lab/checks
    bash run-check.sh

    The output should look like this: If the checks directory is not modified Output of Running Check

Contribute

  • For proposing changes to the source code:

    1. Fork this repo.
    2. Modify the repo on your fork.
    3. Open a Pull Request with meaningful comment stating changes.
  • For reporting an issue:

    1. Go to the Issues Page
    2. Submit your issues with detailed report.

Important Notes

When it comes to writing files for flex, bison and modern C compilers, there are a few changes that need to be done...

  1. Use of "-lfl" instead of "-ly" and "-ll": The newer versions of GCC use the -lfl switch instead of -ly and -ll to link the necessary files.

  2. Versions < 2.5.9 have a memory leak issue that needs to be manually solved by calling the yylex_destroy() function at end of main().

  3. Any functions used in the *.y files need to be globally declared to avoid warnings. This includes void yyerror(char*) and int yylex(void) most importantly.

  4. void yyerror(char*) needs to be defined by the user as an aux function inside the *.y file.

More details can be obtained here: Converting from lex & yacc to flex & bison