Final Exam for Programming Languages | CSCI 4430, Exams of Programming Languages

Material Type: Exam; Professor: Milanova; Class: PROGRAMMING LANGUAGES; Subject: Computer Science; University: Rensselaer Polytechnic Institute; Term: Fall 2008;

Typology: Exams

Pre 2010

Uploaded on 08/09/2009

koofers-user-7m4
koofers-user-7m4 🇺🇸

10 documents

1 / 32

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
NAME
Final
Exam
CSCI
4430
Programming
Languages
December11,
2008
DO
NOT
OPEN
THIS
EXAM
UNTIL
TOLD
TO
DO
SO!
READ
THROUGH
THE
ENTIRE
EXAM
BEFORE
STARTING
TO
WORK.
YOU
ARE ALLOWED
10
“CHEAT”
SHEETS
ONLY.
This
exam
is
worth
380
points.
Make
sure
you
have
15
pages
counting this
one;
there
are
10
questions.
If
you
need
more
room
for an
answer
than
is
provided,
please use
the
back
of
the
page
and
indicate
that
you
have
done
so.
If
you
re-do
a
question,
please
make
clear
what
is
your
final
answer.
Read
through each
entire
question
before
starting
to
answer
it.
Starred
**
questions
may
take
longer
to
answer/think
through,
so
please
budget
your
time
appropriately.
Be
clear
and
brief
in
your
explanations
(when
the
answer
is
text,
write
at
most
2-3
sentences).
The following
is
for
the
use
of
graders
1.
120
2.
130
3.
130
4.
/45
5.
145
6.
140
/60
8.
140
9.
130
10.
140
TOTAL
POINTS:
/380
CSZI
4430
Final
Exam
I
Fall
2008
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20

Partial preview of the text

Download Final Exam for Programming Languages | CSCI 4430 and more Exams Programming Languages in PDF only on Docsity!

NAME

Final

Exam

CSCI

Programming

Languages

December11,

(^2008)

DO

NOT

OPEN

THIS^

EXAM

UNTIL

TOLD

TO

DO

SO!

READ

THROUGH

THE^

ENTIRE

EXAM

BEFORE

STARTING

TO

WORK.^

YOU

ARE ALLOWED

“CHEAT”^

SHEETS

ONLY.

This

exam

is

worth

points.

Make

sure

you

have

pages

counting this

one;^

there

are

questions.

If

you^

need

more

room

for an

answer

than

is

provided,

please use

the

back

of^

the

page

and

indicate

that

you

have

done

so.

If

you

re-do

a^

question,

please

make

clear

what^

is

your

final

Readanswer.

through each

entire

question

before

starting

to

answer

it.

Starred

**

questions

may

take

longer

to

answer/think

through,^

so

please

budget

your

time

appropriately.^

Be

clear

and

brief

in

your

explanations

(when

the^

answer

(^) is

text,

write

at

most

The followingsentences).

is^

for

the

use^

of

graders

TOTAL

POINTS:

CSZI

(^) Final

Exam

I

Fall

(^2008)

2. LLNAME_____________________

Parsing

(3Opoints)

Consider the

following

grammar

over terminals

(,jj,

and

S

is the starting

(^) symbol

of the

grammar.

S

TS

ISIS

I

X-iT-(X)

TX!

IXJXI

a)

( 5pts)**

Fill in

the (^) table

below

with

the

FIRST

and

FOLLOW

sets

for the

nonterminals

in this

grammar:

FISRT

FOLLOW

S

C (L

(l

)

cL’

—___

b)

( (^) points)**

Fill in the

LL(1)

parsing

(^) table

below:

H

x TT S

c)

( points

Is this

grammar

LL(1)?

(^) Explain

(^) briefly

(^) why

(^) or (^) why

not

1 L r

c’

ck

d

e

CSCI

(^4430)

Final

(^) Exam

Fall

(^008)

3. NAME_____________________

LR

Parsing

points)

Consider

the

foowing

grammar

over

terminals

+,

if

and

int:

E

—intI

E

if E E

E

a (

pts) (^) This

grammar

is ambiguous.

Show

two

parse trees

for

mt

mt

if

mt

E

EE

/

I

FLr

..J

b) (

pts)

Consider

(^) the

partial

DFA

(i.e.

CFSM)

for this

grammar:

Complete

state

by performing

(^) closure

on the

item

(^) listed.

Fill in the

elements

of states

and

Fill (^) in the missing labels

(^) of them).

Fill in the (^) “reduce

by

labels

on states

and

6 below:

Label on

state

“reduce

by E

, E

Eon


Label

(^) at (^) state

“reduce

by (^) E

E

if Eon


CSCI 4430

(^) Final

(^) Exam

Fall

(^2008)

5. NAME______________________

Parameter

Passing

points)

a) (2Opts’

What

does

the program

below

print,

assuming

that

each argument/parameter

is passed

according

to the qualifier

on it, Assume

in by value-result

that

all parameter

addresses

are

calculated

only ON

ENTRY

to the

procedure.

Note:

print

a[O..3]

means

print

a[O],a[1],a[2],a[3J

{

mt

a[4);

mt

h,

k,

j;

function

p(int

x

: by

reference,

mt

y

: by

name,

mt

z : by

value-result)

{ j :=

4;

x

x*2;

z :=

x*3;

printa[y]

“in

p “,

h,

j,

k,

a[O..3];

initialize

aErn]

to

(3-rn)

a[O]

a[lJ=2;

a[2]=l;

a[3]=O;

h :=

1;

j :=

2;

:=

print

“before

“,

h,

j,

k,

a[O..3];

call

p(a[j],

(j-l),

a[h));

(***)

print

“after

“,

h,

j,

k,

a[O..3);

Output:

0

CSCI

Final

(^) Exam

Fall

(^2008)

b) NAME______________________ (^) (5pts

How

(^) would

(^) you

(^) change

(^) the

(^) call

(^) to (^) p (^) at (^) (***)

so^ (^) that

(^) after

(^) returning

(^) from

(^) that

call.^ (^) a[2] would

(^) have

(^) been

modified

to^ (^6)

call

p(

(D

tL.):

c)

(^) (2Opts)

(^) Complete

(^) the

(^) following

(^) program fragment

(^) in (^) the

(^) shortest

(^) possible

(^) way

(^) (fewest

(^) and

shortest^

statements)

(^) so (^) that

(^) the

(^) output

(^) will

be^ (^) different

(^) if (^) parameter

passing^

(^) was

(^) by (^) reference

(^) versus

(^) by (^) value-

result.

Indicate

(^) in (^) each

(^) case

(^) what

(^) the (^) output

(^) would be.

procedure

p(integer

x)

{

(A

),

main

()^

{

/*

begin

main

program

integer

A

= 10,

B

= 20;

p (^) (A);

print

(“A=”

(^) , (^) A, (^) “B=”

(^) , B) ;^

A3ci,

iC

Output

n case

(^) of (^) pass

(^) by-reference:

A

ii

(^) Output

(^) in (^) case

(^) of (^) pass by-value-result:


b

2t

AG)

E:O

(SC!

(^) 443()

(Ama!

Exam^

Fall

(^) OO

7. NAME_____________________

Comparative

Programming

Languages

points,

each)

Assume

(^) you

(^) have

(^) a (^) symbol

(^) table

(^) whose

(^) keys

(^) are

(^) variable

(^) names

(^) and

(^) whose

(^) entries

(^) are

(^) symbolic

(^) values

that (^) correspond

(^) to (^) the

(^) type

(^) of (^) that

(^) variable,

(^) In (^) our

(^) Scheme

(^) project and

(^) Python

(^) examples

(^) we (^) have

(^) seen

(^) how

to (^) search

(^) such

(^) a (^) table

(^) to (^) find

(^) the

(^) value

(^) corresponding

(^) to (^) a given

(^) key.

Here,

(^) we (^) want

(^) to (^) do (^) the

(^) opposite,

namely

(^) we (^) want

(^) a (^) function

(^) get

vars

(^) that

finds

all (^) the

(^) variables

n the (^) table

(^) of (^) a (^) given

(^) type

(^) (i.e.

value).

For (^) example,

in

Scheme

(^) we

(^) would

(^) store

(^) the table

(^) as (^) a (^) list

((x

int)

(y

real)

(z

list)

(w

int))

Here

(^) the (^) first

(^) element

(^) of (^) each

(^) sublist

(^) is (^) the

(^) key

(^) (the

(^) variable) and the

(^) second

(^) element

(^) is (^) the (^) value

(^) (or

variable

(^) type).

The

(^) call

(get

vars

‘mt

‘(Cx

int)

(y

real)

(z

list)

(w

int)))will

(^) return

the (^) list

(x

w)

Recall

(^) several

(^) higher

(^) order

(^) functions

(^) in (^) Scheme

(^) that

(^) may

(^) be (^) useful:

(define

(foldl

g ys

u)

(if

(null?

ys)

u (foldi

g (cdr

ys)

(g

u (car

ys)))))

(define

(foldr

op

ys

val)

(if

(null?

ys)

val

(op

(car

ys)

(foldr

op

(cdr

ys)

val))))

(define

(map

f ys)

(if

(null?

ys)

I

(cons

(f

(car

ys))

(map

f (cdr

ys)))))

a. Wrte

(^) a Scheme

(^) function

(^) get

vars

(^) for (^) finding

(^) all (^) the

(^) variables

(^) of (^) a (^) given

(^) type,

(define

(get

vars

type

ilist)


(y

j)

9CL’

CiX

])

(CiS

.ai

ri)

I

)^

CSCJ

(^) f:jia

Exam^

FaIl

(^2008)

b. NAME_____________________

Now

write

a^

Python

(^) function

to accomplish

the

same

task,

Note:

the

following

built-in

operations

in

Python

on dictionaries

may

be of use:

keys

,

values

,

has

key

()

update

(dict)

, len

(dict)

, indexing

or the following

builtin

(^) operations

on Python

lists:

(concatenate),

append(ele),

del

list[k]

(element

deletion),

indexing

[.

I

Function

returns

list of variables

in

dict

of type

type.

def

get

vars

(type,

dict)


k/Lrt4 ( vcrS

CSCl 4430

Final

Exam

Fail