CSE P 501 Exam 8/5/04

Similar documents
CSE P 501 Exam 8/5/04 Sample Solution. 1. (10 points) Write a regular expression or regular expressions that generate the following sets of strings.

CSE 582 Autumn 2002 Exam 11/26/02

CSE P 501 Exam 12/1/11

CSE 401 Midterm Exam Sample Solution 11/4/11

CSE 401 Midterm Exam 11/5/10

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

CSE P 501 Exam 11/17/05 Sample Solution

CSE 401 Midterm Exam Sample Solution 2/11/15

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

CSE 401 Final Exam. December 16, 2010

Syntax-Directed Translation. Lecture 14

CSE 401 Final Exam. March 14, 2017 Happy π Day! (3/14) This exam is closed book, closed notes, closed electronics, closed neighbors, open mind,...

CSE 582 Autumn 2002 Exam Sample Solution

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

Intermediate Code Generation

CSE 5317 Midterm Examination 4 March Solutions

CIS 341 Midterm February 28, Name (printed): Pennkey (login id): SOLUTIONS

Compiler Theory. (Semantic Analysis and Run-Time Environments)

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Comp 204: Computer Systems and Their Implementation. Lecture 22: Code Generation and Optimisation

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

1 Lexical Considerations

A simple syntax-directed

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

CS2110 Assignment 2 Lists, Induction, Recursion and Parsing, Summer

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

Question Points Score

CSE 413 Final Exam. June 7, 2011

2068 (I) Attempt all questions.

CSE 413 Winter 2001 Final Exam Sample Solution

CSE P 501 Compilers. Static Semantics Hal Perkins Winter /22/ Hal Perkins & UW CSE I-1

Semantic Analysis. Lecture 9. February 7, 2018

Midterm II CS164, Spring 2006

CSE P 501 Exam Sample Solution 12/1/11

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

CSCI Compiler Design

Java Primer 1: Types, Classes and Operators

CSCE 531 Spring 2009 Final Exam

SECOND PUBLIC EXAMINATION. Compilers

CS 314 Principles of Programming Languages

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Test I

CS 406/534 Compiler Construction Putting It All Together

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

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

CSE 331 Final Exam 12/9/13

A Simple Syntax-Directed Translator

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

CSE P 501 Compilers. Implementing ASTs (in Java) Hal Perkins Winter /22/ Hal Perkins & UW CSE H-1

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

CSE 413 Final Exam. December 13, 2012

ECE251 Midterm practice questions, Fall 2010

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

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Expressions and Casting

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

QUESTIONS RELATED TO UNIT I, II And III

Introduction to Compilers Professor Jeremy Siek

LECTURE 3. Compiler Phases

CSE P 501 Compilers. Implementing ASTs (in Java) Hal Perkins Autumn /20/ Hal Perkins & UW CSE H-1

Computer Programming: Skills & Concepts (CP) arithmetic, if and booleans (cont)

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

Midterm Exam (REGULAR SECTION)

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

ECE468 Fall 2003, Final Exam

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

Semantics of programming languages

CS143 - Written Assignment 4 Reference Solutions

Problem Score Max Score 1 Syntax directed translation & type

Lexical Considerations

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division

CMSC330 Spring 2016 Midterm #2 9:30am/12:30pm/3:30pm

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

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

Assignment 5. Introduction

CS143 Compilers - Written Assignment 4

Examination in Compilers, EDAN65

CS143 Handout 20 Summer 2011 July 15 th, 2011 CS143 Practice Midterm and Solution

Part III : Parsing. From Regular to Context-Free Grammars. Deriving a Parser from a Context-Free Grammar. Scanners and Parsers.

Postfix Notation is a notation in which the operator follows its operands in the expression (e.g ).

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

Lecture Overview Code generation in milestone 2 o Code generation for array indexing o Some rational implementation Over Express Over o Creating

CSE 331 Midterm Exam 2/13/12

Principle of Compilers Lecture IV Part 4: Syntactic Analysis. Alessandro Artale

CSE 331 Final Exam 3/12/12

The SPL Programming Language Reference Manual

COMPILERS BASIC COMPILER FUNCTIONS

CS/ECE 374 Fall Homework 1. Due Tuesday, September 6, 2016 at 8pm

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

Compilers - Chapter 2: An introduction to syntax analysis (and a complete toy compiler)

1. [5 points each] True or False. If the question is currently open, write O or Open.

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

Assignment 4 Publication date: 27/12/2015 Submission date: 17/01/ :59 People in-charge: R. Mairon and Y. Twitto

Theory of Computations Spring 2016 Practice Final Exam Solutions

Lexical Considerations

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

Transcription:

Name There are 7 questions worth a total of 65 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. You may refer to the following references: Course lecture slides and notes Homework assignments and sample solutions Your primary compiler textbook (presumably Appel) No other books or other materials. Please wait to turn the page until everyone is told to begin. Page 1 of 8

Score 1 2 3 4 5 6 7 Page 2 of 8

1. (10 points) Write a regular expression or regular expressions that generate the following sets of strings. (a) (5 points) All strings containing a s, b s, and c s with at least one a and at least one b. (b) (5 points) All strings of 0 s and 1 s with at most one pair of consecutive 1 s. 2. (8 points) Pascal defined real (floating-point) numeric constants as follows: digit ::= [0-9] digits ::= digit+ real ::= digits. digits digits. digits E scalefactor digits E scalefactor scalefactor ::= digits (+ - ) digits Draw a DFA that accepts real constants as defined above. (You don t need to construct an NFA and use algorithms to convert it to a DFA just draw a suitable DFA diagram.) Page 3 of 8

3. (12 points) (LR parsing) In languages like Scheme, arithmetic expressions are written as parenthesized lists beginning with an operator followed by the operands. Here is a simple grammar for expressions involving addition and subtraction and the single integer constant 1. exp ::= int ( op exp exp ) op ::= + - int ::= 1 (a) (10 points) Construct the LR(0) state machine for this grammar. (b) (2 points) Is this grammar LR(0)? Why or why not? Page 4 of 8

4. (6 points) Some experimental programming languages include an n+1/2 loop with the following syntax: repeat statement1 while ( exp ) statement2 end The semantics of this loop is that statement1 is executed then the conditional expression exp is evaluated. If exp is false, the loop terminates, otherwise, if it is true, statement2 is executed and the loop repeats starting with statement1. Give the x86 code shape for this loop using a style similar to that used in lecture for other statements and conditional expressions. Page 5 of 8

5. (12 points) Suppose we want to add the following conditional statement to MiniJava: ifequal (exp1, exp2) statement1 smaller statement2 larger statement3 The meaning of this is that statement1 is executed if the integer expressions exp1 and exp2 are equal; statement2 is executed if exp1 < exp2, and statement3 is executed if exp1 > exp2. (a) (5 points) Give context-free grammar production(s) for the ifequal statement that allows either or both of the smaller and larger parts of the statement to be omitted. If both the smaller and larger parts of the statement appear, they should appear in that order. (b) (5 points) Is the grammar with your production(s) from part (a) ambiguous? If not, argue informally why not; if it is ambiguous, give an example that shows that it is. (c) (2 points) When compiling this statement, what rule(s) or condition(s) should the type checker verify? Page 6 of 8

6. (5 points) Suppose we have two classes B and D, where D is a subclass (derived class) of B, and these classes contain the methods shown below. class B { void f() { } void g() { } void h() { } } class D extends B { void k() { } void g() { } } Recall that our convention is that in generated x86 assembly code, the label for a method m in class C is C$m. Show what the generated virtual method dispatch tables for classes B and D would look like in x86 assembly language. (Hint: this is supposed to be an easy question don t over-analyze it.) Page 7 of 8

7. (12 points) Write an x86 assembly-language version of the following C function. Your answer doesn t need to use exactly the same code shape presented in class for the various statements and expressions (i.e., it only needs to be legal x86 code that works properly), but you do need to use the C function-calling conventions properly, i.e., push arguments onto the stack, set up a new stack frame, etc., and you must include assembly language code for all statements given here (i.e., don t omit the assignment to the local variable a, for example). int factorial(int n) { int a; a = n; if (a <= 1) { return 1; } else { return a * factorial(a-1); } } Page 8 of 8