0% found this document useful (0 votes)
71 views3 pages

Complier Construction Principles and Practice: Instructions

This document provides instructions for a closed book exam on compiler construction principles and practice. The exam consists of 5 parts testing knowledge of compilers, lexical analysis, finite automata, regular expressions, and translating deterministic finite automata to code. It directs students to write their name, answer all questions on the provided answer sheet, and complete the exam within the allotted time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views3 pages

Complier Construction Principles and Practice: Instructions

This document provides instructions for a closed book exam on compiler construction principles and practice. The exam consists of 5 parts testing knowledge of compilers, lexical analysis, finite automata, regular expressions, and translating deterministic finite automata to code. It directs students to write their name, answer all questions on the provided answer sheet, and complete the exam within the allotted time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Complier Construction Principles and Practice

Instructions:

This exam is closed book, closed notes. You may not refer to any books or other
materials during the exam.

Write your name and student number on your answer sheet if they are not already there.

Write your answers on the answer sheet.

You must complete the answer sheet in the time allowed.

Read the instructions for each part of the paper carefully.

Answer all the questions.

Part I Answer Questions (30 points, 5 points for each)

1. A computer program translates one language to another. A source program is written


in its source language while an equivalent program written in its target language.
What does "source language" usually refer to?

2. What's differences between an interpreter and a compiler?

3. What's major phases of a compiler?

4. Considering the following statement written by language C:

int aa = 0, bb = 1;

Please list all tokens.

5. What’s the meaning of the special meta-character ‘ε’ (epsilon) in basic regular
expressions?

6. What’s the purpose of regular expression in lexical analysis?

Part II True or False Choice (20 points, 2 points for each)

1. A compiler takes as its input a program written in its source language and produces
an equivalent program written in its target language
2. An interpreter is a language translator like a compiler. It differs from a compiler in
that it executes the source program immediately rather than generating object code.

3. Compiled object code is invariably faster than interpreted source code

4. The first phase of the compiler does the actual reading of the source program, which
is called syntax analysis.

5. If r and s are regular expressions, then r|s is a regular expression which matches
any string that is the concatenation of two strings.

6. The pattern for identifiers as commonly defined in programming languages is


defined by the regular expressions.

7. Finite automata is to describe the process of recognizing patterns in input strings.

8. The next state is uniquely given by the current state and the current input character
in nondeterministic finite automaton (NFA).

9. Considering a regular expression a* , it matches the strings a, aa, aaa, …. However,


it doesn’t match empty string ε.

10. To construct an equivalent DFA from a given arbitrary NFA, we need to eliminate
both ε-transitions and multiple transitions from a state on a single input character.

Part III Blank filling (15 points, 3 points for each)

1. is a program that can be used to determine execution errors in a


compiled program. It is also often packaged with a compiler in an IDE. It can also
halt execution at prespecified locations called breakpoints.

2. Programming language tokens tend to fall into several limited categories:

(1) , such as IF and THEN,

(2) Special symbols such as PLUS and MINUS,

(3) Other tokens: such as NUM and ID.

3. The task of the scanner is to read the source program as a file of characters and
dividing it up into , each of which is a sequence of characters that
represents a unit of information in the source program.

4. The set of L(ε) contains element(s).


5. The operation of a regular expression is written r*, where r is a regular
expression. The regular expression r* matches any finite concatenation of strings,
each of which matches r.

Part IV Lexical-Directed Translation (20 points, 5 points for each)

1. Write regular expressions for the following character sets.

(1) ∑={a, b}, all strings of lowercase letters that contain at least one a;

(2) ∑={0, 1}, all strings of the digits that begin and end in 0.

2. Consider the following regular expressions:

aa|bb

(aa|b)*

Use Thompson’s construction to convert the above regular expressions into NFAs;

Part V Programming (15 points)

Translate the following DFA into pseudocode using a doubly nested case statement
inside a loop, where the first case statement tests the current state and the nested second
level tests the input character.

a [other]
1 2 3
b

You might also like