CS 3360 Design and Implementation of Programming Languages. Exam 1

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

Programming Languages, Summary CSC419; Odelia Schwartz

MIDTERM EXAMINATION - CS130 - Spring 2005

Programming Languages Third Edition. Chapter 7 Basic Semantics

Chapter 5 Names, Binding, Type Checking and Scopes

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

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

Concepts of Programming Languages

MIDTERM EXAMINATION - CS130 - Spring 2003

Chapter 5. Names, Bindings, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 1. Preliminaries

CS 415 Midterm Exam Spring 2002

NOTE: Answer ANY FOUR of the following 6 sections:

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Principles of Programming Languages. Lecture Outline

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

Final-Term Papers Solved MCQS with Reference

Programming Languages 2nd edition Tucker and Noonan"

Introduction. Primitive Data Types: Integer. Primitive Data Types. ICOM 4036 Programming Languages

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

COS 140: Foundations of Computer Science

Chapter 1 Preliminaries

Full file at

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

CPSC 3740 Programming Languages University of Lethbridge. Data Types

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

CS 230 Programming Languages

INSTITUTE OF AERONAUTICAL ENGINEERING

CS 415 Midterm Exam Spring SOLUTION

CS143 Final Fall 2009

UNIT 3

COS 140: Foundations of Computer Science

Question Points Score

The PCAT Programming Language Reference Manual

CMSC 331 Final Exam Section 0201 December 18, 2000

Functional Programming. Pure Functional Programming

Data Types. Outline. In Text: Chapter 6. What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 5-1. Chapter 6: Data Types 2

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

6. Discuss how producer-consumer problem and Dining philosophers problem are solved using concurrency in ADA. [16]

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

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

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

Chapter 6. Data Types

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

1 Lexical Considerations

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.


Data Types In Text: Ch C apter 6 1

CS 314 Principles of Programming Languages

CS558 Programming Languages

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types

CS508-Modern Programming Solved MCQ(S) From Midterm Papers (1 TO 22 Lectures) BY Arslan

References and pointers

Concepts of Programming Languages

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

The SPL Programming Language Reference Manual

Outline. Programming Languages 1/16/18 PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY. Current

Grade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline

Chapter 1. Preliminaries

Programming Language Concepts, cs2104 Lecture 04 ( )

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Principles of Programming Languages COMP251: Syntax and Grammars

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

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

BNF, EBNF Regular Expressions. Programming Languages,

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

Chapter 6. Data Types ISBN

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

CS558 Programming Languages

Getting started with Java

Chapter 2 Working with Data Types and Operators

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

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

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

TYPES, VALUES AND DECLARATIONS

MIDTERM EXAM (Solutions)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CSCI Compiler Design

CS Exam #1-100 points Spring 2011

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

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

CS112 Lecture: Primitive Types, Operators, Strings

Lexical Considerations

Grammars & Parsing. Lecture 12 CS 2112 Fall 2018

Topic 1: Introduction

Computer Components. Software{ User Programs. Operating System. Hardware

Concepts Introduced in Chapter 7

Part (04) Introduction to Programming

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Informatica 3 Syntax and Semantics

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

Programming Languages Third Edition

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes,

A simple syntax-directed

Supplemental Materials: Grammars, Parsing, and Expressions. Topics. Grammars 10/11/2017. CS2: Data Structures and Algorithms Colorado State University

Transcription:

1 Spring 2016 (Monday, March 21) Name: CS 3360 Design and Implementation of Programming Languages Exam 1 This test has 18 questions and pages numbered 1 through 6. Reminders This test is closed-notes and closed-book. However, you are allowed to bring 1 page (8.5 X 11) of notes (both sides). Your notes must be 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. (4 points) There are many different criteria for evaluating programming languages, including readability, writability, reliability, overall cost, and so on. Among these, the most important criterion for judging a programming languages is. Justify your answer by stating the reason. 2. (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? (a) Fortran for scientific applications (b) COBOL for business applications (c) C for systems programming (d) Lisp for artificial intelligence (e) Java for scripting 3. (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 4. (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. 5. (2 points) Which of the following statements are incorrect about PHP strings? (a) A string can be expressed by enclosing it in a pair of single or double quotes, e.g., Hello and Hello. (b) There is no semantic difference between the use of single and double quotes in expressing a string. (c) A special character can be contained in a string by preceding it with a escape character. (d) Two strings can be concatenated using the dot (.) operator. 6. (2 points) The address of a variable (l-value) is the machine memory address with which it is associated. Which of the followings is an incorrect statement about the address of a variable? (a) A variable may have different addresses at different times during execution. (b) The same name my have different addresses at different places in a program. (c) If two variable names can be used to access the same memory location, they are called aliases. (d) Aliases are harmful to program efficiency. 7. (2 points) Which storage binding scheme is described below? Storage bindings are created for variables when their declaration statements are elaborated. It allows recursion and conserves storage, however, it incurs overhead of allocation and deallocation and doesn t support history sensitive variables for subprograms. (a) Static (b) Stack-dynamic (c) Explicit heap-dynamic (d) Implicit heap-dynamic 8. (2 points) There are several design choices regarding the length of string values, and Java uses: (a) Static length (b) Limited dynamic length (c) Dynamic length. (d) All of above 9. (2 points) A(n) type is one in which the range of possible values can be easily associated with the set of positive values. Examples in Java include integers, characters, and booleans. 10. (5 points) The major methods of implementing programming languages are compilation, pure interpretation, and hybrid implementation. Which method does Java use and why?

3 11. (10 points) Define what binding is, state the difference between static binding and dynamic binding, and give an example of each in terms of binding of variable attributes in Java. 12. (15 points) This question is about the ambiguity of a grammar. (a) When a grammar is said to be ambiguous? (b) Prove or disprove the ambiguity of the following grammar. <E> -> <E> + <E> 5 (c) Rewrite the above grammar to make the + operator right associative.

4 13. (10 points) Write a BNF grammar for the language of palindromes. Example sentences are aba, pop, and a man a plan a canal panama. You may assume that a non-terminal <letter> is already defined. 14. (10 points) The BNF grammar below defines an identifier that has the form: a letter followed by a string consisting of letters and digits. Define an attribute grammar to impose a length limitation, say up to 32 characters, in the identifier. <ident> -> <letter> <ident> -> <letter> <letter-or-digits> <letter-or-digits> -> <letter> <letter-or-digits> <letter-or-digits> -> <digit> <letter-or-digits> <letter-or-digits> -> <letter> <letter-or-digits> -> <digit>

5 15. (5 points) There are five different subscript and storage bindings possible for arrays. Name and explain the approach used by Java. 16. (5 points) Suppose a programming language L that supports multi-dimensional arrays. Your program written in L contains a two dimensional array, say A[50,100]; each element of the array requires 4 bytes of memory. You learned that A[0,0] and A[2,10] are stored at memory addresses 1000 and 1840, respectively, on a byte-addressable machine. Determine the memory address where A[30,50] is stored. 17. (5 points) In PHP, any value is either true or false. List all false values.

6 18. (15 points) Write a PHP function named diff that takes two arrays, say a and b, and returns a new array. The result array should contain only those elements of a that are not present in b. See sample outputs below. Do not use any standard array manipulation functions such as array diff. diff(array(1,2), array(1,3)) ===> array(2) diff(array(1,1,2), array(2)) ===> array(1,1) diff(array(1), array("1")) ===> array(1) diff(array("a"), array("a")) ===> array()