Professional Documents
Culture Documents
2024 COMPILER DESIGN LABORATORY CSP1601 - Week 0
2024 COMPILER DESIGN LABORATORY CSP1601 - Week 0
docx
Week 0: Installation of Linux OS (Ubuntu) if required, installation of lex/flex, getting familiar with lex/flex syntax,
running sample program(s).
Instructions:
(If you have Ubuntu or WSL already installed, then go to Step no. 4)
1. Download virtualbox and install from:
Local server: \\192.168.1.52\Users\VirtualBox-7.0.6-155176-Win.exe
(copy and paste the above path in your browser)
b. Give the os name and select the downloaded iso file (Ubuntu OS)
c. Set the username and password, hostname (Remember this password to be used later to login)
d. Set the memory (RAM) and CPU cores. RAM = 4096 MB, Processors=2
f. Click Finish
g. The Virtual Machine (Ubuntu) will automatically be powered up and installation will run
h. Once the installation is finished. Log in using the password you set before.
Note: Now, you have Ubuntu installed on virtualbox inside a Windows OS.
If you open the virtualbox windows, the mouse and keyboard will be captured by the virtualbox.
To release the mouse and keyboard capture from virtualbox, press Ctrl (on the right side of your
keyboard)
i. Install VBoxLinuxAdditions and also make vboxuser root/admin by doing the following
a) Click
Devices->Insert Guest Additions CD Image..
b) Open a terminal using the command
Ctrl + Alt + T
c) In the terminal run the following command (to switch to root user):
su -
// Explanation:
// yywrap() - wraps the above rule section
/* yyin - takes the file pointer
which contains the input*/
/* yylex() - this is the main flex function
which runs the Rule Section*/
// yytext is the text in the buffer
yylex();
printf("\nNumber of Capital letters "
"in the given input - %d\n", count);
return 0;
}
b. Compile the lex/flex program (sample.l). The compilation will produce an output file called lex.yy.c
lex sample.l
c. Compile the lex.yy.c file (generated in the previous step) using gcc. This will produce the executable
code/file called a.out (a.out is the generated lexical analyzer / scanner)
gcc lex.yy.c
if you want to specify an output filename (e.g., sample_scanner) instead of the auto generated a.out,
use the following command
gcc lex.yy.c -o sample_scanner