COP4020 Spring 2011 Midterm Exam

Similar documents
COP5621 Exam 3 - Spring 2005

CS 415 Midterm Exam Spring 2002

Question Points Score

COP4020 Programming Assignment 2 Spring 2011

CS 415 Midterm Exam Spring SOLUTION

COP4020 Programming Languages. Semantics Prof. Robert van Engelen

Recursive Descent Parsers

LECTURE 3. Compiler Phases

CSCI Compiler Design

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

CS606- compiler instruction Solved MCQS From Midterm Papers

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

10/18/18. Outline. Semantic Analysis. Two types of semantic rules. Syntax vs. Semantics. Static Semantics. Static Semantics.

COP4020 Programming Assignment 2 - Fall 2016

Abstract Syntax Trees Synthetic and Inherited Attributes

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

COP4020 Programming Languages. Syntax Prof. Robert van Engelen

CSE302: Compiler Design

A simple syntax-directed

CS143 Midterm Sample Solution Fall 2010

Programming Languages

COP 3402 Systems Software Top Down Parsing (Recursive Descent)

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

Test I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Spring Department of Electrical Engineering and Computer Science

Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

CMSC 330, Fall 2018 Midterm 2

COP4020 Programming Languages. Semantics Robert van Engelen & Chris Lacher

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

CS 415 Midterm Exam Fall 2003

Midterm I (Solutions) CS164, Spring 2002

CS 320 Midterm Exam Solution

Comp 311: Sample Midterm Examination

Principles of Programming Languages 2017W, Functional Programming

UMBC CMSC 331 Final Exam

Semantic Analysis Attribute Grammars

CMSC 330, Fall 2018 Midterm 2

CS 406: Syntax Directed Translation

MIDTERM EXAMINATION - CS130 - Spring 2005

ECE 468/573 Midterm 1 September 30, 2015

COP4020 Programming Languages. Syntax Prof. Robert van Engelen

CSE 3302 Programming Languages Lecture 2: Syntax

COP4020 Programming Assignment 1 - Spring 2011

10/26/17. Attribute Evaluation Order. Attribute Grammar for CE LL(1) CFG. Attribute Grammar for Constant Expressions based on LL(1) CFG

Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.

CMSC330 Spring 2018 Midterm 2 9:30am/ 11:00am/ 3:30pm

CS143 Handout 20 Summer 2012 July 18 th, 2012 Practice CS143 Midterm Exam. (signed)

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

Com S 541. Programming Languages I

CMSC 331 Final Exam Section 0201 December 18, 2000

Lecture 14 Sections Mon, Mar 2, 2009

Syntax-Directed Translation Part I

Midterm 2 Solutions Many acceptable answers; one was the following: (defparameter g1

CS 132 Compiler Construction, Fall 2012 Instructor: Jens Palsberg Multiple Choice Exam, Nov 6, 2012

CSCE 531 Spring 2009 Final Exam

Midterm I - Solution CS164, Spring 2014

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

Parsing. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice.

UNIVERSITY OF CALIFORNIA

LECTURE 7. Lex and Intro to Parsing

Syntax Analysis, III Comp 412

Lexical and Syntax Analysis

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

Name EID. (calc (parse '{+ {with {x {+ 5 5}} {with {y {- x 3}} {+ y y} } } z } ) )

Static and Dynamic Semantics

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

CSE 5317 Midterm Examination 4 March Solutions

Chapter 4. Action Routines

MIDTERM EXAMINATION - CS130 - Spring 2003

2068 (I) Attempt all questions.

We now allow any grammar symbol X to have attributes. The attribute a of symbol X is denoted X.a

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

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

Syntax-Directed Translation. Introduction

The role of semantic analysis in a compiler

CS 842 Ben Cassell University of Waterloo

ECE251 Midterm practice questions, Fall 2010

Abstract Syntax Trees & Top-Down Parsing

Abstract Syntax Trees & Top-Down Parsing

[Syntax Directed Translation] Bikash Balami

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

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

Syntax Directed Translation

10/4/18. Lexical and Syntactic Analysis. Lexical and Syntax Analysis. Tokenizing Source. Scanner. Reasons to Separate Lexical and Syntactic Analysis

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

A programming language requires two major definitions A simple one pass compiler

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

Summary: Semantic Analysis

CSCI312 Principles of Programming Languages

ECE 468/573 Midterm 1 October 1, 2014

Abstract Syntax Trees & Top-Down Parsing

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

10/5/17. Lexical and Syntactic Analysis. Lexical and Syntax Analysis. Tokenizing Source. Scanner. Reasons to Separate Lexical and Syntax Analysis

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

Midterm Exam. CSCI 3136: Principles of Programming Languages. February 20, Group 2

Compiler principles, PS1

A Simple Syntax-Directed Translator

Parsing III. CS434 Lecture 8 Spring 2005 Department of Computer Science University of Alabama Joel Jones

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

MIDTERM REVIEW. Lectures 1-15

Compilers. 5. Attributed Grammars. Laszlo Böszörmenyi Compilers Attributed Grammars - 1

Transcription:

COP4020 Spring 2011 Midterm Exam Name: (Please print Put the answers on these sheets. Use additional sheets when necessary or write on the back. Show how you derived your answer (this is required for full credit and helpful for partial credit. You can collect 100 points in total for this exam. 1. Which of the following programming languages is a functional programming language? (mark one (4 points (a Fortran 77 (b COBOL (c Haskell (d Pascal 2. In a recursive decent parser, the attribute values of nonterminals can be passed along function calls as...? (mark one or more (4 points (a function input parameters are synthesized attributes values (b function input parameters are inherited attributes values (c function return and output parameter values are synthesized attributes values (d function return and output parameter values are inherited attributes values 3. A syntax error in the source code input stream is detected by the compiler in its...? (mark one (4 points (a scanner (b parser (c semantic analyzer (d intermediate code generator 4. Given the grammar below, what is the set FIRST(B C a? That is, the set of tokens that start the strings derived from the sentential form B C a? (mark one (4 points (a { b } A B C a B b D ε C c D d (b { b, c } (c { a, b, c, d } (d { b, c, d } 1

5. Which string is recognized by the regular expression R below? (mark one (4 points (a 4,3,2,1 (b 1,432,5 (c 1234 (d 9,876 R D (, D D D with D 0 1 2 3 4 5 6 7 8 9 6. Consider the Prolog unification of two terms containing variables. Which variables (X, Y, and Z are bound after unification and to which terms? (mark one (4 points foo(x, bar(y, a, b, Z = foo(bar(z, a, b, X, c. (a X = bar(c, a, b, Y = c, Z = c (b X = bar(y, a, b, Z = c (c Z = c (X and Y are not set (d None of the above, because unification fails (Y is not set 7. Consider the following recursive Scheme function that translates a list containing certain items: (define buy-or-sell (lambda (items (if (null? items ( (let ( (item (car items (rest (cdr items (cons (cons (if (> (car item 0 buy sell (cdr item (buy-or-sell rest Which one of the following function evaluations is correct? (mark one (4 points (a (buy-or-sell ((thing 1 (thing 2 evaluates to ((buy 1 (buy 2 (b (buy-or-sell ((1 pie (0 jolt (2 pen evaluates to ((buy pie (sell jolt (buy pen (c (buy-or-sell (1 0 2 evaluates to (buy sell buy (d (buy-or-sell ((1 x (0 y (2 z evaluates to (x z z 2

8. An abstract syntax tree is...? (mark one (4 points (a a parse tree (b a parse tree decorated with attributes and values (c a tree data structure produced by a parser implemented by an augmented grammar with translation rules (d an abstract grammar that defines the syntax of a tree data structure 9. Consider following grammar: S if X then S end if X then S else S end id = X X id num (a The productions for S do not make the grammar LL(1, why? Change it to make it LL(1. (5 points (b Given you changed it to LL(1, implement a recursive descent parser (in C or pseudo code, you can use built-in match(token and lookahead( functions. (5 points 3

10. In Project 1 we implemented a translator. What is the Scheme s-expression that the translator produces for the following MicroPL fragment? A rough outline is fine, as long as the necessary Scheme components are shown. (8 points declare x = 10 begin set x call + x 1 $ call display x $ end 11. What is the forward chaining resolution strategy to deduce theorems in logic programming? Explain. (7 points 4

12. Given the following NFA, write a regular expression R that accepts the same strings. (10 points!" #" Note: unlabeled arcs denote empty (a.k.a. epsilon transitions. 13. Describe one example of static semantic checks performed by the compiler. (8 points 5

14. Lambda calculus beta reduction is the process of substituting actual argument values for the formal arguments in a lambda abstraction body (a function body. Apply beta reduction to the following Scheme example, until no further beta reductions can be made. (10 points ( (lambda (f g x (g (f x (lambda (y (* y y display 3 15. Consider the following augmented grammar for a language that describes floating-point fractions, consisting of a decimal period and a fractional part: F. N F.val = N.val N 1 D N 2 N 1.val =(D.val + N 2.val/10.0 N ε N.val = 0 D 0 D.val = 0 D 1 D.val = 1... D 9 D.val = 9 (a Draw the parse tree of. 4 2. (5 points (b Determine which attributes are synthesized and which are inherited. (5 points (c Decorate the parse tree with the attributes and their values as defined in the semantic rules of the augmented grammar. (5 points 6