Final Examination May 5, 2005

Similar documents
CS 415 Midterm Exam Spring 2002

CS 406/534 Compiler Construction Putting It All Together

Introduction to Lexing and Parsing

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

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

CSE 12 Abstract Syntax Trees

Compiler Design (40-414)

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

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

The Structure of a Syntax-Directed Compiler

The role of semantic analysis in a compiler

CS 415 Midterm Exam Spring SOLUTION

Course Overview. Levels of Programming Languages. Compilers and other translators. Tombstone Diagrams. Syntax Specification

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Programming Languages Third Edition. Chapter 7 Basic Semantics

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

CS 3360 Design and Implementation of Programming Languages. Exam 1

Question Points Score

An Overview of Compilation

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

ECE251 Midterm practice questions, Fall 2010

Principles of Programming Languages [PLP-2015] Detailed Syllabus

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?

UNIVERSITY OF CALIFORNIA

CS143 Final Fall 2009

Midterm II CS164, Spring 2006

List of Figures. About the Authors. Acknowledgments

CS4215 Programming Language Implementation

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

CSE 5317 Midterm Examination 4 March Solutions

Syntax Errors; Static Semantics

CS606- compiler instruction Solved MCQS From Midterm Papers

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

Run-time Environments

CS164: Midterm I. Fall 2003

Run-time Environments

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions)

Theory and Compiling COMP360

What do Compilers Produce?

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

Short Notes of CS201

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised:

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1

CSE 413 Final Exam. June 7, 2011

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

CS5363 Final Review. cs5363 1

CS201 - Introduction to Programming Glossary By

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.

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

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization.

The basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table

Stating the obvious, people and computers do not speak the same language.

Compilers. Computer Science 431

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

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

Project Compiler. CS031 TA Help Session November 28, 2011

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

Crafting a Compiler with C (II) Compiler V. S. Interpreter

CS 415 Midterm Exam Fall 2003

Semantic Analysis. Lecture 9. February 7, 2018

KINGS COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING ACADEMIC YEAR / EVEN SEMESTER

CIS 341 Midterm March 2, 2017 SOLUTIONS

G Programming Languages - Fall 2012

CS 44 Exam #2 February 14, 2001

Assignment 4 CSE 517: Natural Language Processing

CSE 431S Final Review. Washington University Spring 2013

CST-402(T): Language Processors

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Review main idea syntax-directed evaluation and translation. Recall syntax-directed interpretation in recursive descent parsers

LECTURE NOTES ON COMPILER DESIGN P a g e 2

CMSC 330: Organization of Programming Languages. Operational Semantics

Compiler Code Generation COMP360

CS 6353 Compiler Construction Project Assignments

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

CS 411 Midterm Feb 2008

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

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

GUJARAT TECHNOLOGICAL UNIVERSITY

G.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY

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

Types and Static Type Checking (Introducing Micro-Haskell)

CSE 413 Final Exam Spring 2011 Sample Solution. Strings of alternating 0 s and 1 s that begin and end with the same character, either 0 or 1.

Lexical Scanning COMP360

CJT^jL rafting Cm ompiler

G Programming Languages - Fall 2012

CSE 401 Midterm Exam Sample Solution 2/11/15

(F)lex & Bison/Yacc. Language Tools for C/C++ CS 550 Programming Languages. Alexander Gutierrez

Heap, Variables, References, and Garbage. CS152. Chris Pollett. Oct. 13, 2008.

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

CS61C : Machine Structures

Notes on the Exam. Question 1. Today. Comp 104:Operating Systems Concepts 11/05/2015. Revision Lectures (separate questions and answers)

Scope, Functions, and Storage Management

COMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

Disclaimer. A Bit About Forth. No Syntax. Outline. I don't know Forth Typical Forth tutorial. Dave Eckhardt

SOFTWARE ARCHITECTURE 5. COMPILER

What s different about Factor?

Semester Review CSC 301

Transcription:

CS 4352 Compilers and Interpreters Final Examination May 5, 2005 Name Closed Book. If you need more space ask for an extra sheet. 1. [4 points] Pick the appropriate data structure for each purpose: storage of information about identifiers input to code generation storage of local variables at run time storage of objects at run tim a. heap b. stack c. queue d. hash table e. parse tree f. doubly linked list g. abstract syntax tree 2. [3pts] In a pure functional language there are no local variables. Is a stack still needed? Why or why not? 3. [15pts] Sometimes you really need something to run fast. One way to do it is to interleave bits of hand-optimized assembler code in the source program. (This is not common, but it can be done.) Suppose you are chosen to modify the Triangle compiler so that it can accept Triangle programs which include sequences of TAM code. These will be delimited with begintam and endtam. Briefly explain how you would modify the various parts of the Triangle compiler to allow this. Also explain the implications for the ASTs. 1

4. [5pts] In addition to JUMP, which will jump to code address (d + register r), TAM also has a JUMPI instruction, which will pop a code address from the stack, then jump to that address. Which of the following would this be useful for, and why? loops recursive functions switch statements conditionals nested conditionals array access method invocation 5. [5pts] Recall that we saw how to build a parse table from the rules of the grammar, and how to use this for parsing. Now briefly describe a way to go the other way, that is, to generate random programs (for example, for testing a compiler) using either a parse table or the raw set of grammar rules. 6. [4] Group the following types of languages into equivalence classes languages described by regular expressions languages handled by lex languages described by BNF context-free languages context-sensitive languages languages recognized by finite autonoma languages recognized by push-down autonoma languages generated by Turing Machines 7. [3] Process switches are handled by the Operating System. Thread switches are handled by the Runtime Environment. Which is faster? Why? 8. [3] Explain why identifier names are not needed at run time. 2

9. [6] Give two dissimilar examples of type coercion and explain how a compiler would deal with each. 10. [4] Give the Unix shell wildcard, single-character wildcard, comment, and escape characters. 11. [3] Given a statement like oblject1.field3 = 0, what computation is required at run-time to compute the address? 12. [2] Give an example of a machine-dependent optimization. 13. [12pts] If you use an optimizing compiler you can expect some things to be different. For each of the below, circle the right answer and explain briefly why. (a) slower compile time [always, sometimes, never] (b) faster run time [always, sometimes, never] (c) smaller object code [always, sometimes, never] (d) more confusing run-time error reports [always, sometimes, never] (e) more confusing compile-time error reports [always, sometimes, never] (f) more accurate computations [always, sometimes, never] 3

14. [20] Briefly define or explain: (a) garbage collection (b) handle (c) scope (d) static link (e) backpatching (f) code template (g) binding (h) code movement (i) register allocation (j) scanner 4

(k) Yacc/Bison (l) translator (m) cross-compilation (n) emulator (o) bootstrapping (in general) (p) grep (q) pipe (in Unix) (r) basic block (s) ambiguous grammar (t) peephole optimization 5

15. [5pts] cc, the old C compiler, often produced the message Syntax error at line x, without specifying anything more. What functions would you change in cc to make it able to say specifically what the problem was? State any assumptions you make. 16. [6pts] Your boss calls you in and says I ve downloaded this great freeware program, bluedog, which does exactly what we want. Unfortunately it s too slow and it uses too much memory. Oh, and bluedog is written in this new language BP, but I downloaded a freeware compiler for that too. Get to work. [2] Describe the situation using a tombstone diagram. [4] Briefly say how you d go about making bluedog run faster and use less memory. 17. [15] The Roboland language needs a break command, to allow termination of loops. 1. Design a code template showing how code generation will handle break. 2. Also design an extension to the AST objects to handle break. 3. Redesign some module of the compiler to allow detection of breaks that are not within loops. For full credit, your designs should work for break commands in nested loops, and inside conditionals inside loops. 6

. 7