Docsity

Compiler Construction Computer Science - Exam 1 | COP 5621, Exams of Computer Science

Toggle sidebar
bg1
COP5621 Exam 1 - Spring 2005
Name: (Please print)
Put the answers on these sheets. Use additional sheets when necessary. Show how you derived your answer
when applicable (this is required for full credit and helpful for partial credit). You can collect 100 points in
total for this exam. A bonus question for an additional 15 points is included. If the total number of points
for this exam exceed 100, the excess points are carried over to the next exams.
1. Match the terms below with the given sentences so as to best complete each sentence. Use no term
more than once. Some terms will go unused. (10 points)
(1) preprocessor (9) lexeme
(2) attribute (10) lexical analysis
(3) back end (11) syntax analysis
(4) front end (12) token
(5) nonterminal (13) terminal
(6) NFA (14) DFA
(7) regular expressions (15) grammar
(8) regular definitions (16) translation rules
(a) The of a compiler produces intermediate code.
(b) Syntax errors are detected in the phase of a compiler.
(c) In a typical compiler, the of a token of an identifier is a pointer to the identifier’s
symbol table entry containing a pointer to the of the identifier.
(d) The time complexity of lexical analysis using a representation of lexical pat-
terns is linear in the size of the input.
(e) A lex/flex specification consists of three parts. The second part defines .
2. The textbook claims that “The analysis part of a compiler breaks up the source program into pieces
and creates an intermediate representation.” What are the three different analysis phases performed
by a compiler? (5 points)
1
pf3
pf4
pf5

Partial preview of the text

Download Compiler Construction Computer Science - Exam 1 | COP 5621 and more Exams Computer Science in PDF only on Docsity!

COP5621 Exam 1 - Spring 2005

Name: (Please print) Put the answers on these sheets. Use additional sheets when necessary. Show how you derived your answer when applicable (this is required for full credit and helpful for partial credit). You can collect 100 points in total for this exam. A bonus question for an additional 15 points is included. If the total number of points for this exam exceed 100, the excess points are carried over to the next exams.

  1. Match the terms below with the given sentences so as to best complete each sentence. Use no term more than once. Some terms will go unused. (10 points)

(1) preprocessor (9) lexeme (2) attribute (10) lexical analysis (3) back end (11) syntax analysis (4) front end (12) token (5) nonterminal (13) terminal (6) NFA (14) DFA (7) regular expressions (15) grammar (8) regular definitions (16) translation rules

(a) The of a compiler produces intermediate code. (b) Syntax errors are detected in the phase of a compiler. (c) In a typical compiler, the of a token of an identifier is a pointer to the identifier’s symbol table entry containing a pointer to the of the identifier. (d) The time complexity of lexical analysis using a representation of lexical pat- terns is linear in the size of the input. (e) A lex/flex specification consists of three parts. The second part defines.

  1. The textbook claims that “The analysis part of a compiler breaks up the source program into pieces and creates an intermediate representation.” What are the three different analysis phases performed by a compiler? (5 points)
  1. What are the contents of a method frame in the JVM? (5 points)
  2. Write a regular expression defining the representation of a signed decimal fraction consisting of an optional sign, a non-empty sequence of digits, followed by an optional decimal period and a non- empty sequence of digits. (5 points)
  3. List the five operations on languages and give their set-based definitions. (10 points)
  1. Given the NFA with S = { 1 , 2 , 3 , 4 , 5 }, Σ = {a, b}, s 0 = 1, F = { 5 } and the transition graph portrayed below

1 5

2

3

4 a

b

ε

ε

ε

b

convert the NFA to a DFA using the subset construction algorithm (do not attempt to minimize the DFA). Express your answer as a transition graph and identify the start and final states. (15 points)

  1. Consider the following state transition table of a DFA with S = { 0 , 1 , 2 , 3 , 4 }, Σ = {a, b}, s 0 = 0 , F = { 3 , 4 }.

State Input a b 0 1 2 1 3 4 2 1 2 3 4 - 4 3 -

(a) Draw the transition graph. (5 points) (b) Minimize the DFA using the algorithm in the book and illustrated in class. Identify the start and final states of the minimized DFA. (15 points) (c) Write an equivalent regular expression that represents the same language as defined by the (min- imized) DFA. (10 points)