Docsity

Backtracking - Compiler Construction and Languages - Past Exam, Exams of Compiler Construction

Toggle sidebar
bg1
Cork Institute of Technology
Bachelor of Science (Honours) in Software Development – Award
(NFQ – Level 8)
Summer 2007
Compiler Construction and Languages
(Time: 3 Hours)
Instructions
Answer FOUR questions
All questions carry equal marks.
Examiners: Dr. M. O’Cinneide
Mr. M. Donnelly
Mr. C.E. Manning
Q. 1 (25 marks)
Part A. (5 marks)
L is a language were all the words have exactly the same number of as, bs, and cs. E.g. aabccb,
cbbbaacac. Write a grammar for language L
Part B. (10 marks)
Write a Type 3 Grammar for the language described by ab+f+(ffc)*fg
[No marks available for a Type 2]
Part C. (10 marks)
Construct a deterministic finite state automaton (DFA) that is equivalent to ab+f+(ffc)*fg
[No marks available or an incomplete or non-deterministic machine]
pf3
pf4

Partial preview of the text

Download Backtracking - Compiler Construction and Languages - Past Exam and more Exams Compiler Construction in PDF only on Docsity!

Cork Institute of Technology

Bachelor of Science (Honours) in Software Development – Award

(NFQ – Level 8)

Summer 2007

Compiler Construction and Languages

(Time: 3 Hours)

Instructions Answer FOUR questions All questions carry equal marks.

Examiners: Dr. M. O’Cinneide Mr. M. Donnelly Mr. C.E. Manning

Q. 1 (25 marks)

Part A. (5 marks) L is a language were all the words have exactly the same number of as, bs, and cs. E.g. aabccb, cbbbaacac. Write a grammar for language L

Part B. (10 marks) Write a Type 3 Grammar for the language described by ab+f+^ (ffc)*fg [No marks available for a Type 2]

Part C. (10 marks) Construct a deterministic finite state automaton (DFA) that is equivalent to ab+^ f+^ (ffc)*fg [No marks available or an incomplete or non-deterministic machine]

Q. 2 (25 marks)

Part A (10 marks)

Find the FIRST and FOLLOW sets for each of the non-terminals in the grammar G (^1)

G 1 : S -> ABC A -> q | Cr B -> t | zA | ε C -> x | y | ε

Part B (5 marks) G 2 : S -> xS | SB | v B -> By | z

Demonstrate (using xvz or any other word) that grammar G 2 is ambiguous.

Part C (10 marks)

G 3 : Q -> Qz | Qx | z | Ry R -> Qz | y | yT T -> z

Remove all the left recursion from G 3

Q. 5

Part A (10 marks) Construct a Top Down Parse Table for the following grammar

S -> ayB | ayC | aD | z B -> a C -> z D -> z

Part B (15 marks)

M 1 States

ε x^ y^ z

0 (Start) 1 2,

1 (Accept) 2,

3 (Accept) 2 1

Use the subset construction technique to produce a deterministic finite state automaton equivalent to the one specified in the table above.