Compiler Construction CSF363 Labsheet-1 (CMS)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Labsheet-1

Prof.R.Gururaj

A. Introduction to Compilation process (theory)


Language processors
Structure of compilers
Translation process
Lexical and Syntax Analyzers
B. Compiler Construction tools
Tools-Lex and Yacc
C. Intro to Lex
D. Accessing CSIS Ubuntu server
E. Creating first lex program, compiling and executing the same
F. Solving Some practice problems

Using Lex :
This is a tool to construct lexical analyzer for given REs (patterns).
The language to specify this is known as Lex Language.
We use Lex compiler.
Input patterns→ Transition diagrams→ code (lex.yy.c)
Lex file→ Lex Compiler→ lex.yy.c → C compiler→ a.out
Input stream → a.out → sequence of tokens
Lab work: We have created user accounts for all students on our CSIS
server (Ubuntu) .

How to access over WAN (from outside the campus) through ssh:
IP address: 125.22.54.200, port No: 51346
Command: ssh -p 51346 <username>@125.22.54.200
(student can connect through Command prompt, terminal, and other
modes like putty or telnet, etc)
Using Command prompt:
ex: ssh -p 51346 2016a7ps0031h@125.22.54.200
(both username and password is your id in lower case, once you login
for the first time please change the Password).

How to access from within the campus through ssh:


IP address: 172.16.88.64
Command: ssh <username>@172.16.88.64
(student can connect through Command prompt, terminal, and other
modes like putty or telnet, etc)
ex: ssh 2016a7ps0031h@172.16.88.64
(both username and password is your id in lower case, once you login
for the first time please change the Password).
The server is accessible 24X7.In case you need help, may contact
Mr.Suresh Gummalla (CSIS Lab Tech support) at:
suresh@hyderabad.bits-pilani.ac.in .
How to edit, compile, and execute lex files.
From windows machine from within the campus:
//students can use vi editor, vim editor or nano editor to create .l and
.y files
Now Create a file first.l with the following :

%%
yes {printf("Hello\n"); printf("good \n: ");}
%%
main()
{
yylex();
}
// to recognize pattern “yes”, and if found will print Hello and good;
takes input from keyboard and output on to the monitor
Next step is to compile a lex file using lex compiler
gururaj@csis-bits:~$ lex first.l
This will create a .c file lex.yy.c (will contain code in C for the lexer)
Now compile the .c file as below.
gururaj@csis-bits:~$ cc lex.yy.c -ll
This will create an executable file that lexer
Now execute the lexer as below.
gururaj@csis-bits:~$ ./a.out
yes
Hello

You might also like