






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Professor: Milanova; Class: PROGRAMMING LANGUAGES; Subject: Computer Science; University: Rensselaer Polytechnic Institute; Term: Unknown 1989;
Typology: Exams
1 / 10
This page cannot be seen from the preview
Don't miss anything!







1. Regular Expressions (30 points)
Consider the following regular expression which has been divided into three parts , 1,2,.
(x | y) (x | z) (w | z)+*
(5 points each) For each string below, either write that it is not generated by the regular expression (i.e., NOT GENERATED ) or circle and label the sections of each string generated by the regular expression parts 1,2,3. The following example shows what we mean.
x x x z w -------------1--------- --2-- --3โ
a) y x w z
b) y y y y y y z
c) x z w x
d) x x x x x x x w
e) x z x z z w
f) x z z z z z
2. Grammars, Ambiguity, Precedence (60 points) Below is a grammar with two operators:
a) (10 points) This grammar is ambiguous. Prove that the grammar is ambiguous.
b) (5 points) What is the precedence of unary - wrt +? (choose one)
**c) (10 points)**** Give evidence to support your answer to part b.
3. LL Parsing (60 points) Consider the following grammar over terminals {c,d,e}****. S is the starting symbol of the grammar.
a) **(30pts)**** Fill in the table below with the FIRST and FOLLOW sets for the nonterminals in this grammar:
FISRT FOLLOW S
b) **(20 points)**** Fill in the column headings and the row corresponding to A in the LL(1) parsing table for this grammar:
( [ ] ) $
c) (10 points) Is this grammar LL(1)? Explain briefly why or why not.
4. LR Parsing (60 Points)
Consider the following grammar:
| B + + // each plus is a separate token
Below is a partial DFA (CSFM) for the grammar above. Notice we did not have to add a new start state as we usually do with LR parsers.
a) (5 points) Complete state 0 by performing closure on the item listed.
b) (10 points) Fill in all elements of states 2, 4 and 7.
c) (10 points) Fill in the missing transition labels (7 of them).
5. Attribute Grammars (30 points)
Consider the following context-free grammar for floating-point constants, without exponential notation. Here C , digits, digit, and more_digits are nonterminals and 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and. are terminals.
| ฮต
Augment this grammar with attribute rules that will accumulate the value of the constant into a val attribute of the root of the parse tree. Your answer should be S-attributed.
6. Scoping (30 points) The interesting thing about this language is that procedures whose names are in upper - case use dynamic scoping to lookup non-local variables, whereas procedures whose names are in lower-case use static (also called lexical) scoping to lookup non-local variables. You will trace the execution of this program and answer the following 2 questions:
a) (20 points) ** What is the output of this program?
b) (10 points) Show the run-time stack when execution reaches /***/ using the frames at the right. You may not need to use all the frames.
main() { integer a, b, c := 0; // all initially 0 procedure P() { integer a := 1; print โ#1โ, a, b, c; a++; b++; if (b mod 2 = 0) then q(); else P(); print โ#2โ, a, b, c; }--end P;
procedure q() { integer b := 0; a++; b++; c++; print โ#3โ, a, b, c;/****/ }---end q
P(); print โ#4โ, a, b, c; }--end main
procedure ___main_____ lexical-link xxxx dynamic-link xxxx
procedure ________ lexical-link dynamic-link
procedure ________ lexical-link dynamic-link
procedure ________ lexical-link dynamic-link
procedure ________ lexical-link dynamic-link