CS 3360 Design and Implementation of Programming Languages. Exam 1

Similar documents
CS 3360 Design and Implementation of Programming Languages. Exam 1

MIDTERM EXAMINATION - CS130 - Spring 2005

Programming Languages, Summary CSC419; Odelia Schwartz

MIDTERM EXAMINATION - CS130 - Spring 2003

Principles of Programming Languages. Lecture Outline

Concepts of Programming Languages

Programming Languages 2nd edition Tucker and Noonan"

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

The PCAT Programming Language Reference Manual

Syntax. A. Bellaachia Page: 1

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

1 Lexical Considerations

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

1. Consider the following program in a PCAT-like language.

Programming Languages Third Edition. Chapter 7 Basic Semantics

CS 415 Midterm Exam Spring 2002

NOTE: Answer ANY FOUR of the following 6 sections:

Full file at

Lexical Considerations

Programming Languages Third Edition

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF)

The SPL Programming Language Reference Manual

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

CS 415 Midterm Exam Spring SOLUTION

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

COS 140: Foundations of Computer Science

BNF, EBNF Regular Expressions. Programming Languages,

CS558 Programming Languages

Chapter 1. Preliminaries

Scheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.

Scheme: Expressions & Procedures

CPS 506 Comparative Programming Languages. Syntax Specification

Type Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413

CSCI 3155: Principles of Programming Languages Exam preparation #1 2007

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS

Chapter 5 Names, Binding, Type Checking and Scopes

Introduction to Programming Using Java (98-388)

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lexical Considerations

COMPUTER APPLICATION

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413

Functional Programming. Pure Functional Programming

CS558 Programming Languages

(Not Quite) Minijava

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

The syntax and semantics of Beginning Student

The syntax and semantics of Beginning Student

G Programming Languages - Fall 2012

Array. Prepared By - Rifat Shahriyar

INSTITUTE OF AERONAUTICAL ENGINEERING

Chapter 3 (part 3) Describing Syntax and Semantics

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

MIDTERM EXAM (Solutions)

Lecture 12: Conditional Expressions and Local Binding

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

COS 140: Foundations of Computer Science


Midterm 1. CMSC 430 Introduction to Compilers Spring Instructions Total 100. Name: March 14, 2012

Question Points Score

Semantic Analysis. Lecture 9. February 7, 2018

CS Exam #1-100 points Spring 2011

CS 314 Principles of Programming Languages

Data Types. Data Types. Introduction. Data Types. Data Types. Data Types. Introduction

Final-Term Papers Solved MCQS with Reference

Defining Program Syntax. Chapter Two Modern Programming Languages, 2nd ed. 1

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

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

Curriculum Map Grade(s): Subject: AP Computer Science

Chapter 3. Describing Syntax and Semantics

Spring 2018 PhD Qualifying Exam in Languages

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

Functional Programming. Pure Functional Languages

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

Syntax/semantics. Program <> program execution Compiler/interpreter Syntax Grammars Syntax diagrams Automata/State Machines Scanning/Parsing

CS 4330/5390: Mobile Application Development Exam 1

Functional Programming. Pure Functional Languages

Final Exam. COMP Summer I June 26, points

Lecture Chapter 6 Recursion as a Problem Solving Technique

CS101 Introduction to Programming Languages and Compilers

COMP 524 Spring 2018 Midterm Thursday, March 1

Chapter 6 part 1. Data Types. (updated based on 11th edition) ISBN

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

Final Exam CS 152, Computer Programming Fundamentals December 5, 2014

This book is licensed under a Creative Commons Attribution 3.0 License

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

Principles of Programming Languages COMP251: Syntax and Grammars

Final Exam CS 152, Computer Programming Fundamentals December 9, 2016

Michele Van Dyne Museum 204B CSCI 136: Fundamentals of Computer Science II, Spring

Types. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus

CS3360 Design and Implementation of Programming Languages Final Exam May 16, pm to 12:45pm (2 hour and 40 minutes) NAME:

The Warhol Language Reference Manual

OF VICTORIA EXAMINATIONS- DECEMBER 2010 CSC

EZ- ASCII: Language Reference Manual

COSC252: Programming Languages: Semantic Specification. Jeremy Bolton, PhD Adjunct Professor

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

Transcription:

1 Spring 2017 (Thursday, March 9) Name: CS 3360 Design and Implementation of Programming Languages Exam 1 This test has 8 questions and pages numbered 1 through 7. Reminders This test is closed-notes and closed-book. However, you are allowed to bring 1 page (8.5 11 ) of notes (both sides). Your notes must be of your own, they must be hand written, and they must be turned in with your test. This test is to be done individually, and you are not to exchange or share materials with other students during the test. If you need more space, use the back of a page. Note when you do that on the front. This test is timed. Your test will not be graded if you try to take more than the time allowed. Therefore, before you begin, please take a moment to look over the entire test so that you can budget your time. Clarity is important; if your writing or code is sloppy or hard to read, you will lose points. Correct syntax also makes some difference. There are 100 points all. 1. (total 20 points) Short answers: multiple choice and fill-in-the-blank. (a) (4 points) There are many different criteria for evaluating programming languages, including readability, writability, reliability, cost, and so on. Among these, the most important criterion for judging a programming languages is. Justify your answer by stating the reason. (b) (2 points) The design and evaluation of a programming language is highly dependent on the domain in which it is to be used. Which of the followings is an incorrect association between a programming language and its application area? i. Fortran for scientific applications ii. COBOL for business applications iii. C for systems programming iv. Lisp for artificial intelligence v. Java for scripting (c) (2 points) A language is said to be if it has a relatively small set of primitive constructs that can be combined in a relatively small number of ways to build the control and data structures of the language. Such a language is easy to learn and read because every possible combination is legal without an exception and the meaning is context independent.

2 (d) (2 points) The major methods of implementing programming languages are compilation, interpretation, and hybrid implementation. Java uses. (e) (2 points) An attribute grammar is a BNF with three additions: attributes, attribute computation functions, and predicate functions. Among the three additions, the role of is to state the semantic rules or constraints of a grammar rule. (f) (2 points) The address of a variable (l-value) is the machine memory address with which it is associated. Which of the following statements is incorrect about the address of a variable? i. A variable may have different addresses at different times during execution. ii. The same name may have different addresses at different places in a program. iii. If two variable names can be used to access the same memory location, they are called aliases. iv. Aliases are harmful to program efficiency. (g) (2 points) PHP supports several different types of values including Booleans, integers, floatingpoint numbers, strings, objects, and resources. All these PHP values are either true or false value. i. True ii. False (h) (2 points) Which of the following statements are incorrect about PHP strings? i. A string can be expressed by enclosing it in a pair of single or double quotes, e.g., Hello and Hello. ii. There is no semantic difference between the use of single and double quotes in expressing a string. iii. A special character can be contained in a string by preceding it with a escape character. iv. Two strings can be concatenated using the dot (.) operator. (i) (2 points) There are five different subscript and storage bindings possible for arrays. Java uses. 2. (6 points) State the difference between static binding and dynamic binding, and give an example of each in terms of bindings of variable attributes occurring in the following Java local variable declaration. if () { int x = 10;.

3 3. (6 points) This question is about the ambiguity of a grammar. When a grammar is said to be ambiguous? I.e., give the definition of the ambiguity of a grammar. Prove or disprove the ambiguity of the following grammar. <assign-expr> -> <assign-expr> = <assign-expr> 4. (10 points) Write a BNF grammar for the language recursively defined as follows. A symbol a is in the language. For any two sentences x and y in the language, x << y is also in the language. For any two sentences x and y in the language, x & y is also in the language. Nothing else is in the language. Both operators (<< and &) are left associative. The operator << has precedence over the operator &. Example sentences of the language include a, a << a, a & a, a << a & a, etc.

4 5. (8 points) There can be different PHP variables and values depending on their scopes and lifetimes, including the following. For each, state the storage binding scheme used; if needed, justify your answer by stating the reason. Local variables Formal parameters Global variables Static local variables Objects (fields) Arrays 6. (10 points) Suppose a programming language PL m that supports multi-dimensional arrays. Your program written in PL m contains a two-dimensional array, say A[100, 50] (100 rows 50 columns). You learned that (i) each element of the array requires 4 bytes of memory, and (ii) A[0, 0] and A[10, 1] are stored at memory addresses 1000 and 1440, respectively, on a byte-addressable machine. (a) Does PL m use row major order or column major order? (b) Write a formula that, given valid indices i and j, gives the memory address where A[i, j] is stored. (c) Calculate the memory address where A[3, 5] is stored? 7. (10 points) PHP provides two different equality operators, == and ===. (a) Describe the two operators by showing examples to highlight the difference. (b) Relate the two equality operators to different kinds of assignments for objects (=, &=, clone). E.g., what re the impacts of the different assignments on the equalities of objects?

5 8. (total 30 points) Consider the Battleship web service that you wrote as part of your PHP assignment. A Battleship board consists of n n places, and each place of a board is uniquely identified by a pair of 1-based column and row indices. A set of ships can be placed in a board. Below you are to implement a couple of features of the Battleship game by writing partial code for three classes: Place, Ship, and Board. (a) (5 points) Write a constructor for the Place class given below. Given 1-based column and row indices ($x and $y), the constructor initializes the newly created instance. Provide reasonable (default) values for all the fields. class Place { var $x; // 1 based column index of this place var $y; // 1 based row index of this place var $ship; // null or occupant of this place var $ishit; // true if this place is hit function ishit() { // return true if this place is hit. (b) (5 points) A ship can be placed on a consecutive sequence of places in a board, either horizontally or vertically. A ship placed on a board becomes sunk if all its places are hit. Write the issunk() function of the Ship class given below. class Ship { var $places; // array of the places this ship is placed on function issunk() { // is this ship sunk?

6 (c) (15 points) A board consists of n n places, where n is the size (dimension) of the board. A board also knows all the ships placed on it. Write the following three functions of the Board class (see the skeletal code below). A constructor that takes an optional board size ($size) and initializes a newly created board instance. If the optional board size is missing, the constructor creates a board of size 10; e.g., new Board() creates a board of size 10. The getplace() function returning the place of the given 1-based column and row indices ($x and $y) or null if no such place exists. The isgameover() function returning true if the game is over, i.e., all the ships placed on the board are sunk. class Board { var $size; // dimension of this board var $places; // 1 dimensional array containing all the places of this board var $ships; // array of ships placed in this board function getplace($x, $y) { function isgameover() {

7 (d) (5 points) Explain the function places() defined in the Board class below. What value will be returned by the calls places(1) and places(2), respectively, and why? class Board { var $places; // array of places function places($delta) { $i = 0; while ($i < sizeof($this >places)) { yield $this >places[$i]; $i += $delta;