Lab Assignment 3
Lab Assignment 3
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]
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]