Complier Construction Principles and Practice: Instructions
Complier Construction Principles and Practice: Instructions
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.
int aa = 0, bb = 1;
5. What’s the meaning of the special meta-character ‘ε’ (epsilon) in basic regular
expressions?
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.
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.
8. The next state is uniquely given by the current state and the current input character
in nondeterministic finite automaton (NFA).
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.
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.
(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.
aa|bb
(aa|b)*
Use Thompson’s construction to convert the above regular expressions into NFAs;
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