Test 1 Summer 2014 Multiple Choice. Write your answer to the LEFT of each problem. 5 points each 1. Preprocessor macros are associated with: A. C B.

Similar documents
low and not larger than high. 18 points

The results for a few specific cases below are indicated. allequal ([1,1,1,1]) should return true allequal ([1,1,2,1]) should return false

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

NOTE: Answer ANY FOUR of the following 6 sections:

CSE 413 Midterm, May 6, 2011 Sample Solution Page 1 of 8

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

Introduction to Programming Using Java (98-388)

Functional Programming. Pure Functional Programming

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

CMSC 331 Final Exam Section 0201 December 18, 2000

CS 415 Midterm Exam Spring SOLUTION

CSE 3302 Notes 6: Data Types

Racket. CSE341: Programming Languages Lecture 14 Introduction to Racket. Getting started. Racket vs. Scheme. Example.

CS 415 Midterm Exam Fall 2003

CS 314 Principles of Programming Languages

Project 2: Scheme Interpreter

Functional Programming. Pure Functional Languages

Control in Sequential Languages

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

G Programming Languages - Fall 2012

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

CS 314 Principles of Programming Languages

FORM 2 (Please put your name and form # on the scantron!!!!)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Symbol Tables. ASU Textbook Chapter 7.6, 6.5 and 6.3. Tsan-sheng Hsu.

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT

UMBC CMSC 331 Final Exam

Chapter 7 Control I Expressions and Statements

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

Functional Programming. Pure Functional Languages

COP4020 Programming Assignment 1 - Spring 2011

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Final-Term Papers Solved MCQS with Reference

INSTITUTE OF AERONAUTICAL ENGINEERING

Introduction to Functional Programming

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

SOFTWARE ARCHITECTURE 6. LISP

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

CSE 5317 Midterm Examination 4 March Solutions

1 Lexical Considerations

COP4020 Programming Languages. Control Flow Prof. Robert van Engelen

CS 314 Principles of Programming Languages

Lecture 13: Complex Types and Garbage Collection

CSCE 531 Spring 2009 Final Exam

Recursive Functions of Symbolic Expressions and Their Computation by Machine Part I

Time : 1 Hour Max Marks : 30

UMBC CMSC 331 Final Exam

2. Reachability in garbage collection is just an approximation of garbage.

Flow of Control Execution Sequence

G Programming Languages - Fall 2012

Heap storage. Dynamic allocation and stacks are generally incompatible.

CMSC 331 Final Exam Section 0201 December 18, 2000

Concepts Introduced in Chapter 7

LECTURE 18. Control Flow

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

Compilers. 8. Run-time Support. Laszlo Böszörmenyi Compilers Run-time - 1

COP4020 Spring 2011 Midterm Exam

Functional Programming. Big Picture. Design of Programming Languages

Principles of Programming Languages

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page.

Chapter 8 :: Composite Types

CSE413 Midterm. Question Max Points Total 100

Today's Topics. CISC 458 Winter J.R. Cordy

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Organization of Programming Languages CS3200/5200N. Lecture 11

JVM ByteCode Interpreter

An Introduction to Scheme

Continuations provide a novel way to suspend and reexecute

Pierce Ch. 3, 8, 11, 15. Type Systems

G Programming Languages - Fall 2012

CPSC 3740 Programming Languages University of Lethbridge. Control Structures

C Programming SYLLABUS COVERAGE SYLLABUS IN DETAILS

Lecture 09: Data Abstraction ++ Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree.

regsim.scm ~/umb/cs450/ch5.base/ 1 11/11/13

Programming Language. MODEL Question paper and solution. 1 a) With diagrams, explain the compilation and interpretation. Compare the two.

Lexical Considerations

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

Parsing Scheme (+ (* 2 3) 1) * 1

Modern Programming Languages. Lecture LISP Programming Language An Introduction

CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.

Principles of Programming Languages [PLP-2015] Detailed Syllabus

Comp 311: Sample Midterm Examination

Lexical Considerations

More Scheme CS 331. Quiz. 4. What is the length of the list (()()()())? Which element does (car (cdr (x y z))) extract from the list?

Lectures Basics in Procedural Programming: Machinery

Topic IV. Block-structured procedural languages Algol and Pascal. References:

Functional Languages and Higher-Order Functions

MIDTERM EXAMINATION - CS130 - Spring 2005

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Lecture 15: Iteration and Recursion

Functional Programming - 2. Higher Order Functions

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Chapter 10 Implementing Subprograms

Equivalent Notations. Higher-Order Functions. (define (f x y) ( body )) = (define f (lambda (x y) ) ) Anonymous Functions.

Compiler Theory. (Semantic Analysis and Run-Time Environments)

Topic III. LISP : functions, recursion, and lists References: Chapter 3 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

Transcription:

CSE 3302 Test 1 1. Preprocessor macros are associated with: A. C B. Java C. JavaScript D. Pascal 2. (define x (lambda (y z) (+ y z))) is an example of: A. Applying an anonymous function B. Defining a function named x in Scheme C. Defining a function name lambda in JavaScript D. Renaming the library function + as x 3. Which language does not evaluate boolean expressions with short circuiting? A. Scheme B. JavaScript C. Pascal D. C 4. Having a pointer to a non-existent element one past the end of a table is part of which language s dynamic semantics? A. Java B. JavaScript C. Pascal D. C 5. Which of the following is not a JavaScript feature? A. first-class functions B. strong type checking C. event-driven execution D. integration with HTML 6. A call to this Scheme function will return: (define (func x) (cond ((pair? x) (cons (car x) (cdr x))) (else x))) A. a function named x B. the value of x C. the list x appended to itself D. if and only if x is a pair 7. Attribute grammars were invented by: A. Dijkstra B. Knuth C. McCarthy D. Slonneger 8. The Scheme cond is like what idiom in an imperative language? A. a chain of ifs B. a for loop C. switch D. a while loop 9. Which of the following is not true regarding attribute grammars? A. Synthesized attributes carry information up the parse tree B. Inherited attributes carry information down the parse tree C. They cannot represent context-sensitive information D. They can capture the information that usually goes in symbol tables 10. If a value is second class, then it can be A. Passed as an argument B. Returned from a function C. Assigned to a variable D. All of the above 1. Give Scheme code for a function (help i j) to construct a list with all integer values between i and j, inclusive. If i is larger than j, then the list will be empty. Error checking is not expected (15 points) > (help 0 5) '(0 1 2 3 4 5) > (help 11 14) '(11 12 13 14) > (help 100 100) '(100) > (help 200 100) '()

2 2. Give a Pascal procedure to place all integer values between i and j, inclusive, into a global array arr begining at subscript 0, so i will be stored at arr[0]. Error checking is not expected. 10 points arr: array[0..1000] of integer; procedure help(i,j: integer); 3. Give a JavaScript function to place all integer values between i and j, inclusive, into a global array arr begining at subscript 0, so i will be stored at arr[0]. Error checking is not expected. 10 points var arr=[]; function help(i,j) { 4. Draw the Scheme node structure for: (5 points) '(a (b (c d) (1 2 3) 4) (5 (6 (7 (8))))) 5. Compute the result of: (5 points) (car (cdr (cdr '(a (b (c d) (1 2 3) 4) (5 (6 (7 (8)))))))) 6. Compute the result of: (5 points) (cdr (car (cdr '(a (b (c d) (1 2 3) 4) (5 (6 (7 (8)))))))) CSE 3302 Test 2 1. In JavaScript, the result of [0,[1,2],"123",3].length will be: A. undefined B. 3 C. 4 D. 5 2. Which technique is applicable to garbage collection? A. binary search B. depth-first search C. dynamic programming D. shallow copying 3. The notion of l-value and r-value is associated with which PL construct? A. assignment B. iteration C. recursion D. selection 4. Many development organizations require the use of { and } when coding control structures in a C derivative language. This avoids which issue? A. dangling else B. subscripts out of range C. unmatched delimiters D. exceptions 5. Which type cannot be involved when ML attempts an equality comparison? A. list B. tuple C. int D. real 6. Suppose a variable is referenced in a subroutine closure. Where is it stored? A. static B. heap C. stack D. registers 7. Which language does not allow nesting functions? A. C B. Scheme C. JavaScript D. Pascal 8. For JavaScript, which expression always gives the same value as a && b? A.!(!a!b) B. a? b : a C. a? a : b D. b && a 9. Generational garbage collection is a generalization of: A. mark-and-sweep B. reference counts C. Schorr-Waite D. stop-and-copy 10. Which technique is not used in the PL/0 and Pascal-S environments? A. hand-coded scanner B. recursive-descent parsing C. shunting-yard processing D. stack-based interpreter 1. What appears on the console for the code below? (10 points) a={b: 5, c: 6 b=object.create(a); a.c=7; c=object.create(b); b.c=8; c.d=9; delete c.c;

3 delete b.c; console.log(c.b); console.log(c.c); console.log(c.d); 2. Suppose a Pascal array is to be stored starting at location 50000 and is declared: c: array[25..70,20..33] of integer; If one integer takes four bytes, what is the location of c[35,30]? (10 points) 3. Give equivalent C code (e.g. using if... else...) to demonstrate the short-circuit nature of C boolean operators. Do not use &&,, or! in your solution! Do not use work variables! Do not use return! (15 points) a. result = a < 10 b > 13; b. result = c < 20 && d > 17; c. result = d < 66 &&!(e < 25 f > 55); 4. What appears on the console for the code below? (15 points) var makecountergroup = function() { var counter=0; return { newsub: function (initval) { var subcounter=0; var funcs = { reset: function() { counter=counter-subcounter+initval; subcounter=initval; up: function(val) { subcounter+=val; counter+=val; down: function(val) { subcounter-=val; counter-=val; value: function() { return subcounter; } funcs.reset(); return funcs; value: function() { return counter; } var a=makecountergroup(); var b=makecountergroup(); var c=a.newsub(100); var d=a.newsub(200); var e=b.newsub(300); var f=b.newsub(400); c.up(50); f.down(50); e.reset(); console.log(a.value()); console.log(b.value()); console.log(c.value()); console.log(d.value()); console.log(e.value()); console.log(f.value());

CSE 3302 Test 3 1. For which of these languages is there a significant difference between for and while loops? A. C B. Java C. JavaScript D. Pascal 2. Keyword parameters give flexibility in: A. achieving overloading B. making call-by-name work effectively C. overriding the reserved words of a language D. the order in which parameters are passed 3. Beside a switch statement, Duff s device also involves which C construct? A. break B. continue C. goto D. loop 4. The cost of addressing a variable in PL/0 is linear in: A. level difference B. number of entries in the display C. scope level of the instruction D. scope level of the variable 5. (cons (cdr '(e (g f) (a b c))) (car (cdr '(h (i j k) l m)))) will result in: A. '((e (g f) (a b c)) i j k) B. '((i j k) e (g f) (a b c)) C. '(((g f) (a b c)) i j k) D. '((i j) e (g f) (a b c)) 6. (cdr (cdr (cdr (cdr '(a b (c d e) f (g h i)))))) will result in: A. '((g h i)) B. 'b C. '(c d e) D. '(g h i) 7. The for.. in construct is used to: A. enumerate array elements that are not undefined B. enumerate properties C. test a subclass/superclass relationship D. iterate over an integer subrange 8. Call-by-name is most similar to application of: A. #include B. macro C. r-value D. recursion 9. The state of a Scheme computation may be saved as: A. an anonymous function B. a continuation C. a fixed point D. a thread 10. PL/0 uses dynamic links to: A. Place an integer on the stack B. Reference data C. Update the display table D. Return from a called procedure 1. What is the result of executing this Scheme code? 10 points (define y 10) 4 ((lambda (x y) (x (x (x y y) y) y)) (lambda (x y) (+ x y)) 7) 2. A list has only integers as elements (i.e. no nested sub-lists, a lat ). Give Scheme code that returns the sum of these integers. (Line breaks, indenting, and comments are useful.) 20 points > (sum '()) 0 > (sum '(1 2 3 4)) 10 > (sum '(100)) 100 > (sum '(1000 200)) 1200

5 3. Two unordered lists have only atoms as elements (i.e. no nested sub-lists, a lat ). Give Scheme code to test whether the sets of atoms appearing in the two lists are the same. (Line breaks, indenting, and comments are useful.) 20 points > (lists=? '(1 a 4 5 2 3 "XXXX") '(5 1 "XXXX" a 4 2 3)) > (lists=? '() '()) > (lists=? '(a c e) '(a b c d e)) #f > (lists=? '(1 4 3 2 1 3 2) '(2 3 4 1 2)) > (lists=? '(1 3 2 1 3 2) '(2 3 4 2)) #f