CSE3322 Programming Languages and Implementation

Similar documents
CSE3322 Programming Languages and Implementation

CSE3322 Programming Languages and Implementation

1. (a) What are the closure properties of Regular sets? Explain. (b) Briefly explain the logical phases of a compiler model. [8+8]

Question Marks 1 /20 2 /16 3 /7 4 /10 5 /16 6 /7 7 /24 Total /100

CS 164 Handout 11. Midterm Examination. There are seven questions on the exam, each worth between 10 and 20 points.

CSE341 Autumn 2017, Midterm Examination October 30, 2017

Processadors de Llenguatge II. Functional Paradigm. Pratt A.7 Robert Harper s SML tutorial (Sec II)

SYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram

Error Recovery. Computer Science 320 Prof. David Walker - 1 -

Question Bank. 10CS63:Compiler Design

CSE341 Spring 2016, Midterm Examination April 29, 2016

CSE 341 Section 5. Winter 2018

Introduction to SML Basic Types, Tuples, Lists, Trees and Higher-Order Functions

Higher-Order Functions

Syntax Analysis. Chapter 4

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI

MIDTERM EXAM (Solutions)

PART 3 - SYNTAX ANALYSIS. F. Wotawa TU Graz) Compiler Construction Summer term / 309

1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail.

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1

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

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 20th May 2016 Time: 14:00-16:00

UNIVERSITETET I OSLO

ML Built-in Functions

CSE341, Fall 2011, Midterm Examination October 31, 2011

Question Marks 1 /12 2 /6 3 /14 4 /8 5 /5 6 /16 7 /34 8 /25 Total /120

Question Marks 1 /11 2 /4 3 /13 4 /5 5 /11 6 /14 7 /32 8 /6 9 /11 10 /10 Total /117

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

CSE341 Spring 2016, Midterm Examination April 29, 2016

UNIVERSITETET I OSLO

Roll No. :... Invigilator's Signature :. CS/B.Tech(CSE)/SEM-7/CS-701/ LANGUAGE PROCESSOR. Time Allotted : 3 Hours Full Marks : 70

HW 3: Bottom-Up Parsing Techniques

Compiler Design Aug 1996

CSCI-GA Final Exam

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

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

Handout 2 August 25, 2008

CST-402(T): Language Processors

CS 314 Principles of Programming Languages. Lecture 9

CSE341, Fall 2011, Midterm Examination October 31, 2011

Consider the following EBNF definition of a small language:

A Fourth Look At ML. Chapter Eleven Modern Programming Languages, 2nd ed. 1

Section A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous.

F28PL1 Programming Languages. Lecture 11: Standard ML 1

EXAM. CS331 Compiler Design Spring Please read all instructions, including these, carefully

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

COP4020 Spring 2011 Midterm Exam

Question Marks 1 /16 2 /13 3 /12 4 /15 5 /8 6 /15 7 /8 8 /5 9 /8 Total /100

BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE, Pilani Pilani Campus Instruction Division

LECTURE NOTES ON COMPILER DESIGN P a g e 2

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

2068 (I) Attempt all questions.

Question Points Score

CSE431 Translation of Computer Languages

CSE 401/M501 18au Midterm Exam 11/2/18. Name ID #

Appendix Set Notation and Concepts

CS 415 Midterm Exam Spring 2002

Semantics of programming languages

Types and Static Type Checking (Introducing Micro-Haskell)

Exam Duration: 2hrs and 30min Software Design

CSE341: Programming Languages Lecture 9 Function-Closure Idioms. Dan Grossman Fall 2011

Lecture 12: Data Types (and Some Leftover ML)

UNIVERSITY OF CALIFORNIA

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

Talen en Compilers. Jurriaan Hage , period 2. November 13, Department of Information and Computing Sciences Utrecht University

SECOND PUBLIC EXAMINATION. Compilers

CS153: Compilers Lecture 15: Local Optimization

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

Mini-ML. CS 502 Lecture 2 8/28/08

COP4020 Programming Assignment 2 - Fall 2016

COP5621 Exam 3 - Spring 2005

Chapter 4 - Semantic Analysis. June 2, 2015

Peace cannot be kept by force; it can only be achieved by understanding. Albert Einstein

COP-4620/CIS-6930 PROGRAMMING LANGUAGE TRANSLATORS Instructor: Manuel Bermudez FALL 2015

Working of the Compilers

CS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F).

Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov Compiler Design (170701)

[Syntax Directed Translation] Bikash Balami

Compiler Code Generation COMP360

INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS)

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

Recap: Functions as first-class values

A Concepts-Focused Introduction to Functional Programming Using Standard ML Sample Exam #1 Draft of August 12, 2010

CSE341: Programming Languages Lecture 9 Function-Closure Idioms. Dan Grossman Winter 2013

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

INSTITUTE OF AERONAUTICAL ENGINEERING

CS 421, Fall Sample Final Questions & Solutions

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

Compiler Construction

CSCI Compiler Design

Exercises on ML. Programming Languages. Chanseok Oh

General Computer Science (CH ) Fall 2016 SML Tutorial: Practice Problems

The type checker will complain that the two branches have different types, one is string and the other is int

CSE 582 Autumn 2002 Exam 11/26/02

CSE 3302 Programming Languages Lecture 2: Syntax

SMURF Language Reference Manual Serial MUsic Represented as Functions

A simple syntax-directed

At build time, not application time. Types serve as statically checkable invariants.

CSCE 314 Programming Languages

CS143 Midterm Sample Solution Fall 2010

Transcription:

Monash University School of Computer Science & Software Engineering Sample Exam 2003 CSE3322 Programming Languages and Implementation Total Time Allowed: 3 Hours 1. Reading time is of 10 minutes duration. 2. Examination time is of 3 hours duration. 3. The total marks are 100. 4. All questions should be attempted. 5. Question 1 should be answered in the exam paper itself, the remaining questions in a script book. Fill in your name and Monash Student ID. Name: Student ID:

Question 1 [30 marks] Answer the following multiple choice questions by ticking the box corresponding to the statement which best answers the question. You receive 2 points for each correct answer. (a) FORTRAN was developed by IBM in the late 1930s S. Wolfram in the mid 1960s J. Bachus and his team in the mid 1950s J. Von Neumann in the early 1940s. (b) Which of the following is not true about the language SML: it has type variables it has type constructors it has automatic type coercion it has automatic type deduction it has polymorphic types. (c) Consider the SML program fun dummy x [] = 1 dummy x (y::ys) = x (dummy x ys) ; What does the expression dummy ~ [4,5,6] evaluate to? val it = 1 : int val it = 15 : int val it = ~6 : int val it = 120 : int none of the above (d) What is the type of the function dummy given in (c): int -> a list -> int real -> a list -> real (int -> int) -> a list -> int (real -> real) -> a list -> real none of the above.

(e) An abstype in ML is used to initialize data inside a structure a higher-order data structure hide the definition of higher-order functions define the interface of a structure none of the above (f) What will the ML function mystery defined as follows do fun mystery L = foldr (op +) 0.0 (map (fn x => x*x) L); add the elements of a list square the elements in a list and add them together square the elements in a list and add 0.0 to each one give a syntax error none of the above (g) What is the type of ML function mystery defined above real list -> real real list -> real list a list -> real a list -> a list none of the above (h) Consider the query path(v,w) run with the Prolog program: edge(a,b). edge(b,c). edge(c,a). path(x,y) :- edge(x,y). path(x,z) :- edge(x,y), path(y,z). The first answer found is V = a, W = b. What is the third answer found? V = b, W = c V = b, W = a V = a, W = b V = a, W = c None of the above.

(i) Consider the overloaded operator I which denotes both the functions f 1 : S 1 T 1 and f 2 : S 2 T 2. Context dependent overloading requires that Types S 1 and S 2 are different. Types T 1 and T 2 are different. Types S 1 and S 2 are different or types T 1 and T 2 are different. Types S 1 and S 2 are different and types T 1 and T 2 are different. (j) Consider the Cascal program: int function tricky(int x, int y) { y := 11; x := y; } void main(void) { int y = 3; int x = 4; tricky(x,y); writeln(x+y); } What will be written by the above program if Cascal uses call-by-reference parameter passing: 7 14 21 6 none of the above. (k) Consider the Cascal program: int function inc(int x, int y) { x := y + 1; x := y + 1; } void main(void) { int s := 3; inc(s,s); writeln(s); } What will be written by the above program if Cascal uses call-by-name parameter passing?

3 4 5 6 it will generate a run-time error. (l) In which phase of a compiler is type analysis typically performed? lexical analysis syntax analysis semantic analysis code generation language-independent optimization (m) Consider the context-free grammar with terminal symbols a, b, c, non-terminal symbols A and B where A is the start symbol and productions A BAB a B b c ɛ Which of the following strings is not in the language of the grammar: abb bcacb bbccab bcab bcacba (n) Which of the following statements is true for error correction in Burke-Fisher Parsing? it is a form of panic mode recovery it relies on LL(1) grammars it is a form of local error correction it works by modifying the input string it aborts after the first error (o) Which of the following operations is not part of the language-independent optimization phase? moving invariants out of loops eliminating tail recursion eliminating constants selecting more efficient target code instructions in-lining procedure code

Question 2 [10 marks] Define an ML function inttostring : int -> string such that inttostring i returns a string representation of integer i in decimal. Example: inttostring ~12345 has answer it = "~12345" : string. You should not call the library function Int.toString! Hint: the ML operators for integer division and remainder are div and mod while chr takes an integer and returns the corresponding ASCII character. Question 3 [10 marks] A file system contains files and directories. A file has a name which is a string and some contents which has type char list. A directory has a name and contains files and directories. It is convenient to consider both a file and a directory as file systems so that a directory contains file systems. Define (a) an ML datatype, T, for representing a file system. [3 marks] (b) a function name : T -> string which returns the name followed by a blank character. [3 marks] (c) a function ls : T -> string which returns the name of the file for a file argument and a string containing the names of all components of a directory argument. The predefined functions map : ( a -> b) -> a list -> b list and concat : string list -> string may be used in the solution. [4 marks] Example: If f is a file and d is a directory the returned values could be: ls f = "main.c " ls d = "a.out main.c main.o RCS " Question 4 [10 marks] (a) Briefly explain how call-by-name parameter passing works. [4 marks] (b) Give an example of a language or system that uses call-by-name parameter passing. [2 marks] (c) Give the main reason why call-by-name parameter passing is not widely used and give a supporting example to explain the difficulty with call-by-name parameter passing. [4 marks]

Question 5 [12 marks] Consider the context-free grammar S X S d S ɛ X Y Z b a Y Y c Z Z e The symbols S, X, Y and Z are non-terminals with S as the start symbol while a, b, c, d, e are terminal symbols. Give the F OLLOW and F IRST sets for each non-terminal symbol. [5 marks] Construct the parsing table for a non-recursive predictive parser for this grammar. [4 marks] Is the grammar LL(1)? [1 mark] Detail how an non-recursive predictive parser will parse the sentence dace using the table you constructed above. [2 marks] Question 6 [4 marks] Consider again the context-free grammar from Question 5. Why is this grammar not directly suitable for implementing a recursive descent parser. Identify the productions that cause the problem? [2 marks] Modify the grammar (of course without changing the language it defines) such that it can be implemented directly with a recursive descent parser. [2 marks] Question 7 [ 14 marks] Consider the context-free grammar S a X X b X b Y Y c The symbols S, X, Y are non-terminals and S is the start symbol while a, b and c are terminal symbols. Give the cannonical collection of LR(0) items for this grammar (remembering to first augment it with a new start symbol S ). [6 marks] Compute the F OLLOW sets for all non-terminals and give the SLR parsing table (action and goto) for this grammar. [4 marks] Detail how an SLR parser will parse the sentence abbc using the SLR table you constructed above. [4 marks]

Question 8 [10 marks] Consider the core ML program val mystery = fn (u,v) => (fn (x,y) => (u x, v y)) (a) Give its syntax tree and assign a type variable to each subexpression. [3 marks] (b) Generate a set of type equations (or constraints) on the type variables based on the annotated syntax tree from (a) [4 marks] (c) Solve the type equations from (b) and give the type for mystery. [3 marks] ******* END OF EXAM *******