Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
30 views4 pages

Compiler 1 and 2

CD questions

Uploaded by

MD FARHAN 3070
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views4 pages

Compiler 1 and 2

CD questions

Uploaded by

MD FARHAN 3070
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CO1

1. A lexical analyzer uses the following patterns to recognize three tokens T1, T2, and
T3 over the alphabet {a,b,c}. T1: a?(b∣c)*a T2: b?(a∣c)*b T3: c?(b∣a)*c
If the string bbaacabc is processes by the analyzer, which sequence of tokens it
outputs?

2. A particular BNF definition for a “word” is given by the following rules.

Which of the following lexical entries can be derived from < word > ?
I. pick
II. picks
III. c44

3. How many tokens are there in the following C statement?


printf("i = %d, &i = %x", i, &i);

4. Convert the NFA to DFA

5. Write the grammar to produce a language consisting of palindrome strings over


∑={a,b} is
CO2
6. Given the following expression grammar:

E→ E*F|F+E|F
7.
F → F - F | id

which operator has a higher precedence? Explain

8. Consider the following grammar G.

S→F⎪H
F→p⎪c
H→d⎪c

Where S, F and H are non-terminal symbols, p, d and c are terminal symbols.


Construct the LL(1) parsing table

9. Consider the following grammar.


S → ACB|Cbb|Ba
A → da|BC
B → g|Є
C→ h| Є

Compute First(S).

10. Consider the following grammar.


S → ACB|Cbb|Ba
A → da|BC
B → g|Є
C → h| Є

Compute Follow(B).

11. Consider the following grammar.


E→ E-T|T
T→ T+F|F
F → (E) | id

Eliminate left recursion

12. Consider the following grammar.


S → Saa | aab | aac.

Convert the given grammar to an LL(1) grammar a)

13. Consider the following LL(1) grammar.


S → aSb | ε
Compute the LL(1) parse table for this grammar.

14. Consider the following grammar.

S → aSC | b
C → cC | d
How many steps are needed to derive the string aabcdd using leftmost derivation?

15. Consider the grammar


E→E+n|E×n|n
For a sentence n+nxn, what is the depth of the parse tree (assuming depth at the root
is zero)?

16. Show that the following grammars are ambiguous?


a) S → aS |Sa| Є
b) E → E +E | E*E| id
c) A → AA | (A) | a

17. Compute the predictive Parsing table for the grammar S → ( S )S |


How many push and pop operations are needed to parse ()()$? Do not count pushing
the first $ and S.

18. For the grammar below, a partial LL(1) parsing table is also presented along with the
grammar. Entries that need to be filled are indicated as E1, E2, and E3. is the empty
string, $ indicates end of input, and, | separates alternate right hand sides of
productions.

What are E1, E2 and E3?

19. If x is terminal then what will be FIRST(x) is

20. Consider the following grammar

S → iCtSS1|a
S1 → eS|ϵ
C→ b

Show that the grammar is ambiguous. Is the grammar LL(1)?

21. Consider the following grammar


S → FR
R→S|ε
F → id

In the predictive parser table, M, of the grammar, what are the entries M[S, id] and
M[R, $] ?

22. Consider the following grammar


S → aB | bA
B → b | bS | aBB
A → a | aS | bAA
Show the derivation of the string “aabbab”

You might also like