0% found this document useful (0 votes)
23 views

Cosc 327

COSC 327

Uploaded by

grahamoyigo19
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)
23 views

Cosc 327

COSC 327

Uploaded by

grahamoyigo19
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/ 3

COSC 327

CHUKA UNIVERSITY

UNIVERSITY EXAMINATIONS

THIRD YEAR EXAMINATION FOR THE AWARD OF DEGREE OF


BACHELOR OF SCIENCE COMPUTER SCIENCE

COSC 327: COMPILER CONSTRUCTION

STREAMS: BSC (COSC) Y3S2 TIME: 2 HOURS

DAY/DATE: THURSDAY 09/04/2020 2.30 PM – 4.30 PM


INSTRUCTIONS:

• Answer Question ONE and any other TWO questions.


• Diagrams should be used whenever they are relevant to support an answer.
• Sketch maps and diagrams may be used whenever they help to illustrate your answer
• Do not write anything on the question paper
• This is a closed book exam, No reference materials are allowed in the examination room
• There will be No use of mobile phones or any other unauthorized materials
• Write your answers legibly and use your time wisely

SECTION A
ANSWER ALL THE QUESTIONS IN THIS SECTION
QUESTION ONE [30 MARKS]
a) Highlight the role of the symbol table in the compilation process. [4 Marks]

b) Giving one example for each, differentiate between a low level and a high-level
programming language. [4 Marks]

c) Compilers and Interpreters are both used in the language translation process.

i. Differentiate between a compiler and an interpreter [4 Marks]

Page 1 of 3
COSC 327

ii. Describe two advantages of compilers over interpreters [2 Marks]

iii. Describe two advantages of interpreters over compilers [2 Marks]

d) Identify any five categories of compilers and describe each. [5 Marks]

e) List and explain any four outputs of the preprocessor phase of compilation. [4 Marks]

f) Name any five popular compilers and identify the language popularly associated with.
[5 Marks]
SECTION B
ANSWER ANY TWO QUESTIONS FROM THIS SECTION
QUESTION TWO [20 MARKS]
a) In some language processing systems, the compiler compiles to assembly language rather
than to machine language. Discuss the pros and cons of this approach [6 Marks]

b) Pass and Phases are terms used in Compiler construction

i. Giving examples differentiate between a pass and a phase in compiler construction


[4 Marks]

ii. Identify any three type of passes in compiler design and describe each briefly
[6 Marks]

c) Describe how a typical Java program is compiled and highlight the benefit of such an
approach of compilation. [4 Marks]
QUESTION THREE [20 MARKS]
a) Draw a diagram of a typical language processing system and explain in detail what happens
at each stage of the processing through the system. [8 Marks]

b) C++ is an example of a language that is compiled


i. Write a well-designed C++ program that sums up a CAT and EXAM and
determines the total mark. The program then determines whether a student has
passed or not given that passmark is greater or equal to 40 marks. [6 Marks]

ii. By referencing the language processing system in a) above, explain how this C++
program moves from source language to target language. [6 Marks]

Page 2 of 3
COSC 327

QUESTION FOUR [20 MARKS]

a) Explain how lexemes becomes tokens and consequently highlight the importance of tokens in
the compilation process. [4 Marks]

b) Formally define a Context Free Grammar and explore the role a Context Free Grammar plays
in the compiler design. [6 Marks]

c) For any context-free grammar there is a parser that takes at most 0(n3) time to parse a string
of n terminals.

i. Highlight the relationship between a Context Free Grammar and a parser


[4 Marks]

ii. Demonstrate how a CFG can be parsed in a typical compile process. [4 Marks]

iii. Cubic time 0(n3) is generally considered too expensive for a parser. Explain what
can be done to reduce this time. [2 Marks]
cubi
e.

QUESTION FIVE [20 MARKS]

a) With the aid of examples, differentiate between syntax and semantic analysis as regards
compilers. [4 Marks]

b) Diagrammatically present the structure of a compiler and explain how each part works and
how they work together. [16 Marks]
----------------------------------------------------------------------------------------------------------------

Page 3 of 3

You might also like