Make sure you have a Linux environment for this project. You can use 'bolt', your own Linux machine, or Windows Subsystem for Linux(WSL). I highly recommend you directly use 'bolt' since it contains all the necessary tools preinstalled.
ssh <your-net-id>@bolt.cs.ucr.edu
Make sure you have the following tools installed and check the version:
- flex -V (>=2.5)
- git --version (>=1.8)
- make -v (>=3.8)
- gcc -v (>=4.8)
- g++ -v (>=4.8 optional if you wish to use C++)
Use 'git' to clone the project template:
git clone <your-repo-link> lab1
Read the documentation of flex and your tasks in home page for lab1. From this starter template, you can edit 'calc.lex' to finish tasks step by step.
Here is a basic FLEX tutorial: http://alumni.cs.ucr.edu/~lgao/teaching/flex.html
flex can generate C source code of a lexer using flex specification 'calc.lex' in our lab.
flex -o calc.c calc.lex
After generate the C code, we can use gcc to compile it and link flex library 'fl' to support its functionailty.
gcc calc.c -lfl -o calc
The lexer will read from STDIN and tokenize your input stream by running actions defined in your specification.
We recommand you to write a Makefile to avoid typing these commands repeatly.
After you finish all 4 tasks, you are done the first part of this lab. You don't need to submit the code but should keep your progress until next time when we start learning syntax analysis.
Uploading to Github is a safe way:
git add . # add all files under current folder to staged changes
git commit -m "lab1 - lexer" # create a new commit
git push # upload to Github, it may requires your username and password of Github