MIDTERM EXAMINATION. CSE 130: Principles of Programming Languages. Professor Goguen. February 16, points total

Similar documents
MIDTERM EXAMINATION - CS130 - Spring 2003

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

Contents. Chapter 1 SPECIFYING SYNTAX 1

MIDTERM EXAM (Solutions)

LECTURE 17. Expressions and Assignment

Control Flow February 9, Lecture 7

More Assigned Reading and Exercises on Syntax (for Exam 2)

G Programming Languages - Fall 2012

CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm

CS 415 Midterm Exam Fall 2003

CS 242. Fundamentals. Reading: See last slide

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Seminar in Programming Languages

Programming Languages Third Edition

CS 314 Principles of Programming Languages

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

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

MIDTERM EXAMINATION - CS130 - Spring 2005

Chapter 3. Describing Syntax and Semantics

Lecture 13: Expression Evaluation

Compiler Design Aug 1996

Functional Programming Lecture 1: Introduction

Final Examination CSE 100 UCSD (Practice)

CSE 401 Midterm Exam 11/5/10

Chapter 3. Syntax - the form or structure of the expressions, statements, and program units

CS 415 Midterm Exam Spring SOLUTION

Draw a diagram of an empty circular queue and describe it to the reader.

Syntax. A. Bellaachia Page: 1

Midterm I - Solution CS164, Spring 2014

Examples of attributes: values of evaluated subtrees, type information, source file coordinates,

Earlier edition Dragon book has been revised. Course Outline Contact Room 124, tel , rvvliet(at)liacs(dot)nl

Chapter 3. Describing Syntax and Semantics ISBN

Chapter 3. Describing Syntax and Semantics

CS 415 Midterm Exam Spring 2002

This book is licensed under a Creative Commons Attribution 3.0 License

1 A question of semantics

CSc 520 Principles of Programming Languages. 26 : Control Structures Introduction

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

Homework. Lecture 7: Parsers & Lambda Calculus. Rewrite Grammar. Problems

Chapter 11 :: Functional Languages

CMSC 330, Fall 2018 Midterm 2

SECOND PUBLIC EXAMINATION. Compilers

Programming Language Pragmatics

Imperative Paradigm. Syntax. Role of Programming Languages. Expressions. Expressions. Role of Programming Languages. Symbols.

7. Introduction to Denotational Semantics. Oscar Nierstrasz

Com S 541. Programming Languages I

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

EXAMINATIONS 2009 END-OF-YEAR. COMP 202 / SWEN 202 Formal Methods of Computer Science / Formal Foundations of Software Engineering

Programmiersprachen (Programming Languages)

Midterm I (Solutions) CS164, Spring 2002

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

CSCC24 Functional Programming Scheme Part 2

UNIT 3

CSE 582 Autumn 2002 Exam 11/26/02

Lecture 10: Expression Evaluation

Comp 311: Sample Midterm Examination

2.2 Syntax Definition

Semantic Analysis computes additional information related to the meaning of the program once the syntactic structure is known.

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

Context-Free Grammar. Concepts Introduced in Chapter 2. Parse Trees. Example Grammar and Derivation

CMSC 331 Final Exam Section 0201 December 18, 2000

Programming Languages, Summary CSC419; Odelia Schwartz

CMPS Programming Languages. Dr. Chengwei Lei CEECS California State University, Bakersfield

A Simple Syntax-Directed Translator

Midterm Solutions COMS W4115 Programming Languages and Translators Wednesday, March 25, :10-5:25pm, 309 Havemeyer

Chapter 6 Control Flow. June 9, 2015

CSE au Final Exam Sample Solution

COP4020 Spring 2011 Midterm Exam

Informatica 3 Syntax and Semantics

CSE 413 Final Exam. June 7, 2011

Consider a description of arithmetic. It includes two equations that define the structural types of digit and operator:

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona

CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Winter /15/ Hal Perkins & UW CSE C-1

CS164: Midterm I. Fall 2003

Functional Programming. Pure Functional Programming

UNIVERSITY OF CALIFORNIA

COP4020 Programming Languages. Control Flow Prof. Robert van Engelen

Welcome to CS 115 (Winter 2019)

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

CSE 413 Final Exam. December 13, 2012

Introduction to Parsing

FreePascal changes: user documentation

Lecture Chapter 6 Recursion as a Problem Solving Technique

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

CS Exam #1-100 points Spring 2011

The PCAT Programming Language Reference Manual

Functional Programming Languages (FPL)

CSE 3302 Programming Languages Lecture 2: Syntax

CSCE 314 Programming Languages

Lambda Calculus. Gunnar Gotshalks LC-1

Chapter 3: Syntax and Semantics. Syntax and Semantics. Syntax Definitions. Matt Evett Dept. Computer Science Eastern Michigan University 1999

Chapter 3. Semantics. Topics. Introduction. Introduction. Introduction. Introduction

Introduction. A. Bellaachia Page: 1

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler.

Principles of Programming Languages COMP251: Syntax and Grammars

CSCI312 Principles of Programming Languages!

Part 5 Program Analysis Principles and Techniques

CMSC 330, Fall 2018 Midterm 2

CS 3360 Design and Implementation of Programming Languages. Exam 1

CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Spring UW CSE P 501 Spring 2018 C-1

Transcription:

CSE 130, Winter 2006 MIDTERM EXAMINATION CSE 130: Principles of Programming Languages Professor Goguen February 16, 2006 100 points total Don t start the exam until you are told to. Turn off any cell phone or pager. Write your name and PID in the top-right corner of this page. Do not separate the pages. This is a closed-book, closed-notes, no-calculator exam. Don t refer to any materials other than the exam itself. Do not look at anyone else s exam. Do not talk to anyone but an exam proctor during the exam. If you have a question, raise your hand and an exam proctor will come to you. You have 80 minutes to finish the exam. When time is up, you must stop writing. Do not turn this page until you are told that you may do so 1

History and Culture of Programming Languages 1. [2 points] A main point of the Essay on Comparative Programming Linguistics is: a. Comparing programming languages to one another is more fruitful than studying one in isolation. b. The study of programming languages should employ tools from linguistics such as Chomsky s formal grammars. c. In order to understand programming languages in depth, one must study the context of their use. d. We should adopt a paradigmatic rather than syntagmatic focus when discussing the merits of programming languages. 2. [2 points] The first high-level imperative computer programming language was a. Algol 60. b. Lisp. c. Pascal. d. Fortran. 3. [2 points] The functional programming paradigm grew out of a. the theory of Turing machines. b. the lambda calculus. c. need to overcome the limitations of early imperative languages. d. early artificial-intelligence research at MIT. Expressions, Grammars, and Syntax 4. [4 points] Convert the infix expression to both prefix and postfix notation. Assume the standard precedence of operators. Prefix: Postfix: CSE 130 Midterm Exam 2

5. [20 points] Use the following grammar for parts a c. is the start symbol, italicized capital letters ( ) denote non-terminal symbols, and other letters, numbers, and symbols denote terminal symbols.. a. [5 points] Are the following strings in the language of the grammar? w. x. ( w x ) Yes No ( ( x x ) x ) ( y y ) Yes No x 2 Yes No x. ( 2 x. y ) Yes No ( x x ). ( x x ) Yes No b. [5 points] Draw a parse tree for the following string. If there are multiple possible parse trees, any are acceptable. x. ( y. z. ( x y ) z ) c. [10 points] Is the grammar ambiguous? Why or why not? CSE 130 Midterm Exam 3 Turn Over

6. [10 points] Convert the following grammar to an equivalent unambiguous grammar using the template provided. is the start symbol. Both and should be right associative; but,, and should be left associative. The should have the lowest precedence, followed by and (second lowest), then (second-highest) and (highest). Use the following template for your unambiguous grammar: ::= ::= ::= ::= ::= Structured Programming and Invariants 7. [2 points] Advocates of structured programming argued that: a. Programming languages should support the clean division of problems into smaller units. b. Programmers should structure their code by writing invariants first. c. Encapsulation is important in the design of large software systems. d. A program s control flow should be evident from its syntactic structure. CSE 130 Midterm Exam 4

! (! 8. [10 points] The following program fragment rearranges the elements of an array into non-decreasing order using a variant of selection sort. A precondition, a postcondition, and several invariants have been provided for you, but important invariants are missing from the 2 blank spaces. In these spaces write thorough, precise mathematical invariants that logically follow from preceding invariants and imply those following. while do missing invariant while do if then " # $ # missing invariant %& )( * %& ' ( CSE 130 Midterm Exam 5 Turn Over

Types and Type Equivalence 9. [15 points] Consider the following type definitions. type array of integer type array of integer type $ type type In each cell of the grid below, write S if the types in the row and column headers are structurally equivalent, T if they are transitive-name equivalent, and P if they are pure-name equivalent. If two types are equivalent under all 3 kinds of equivalence, you should write STP; if they are not equivalent under any, you should leave the cell blank. 10. [5 points] Briefly state the difference between strongly typed and weakly typed languages. CSE 130 Midterm Exam 6

Parameter Passing and Scope 11. [20 points] Consider the following! Pascal! code: procedure! var new! (* This is the same as return *) var!! var new For each parameter-passing method in the table below, fill in the values of and the Pascal code above. Call-by-Value after running Call-by-Value-Result Call-by-Reference Call-by-Macro Expansion Call-by-Name 12. [8 points] Briefly state what tail recursion is and why it is important. CSE 130 Midterm Exam 7 End of Last Page