Sample Final Questions | Introduction to Programming Languages | COP 5555, Exams of Computer Science

Material Type: Exam; Professor: Bermudez; Class: PROGRAM LANGUAGE PRIN; Subject: COMPUTER PROGRAMMING; University: University of Florida; Term: Unknown 1989;

Typology: Exams

Pre 2010

Uploaded on 03/11/2009

koofers-user-egj
koofers-user-egj 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PROGRAMMING LANGUAGEPRINCIPLES
Instructor: Manuel Bermudez
SAMPLE FINAL QUESTIONS (denotational semantics, actually)
PROBLEM 1.
Add procedures to the denotational description of Tiny. Wewill consider proce-
dures with one parameter,and with no local variables, but the procedures are recursive.
Tw o newconstructs need to be handled: a procedure declaration, and a procedure call.
Complete the following:
CC[<proc I x C>] =
CC[<call I E>] =
Hint: Treat the procedure declaration as an asignment to the procedure name I.
PROBLEM 2.
Add the Algol ’for’ loop to the the denotational description of Tiny. The Algol ’for’
loop has the following syntax:
Statement -> ’for’ ’<identifier>’ ’:=’ List ’do’ Statement => ’for’
List -> IntExp list ’,
IntExp -> Expression ’..’Expression => ’..’
-> Expression
Forexample:
for i:= 0, 8, 9, 8..19, 7..3 do output(i)
Note: ranges are intended to count ’upwards’ only.Complete the following:
CC[<’for’ <id:x> IE1... IEnC>] =
Hint: Consider defining CC for a new’on-the-fly’ construct, that will process exactly one
IntExp, be it a single integer or a range of integers.
pf2

Partial preview of the text

Download Sample Final Questions | Introduction to Programming Languages | COP 5555 and more Exams Computer Science in PDF only on Docsity!

PROGRAMMING LANGUAGE PRINCIPLES

Instructor: Manuel Bermudez

SAMPLE FINAL QUESTIONS (denotational semantics, actually)

PROBLEM 1.

Add procedures to the denotational description of Tiny. We will consider proce- dures with one parameter, and with no local variables, but the procedures are recursive. Two new constructs need to be handled: a procedure declaration, and a procedure call.

Complete the following:

CC[] =

CC[] =

Hint: Treat the procedure declaration as an asignment to the procedure name I.

PROBLEM 2.

Add the Algol ’for’ loop to the the denotational description of Tiny. The Algol ’for’ loop has the following syntax:

Statement -> ’for’ ’’ ’:=’ List ’do’ Statement => ’for’ List -> IntExp list ’,’ IntExp -> Expression ’..’ Expression => ’..’ -> Expression

For example:

for i:= 0, 8, 9, 8..19, 7..3 do output(i)

Note: ranges are intended to count ’upwards’ only. Complete the following:

CC[<’for’ <id:x> IE 1 ... IEn C>] =

Hint: Consider defining CC for a new ’on-the-fly’ construct, that will process exactly one

IntExp, be it a single integer or a range of integers.

PROBLEM 3.

Let’s specify the semantics of a language of integer (no fractions) binary numbers.

Below is the AST grammar for binary numbers.

B → < ’bin’ E B > → ’0’ E → < ’cat’ E D > → D D → ’0’ → ’1’

Below is a sample AST, produced from the input string The numbers are 4+2=6, and 2+1=3.

bin ____/ __ /
cat bin / \ /
cat 0 cat ’0’ / \ /
1 1 cat 1 /
0 1

The following are the semantic domains:

Num = { 0, 1, 2,... } Output = Num * (tuples of numbers)

The following are the functionalities of the semantic functions:

EE: E → Num BB: B → Output → Output

Fill in the following lines to complete the denotational semantic description of the lan- guage. Hints: the meaning of a binary number tree X, such as the one above, is BB [X] nil. The cascade of "bin" nodes is intended for BB to take the current output, augment it with value of the current binary number, and pass the new output along to the next "bin" node. A cascade of "cat" nodes is intended for EE to calculate the value of the binary number, from left to right.

EE [’1’] = EE [’0’] = EE [< cat E D > ] = BB [< ’bin’ E B > ] = BB [’0’] =