0% found this document useful (0 votes)
45 views

Compiler Construction CSF363 Labsheet-1 (CMS)

This document provides instructions for accessing a CSIS Ubuntu server remotely and working with Lex tools for compiler construction. It describes how to connect to the server using SSH, either internally or externally. It also explains how to create a simple Lex program called first.l, compile it using Lex and gcc, and execute the resulting a.out file to recognize patterns in input and print output.

Uploaded by

Rishab Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Compiler Construction CSF363 Labsheet-1 (CMS)

This document provides instructions for accessing a CSIS Ubuntu server remotely and working with Lex tools for compiler construction. It describes how to connect to the server using SSH, either internally or externally. It also explains how to create a simple Lex program called first.l, compile it using Lex and gcc, and execute the resulting a.out file to recognize patterns in input and print output.

Uploaded by

Rishab Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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 [email protected]
(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 [email protected]
(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:
[email protected] .
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