Compiler Construction CSF363 Labsheet-1 (CMS)
Compiler Construction CSF363 Labsheet-1 (CMS)
Compiler Construction CSF363 Labsheet-1 (CMS)
Prof.R.Gururaj
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).
%%
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