Tiger Interpreter - Programming Languages and Compilers - Exams, Exams of Programming Languages

Main points of this exam paper are: Tiger Interpreter, Programming Language, Primitive Type, Type Float, Explicit Declaration, Index Variable, Lisp System, Excecution, Accessible Heap, Heap Cells

Typology: Exams

2012/2013

Uploaded on 04/02/2013

shailaja_987c
shailaja_987c 🇮🇳

4.3

(34)

217 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
UNIVERSITY OF CALIFORNIA
Department of Electrical Engineering
and Computer Sciences
Computer Science Division
Prof. R. Fateman
Fall, 2001
CS 164 Midterm 2: October 31, 2001, 9:00AM
Please read all instructions carefully.
There are 6 questions in the exam on 4 pages. Some questions have multiple parts.
You have 50 minutes to complete this test. The exam is closed book but you may refer
to your one page (2-sides) handwritten 8.5 by 11 inch paper.
Please write your answers in the space provided. You may use the backs of the exam
pages for scratch space. Solutions will be graded on correctness. Partial credit will be given.
Your family name
Your first name
Your LOGIN NAME PRINTED IN CAPITAL LETTERS CS164-
Underline the name of your Teaching Assistant: James Lee, Johnathon Jamison
READ AND SIGN THIS:
I certify that my answers to this exam are all my own work.
Signed:
question grade out of
1 20
2 10
3 20
4 5
5 5
6 10
total 70
1
pf3
pf4

Partial preview of the text

Download Tiger Interpreter - Programming Languages and Compilers - Exams and more Exams Programming Languages in PDF only on Docsity!

UNIVERSITY OF CALIFORNIA

Department of Electrical Engineering and Computer Sciences Computer Science Division

Prof. R. Fateman Fall, 2001

CS 164 Midterm 2: October 31, 2001, 9:00AM

Please read all instructions carefully. There are 6 questions in the exam on 4 pages. Some questions have multiple parts. You have 50 minutes to complete this test. The exam is closed book but you may refer to your one page (2-sides) handwritten 8.5 by 11 inch paper. Please write your answers in the space provided. You may use the backs of the exam pages for scratch space. Solutions will be graded on correctness. Partial credit will be given. Your family name Your first name Your LOGIN NAME PRINTED IN CAPITAL LETTERS CS164- Underline the name of your Teaching Assistant: James Lee, Johnathon Jamison READ AND SIGN THIS: I certify that my answers to this exam are all my own work.

Signed:

question grade out of 1 20 2 10 3 20 4 5 5 5 6 10 total 70

  1. [20 points] Consider the following grammar.

1 : S → E$ 2 : E → T 3 : E → E; T 4 : T → ε 5 : T → T a

Construct the LR(0) item sets for this grammar, point out the conflict that arises, and identify what type of conflict it is. Compute FOLLOW(S), FOLLOW(E), and FOLLOW(T ). Argue that since a /∈ FOLLOW(E), these conflicts can be resolved with 1 token of looka- head. Use the reverse of this page for your work.

  1. [10 points] Consider the following modifications to the Tiger programming language. For each proposed modification, identify the component(s) of the compiler that will need to be changed (select from the lexical analyzer (L), parser (P), type-checker (T), interpreter (I). Sometimes more than one may be appropriate. If so, write your answer here and explain on the reverse of this page.
    1. For a let statement, require that all variable declarations precede function declarations.
    2. Addition of the primitive type float.
    3. Allow C++/Java comment syntax: “//” followed by text until the end-of-line.
    4. Addition of a Pascal like repeat-until looping construct “repeat exp until exp”
    5. Requiring an explicit declaration of the for-loop index variable.
    6. Addition of a procedure sleep that takes one argument n, a integer. This procedure waits n seconds and then “returns” no value.
  2. [20 points] For each of the following Tiger programs, determine where the processing will detect an error. Mark the location L if it will fail in Lexical analysis.

Mark the location P if it will not Parse. Mark the location T if it will fail Type Checking. If there are no errors, write OK. Give some explanation as to why the failure occurs. If you are not sure what will happen explain that too. If you think there are several errors, such that if you correct the first one, there are still others, mention them all.

  1. [5 points] How does the tiger interpreter discussed in class deal with logical “and” and “or” expressions?
  2. [5 points] Explain what steps are necessary in the Tiger interpreter to interpret a call to function F.
  3. [10 points] A Lisp system with a mark and sweep garbage collector takes 3 microseconds (3 × 10 −^6 seconds) to mark a cons cell, and 4 microseconds to sweep each heap cell. The heap size is 10^6 cells. At time t during excecution of a program, the number of live, accessible heap cells is 0. million (although the system does not know this!). At time t the system is forced to do a garbage collection.

a. At time t, just before this GC, how many cells are on the free list?

b. Just after this GC, how many cells are on the free list?

c. Calculate how long the GC took (show work).

d. What is the cost (in seconds) per cell reclaimed?

e. What is the cost (in seconds) per cell reclaimed under the same circumstances if the heap contains 0.30 million cells?