This repository holds the code and instructions for the compiler construction lab (Spring 2021).
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...
-
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.
-
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
c. Installing Bison:
sudo apt install bison
-
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
-
Install Homebrew : Homebrew is a package manager for MacOS (kind of like what apt is to linux). After Successfull installation move onto next step.
-
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
c. Insall bison using following command :
brew install bison
-
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
-
For proposing changes to the source code:
- Fork this repo.
- Modify the repo on your fork.
- Open a Pull Request with meaningful comment stating changes.
-
For reporting an issue:
- Go to the Issues Page
- Submit your issues with detailed report.
When it comes to writing files for flex, bison and modern C compilers, there are a few changes that need to be done...
-
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.
-
Versions < 2.5.9 have a memory leak issue that needs to be manually solved by calling the
yylex_destroy()
function at end ofmain()
. -
Any functions used in the
*.y
files need to be globally declared to avoid warnings. This includesvoid yyerror(char*)
andint yylex(void)
most importantly. -
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