IT6612 CD LAB Manual, Compiler Laboratory Manual – IT 6th SEM Anna University


Anna University Regulation 2013 Information Technology (IT) IT6612 CD LAB Manual for all experiments is provided below. Download link for IT 6th SEM IT6612 Compiler Laboratory Manual is listed down for students to make perfect utilization and score maximum marks with our study materials.

Anna University Regulation 2013 Information Technology (IT) 6th SEM IT6612 COMPILER LAB-Compiler Laboratory Manual



To write a program for implementing a Lexical analyser using LEX tool in Linux platform.


1. Lex program contains three sections: definitions, rules, and user subroutines. Each section must be separated from the others by a line containing only the delimiter, %%.

The format is as follows:






2. In definition section, the variables make up the left column, and their definitions make up the right column. Any C statements should be enclosed in %{..}%. Identifier is defined such that the first letter of an identifier is alphabet and remaining letters are alphanumeric.

3. In rules section, the left column contains the pattern to be recognized in an input file to yylex(). The right column contains the C program fragment executed when that pattern is recognized. The various patterns are keywords, operators, new line character, number, string, identifier, beginning and end of block, comment statements, preprocessor directive statements etc.

4. Each pattern may have a corresponding action, that is, a fragment of C source code to execute when the pattern is matched.

5. When yylex() matches a string in the input stream, it copies the matched text to an external character array, yytext, before it executes any actions in the rules section.

6. In user subroutine section, main routine calls yylex(). yywrap() is used to get more input.

7. The lex command uses the rules and actions contained in file to generate a program, lex.yy.c, which can be compiled with the cc command. That program can then receive input, break the input into the logical pieces defined by the rules in file, and run program fragments contained in the actions in file.

3.(a) The program replaces the substring abc by ABC from the given input string:




int i;



[a-z A-Z]*

{ for(i=0;i<=yyleng;i++) {

if((yytext[i]==’a’)&&(yytext[i+1]==’b’)&&(yytext[i+2]==’c’)) {

yytext[i]=’A’; yytext[i+1]=’B’;

yytext[i+2]=’C’; } }

printf(“%s”,yytext); }

[\t]* return;

.* {ECHO;}

\n {printf(“%s”,yytext);}



{ yylex(); }

int yywrap() {

return 1;



[CSE@localhost ~]$ lex lex1.l

[CSE@localhost ~]$ cc lex.yy.c

[CSE@localhost ~]$. /a.out



IT6612 CD Lab Manual with all experiments – Download Here
If you require any other notes/study materials, you can comment in the below section.

Related Links
For IT6612 CD Lab Syllabus – Click here
Search Terms
Anna University 6th SEM IT CD LAB Manual
IT6612 Compiler Laboratory Manual free download
Anna University IT CD LAB Manual Regulation 2013
IT6612 Manual, CD LAB experiment wise Manual – IT 6th Semester


Comments are closed.