c262f98t2 - CSc 262 Test 1 Friday 23 October 1998...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSc 262 Test 1 Friday 23 October 1998 >>>>>>>>>>>>>>>>>ANSWERS<<<<<<<<<<<<<<<<<<< 1. (15 pts) Suppose we have the program ONE below, which is written in some programming language, say ELBONIAN. PROGRAM ONE; INTEGER GLOBAL; INTEGER ARRAY LIST[1. .3]; PROCEDURE SUB(PARAM1:INTEGER; PARAM2:INTEGER); BEGIN PARAM1=6; PARAM2=PARAM2+1; GLOBAL=GLOBAL+1; PARAM1=5; END; BEGIN LIST[1]=1; LIST[2]=2; LIST[3]=3; GLOBAL=1; SUB(LIST[GLOBAL],GLOBAL); END. Fill out the following table, giving the values of GLOBAL and LIST after returning from the call to SUB, with the given method of passing the parameter. method of passing parameter GLOBAL LIST[1] LIST[2] LIST[3] ---------------------------------------------------------------- RESULT ? 5 2 3 VALUE 2 1 2 3 VALUE-RESULT 2 5 2 3 REFERENCE 3 5 2 3 NAME 3 6 2 5 ---------------------------------------------------------------- 2. (15 pts) In designing a language in which @ and # are binary operators, explain what rules you must consider in deciding how the compiler will evaluate the syntactically correct expression 4#2#3@(x#f(x))@4, where f(x) is a function call. We have to have a rule for determining the precedence of # versus @, i.e., whether one should be evaluated before the other. We have to have an associativity rule for #, i.e., whether a#b#c should be evaluated as (a#b)#c or a#(b#c), and an assoicativity rule for @. We have to have a rule for when the contents of parentheses, (), should be evaluated. We have to have a rule for which member of a the pair in the express a#b
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/09/2008 for the course CSC 262 taught by Professor Varies during the Spring '08 term at Lehigh University .

Page1 / 3

c262f98t2 - CSc 262 Test 1 Friday 23 October 1998...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online