CS3501 Set2
CS3501 Set2
1. Implement the lexical analyzer using Jlex, flex or any other lexical analyzer generating
tools.
2. i. Write a LEX program to identify whether the given line is comment line or not.
ii. Develop a LEX program to simulate lexical analyzer for validating operators.
3. Write a program to construct LL(1) parser for the grammar
SCC
CcC
Cd
4. Implement the back end of the compiler which takes the three address code and produces
the 8086 assembly language instructions that can be assembled and run using a 8086
assembler. The target assembly instructions can be simple move, add, sub, jump.
5. i. Write a LEX program to count the number of words, characters, blank spaces and lines
in a C file.
ii. Develop a LEX program to find the given string is identifier or not.
6. i. Write a LEX and YACC program to recognize a valid arithmetic expression that uses
the operator +, -, *, /.
ii. Write a LEX and YACC program to recognize a valid variable which starts with a
letter followed by any number of letters or digits.
7. i. Generate YACC specification to recognize while loop of a C file.
ii. Write a program for strength reduction to optimize the code.
Page 1 of 3
8. Write a program for implementing a calculator for computing the expression using
semantic rules of LEX and YACC.
9. Write a program to generate three address codes for the following expression using LEX
and YACC.
i. f=a+b-c*d
ii. x=y+z*50
10. Write a program for type checking using LEX and YACC.
11. Implement the following code optimization techniques.
i. Dead code elimination
ii. Code motion
12. Develop a lexical analyzer to recognize identifiers, digits, operators, keywords, special
characters of any source language.
13. Write a LEX program to generate the tokens in the following source code by removing
white space.
i. initial = rate*100.0
ii. printf (“%d”,&a);
14. Write a program to implement the following code optimization techniques.
i. Constant folding
ii. Unreachable code
15. Write a program to generate the target code for the below intermediate code .
temp1=id3*60.00
id1=id2+temp1
16. i. Write a LEX program to recognize the following control structure
a. while(i<n)
b. for(i<0;i<n;i++)
ii. Develop a program to eliminate the dead code from the intermediate code given
below.
a=9
b=c+d
e=c+d
f=b+e
r=f
Page 2 of 3
17. Write a LEX and YACC program to construct a calculator and evaluate the following
expression
i.6+6+1-(6+3)
ii.8(7*3)+10
18. Design and implement lexical analyzer for a given language using C and the lexical
analyzer should ignore redundant spaces, tabs and newlines. It should also ignore
comments. Although the syntax specification states that identifiers can be arbitrarily
long, you may restrict the length to some reasonable value. Simulate the same in C
language.
19. i.Write a LEX program to validate the below expression.
a. (d+f-g
b.((a+b)-c)
ii.Write a program to generate the tokens of any source language using LEX.
20. i. Write a program to recognize valid control structures syntax of C language for “if-else”
using LEX and YACC.
ii. Develop a program to recognize switch case statement using LEX and YACC.
Page 3 of 3