Indian Institute of Information Technology, Nagpur
Department of Computer Science and Engineering
Session:2024-2025
Course: Compiler
Lab Assignment 3
Semester: VI Marks: 30
This assignment is based on preprocessing C language program. Submission deadline is 2nd
April 2025.
1. Convert “for-loop”/“do-while loop” to “while loop” without changing the meaning of
the program. There may be loops inside loops and so on. The input would be a C
language program and output would be a valid C language program. Both the programs
should be compiling and producing same output for same input. [10M]
2. Write a lex program which takes a C language program as input and places a marker
<KW> and <ID> with every Keyword and Identifier respectively.
Example:
Input Program
main( )
{
int a = 10;
printf(“%d\n”, a);
}
Output program
main( )
{
int<KW> a<ID> = 10;
printf(“%d\n”, a);
} [10M]
3. Write code to process macros.
For Example:
#define f(x) x*x
If anywhere f(x) appears in any function then it is replaced by the right side of the
macro substituting for the argument ‘x’.
For example, f(3) would be replaced with 3*3. Remember that a macro can call
another macro.
The program should also produce a table of all macros (#defines) and their values.
[10M]