Compiler Design
Compiler Design
B) Define token, pattern, and lexeme with suitable examples. Find tokens, Remembering 6
pattern and lexemes forthe following C- program. Give reasonable at-
tribute values for the tokens.
int main()
{
int a = 10, b = 20;
printf (“Sum is : %d”, a+b);
return (0)
}
C) i) Explain regular expression and regular definition with example. Analyzing 6
ii) Write regular definitions for the following languages:
1. All strings of lowercase letters that contain the five vowels in
order.
2. All strings of lowercase letters in which the letters are in
ascending lexicographic order.
(a|b*ab)*
C) Convert the following NFA to DFA using subset construction algorithm. Remembering 6
Analyzing
((01| 0) 1*)*
Q.3 Solve Any Two of the following. 12
A) i) What is left recursion and left factoring? Remembering 6
ii) Consider the CFG SSS+| SS* | a
a) Left factor this grammar.
b) Eliminate the left recursion from the original grammar.
c) Is the resulting grammar suitable for top-down parsing?
C) What is LL(1) grammar? Construct a LL(1) parsing table for the Applying 6
following grammar. Test whether following grammar isLL(1).
S → aAB|bA|є
A → aAb |є
B → bB |c
Q.4 Solve Any Two of the following. 12
A) Explain stack implementation of shift reduce parsing with their four Understanding, 6
Applying
possible actions.
Consider the following grammar
S → TL
T → int | float
L → L,id | id
Parse the input string int id, id using shift – reduce parser.
ii)What is handle? Consider the following grammar and show the handle
S→ (L)|a
L → L ,S |S
S→ AaAb | BbBa
A →є
B→є