Page No 1 (Please look at the next page )

Similar documents
Intermediate Code Generation

BSCS Fall Mid Term Examination December 2012

PSD3A Principles of Compiler Design Unit : I-V. PSD3A- Principles of Compiler Design

Principle of Compilers Lecture VIII: Intermediate Code Generation. Alessandro Artale

CS606- compiler instruction Solved MCQS From Midterm Papers

CD Assignment I. 1. Explain the various phases of the compiler with a simple example.

CA Compiler Construction

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

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

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

Table-Driven Parsing

Chapter 6 Intermediate Code Generation

Compiler Theory. (Intermediate Code Generation Abstract S yntax + 3 Address Code)


Review. Pat Morin COMP 3002

A simple syntax-directed

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

2068 (I) Attempt all questions.

Formal Languages and Compilers Lecture X Intermediate Code Generation

UNIT IV INTERMEDIATE CODE GENERATION

MidTerm Papers Solved MCQS with Reference (1 to 22 lectures)

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CS 4201 Compilers 2014/2015 Handout: Lab 1

The procedure attempts to "match" the right hand side of some production for a nonterminal.

UNIT -2 LEXICAL ANALYSIS

1. The output of lexical analyser is a) A set of RE b) Syntax Tree c) Set of Tokens d) String Character

A Simple Syntax-Directed Translator

LECTURE 3. Compiler Phases

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Principles of Compiler Design

Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday

CS308 Compiler Principles Lexical Analyzer Li Jiang

Question Bank. 10CS63:Compiler Design

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

Lecture 10 Parsing 10.1

CSCE 531, Spring 2015 Final Exam Answer Key

Alternatives for semantic processing

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

KEY. A 1. The action of a grammar when a derivation can be found for a sentence. Y 2. program written in a High Level Language

Chapter 4. Lexical and Syntax Analysis

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

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

Chapter 3 Lexical Analysis

COMPILER CONSTRUCTION (Intermediate Code: three address, control flow)

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

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

Compiler course. Chapter 3 Lexical Analysis

Intermediate Representations

CS 406/534 Compiler Construction Putting It All Together

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

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

CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2]

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

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

BVRIT HYDERABAD College of Engineering for Women Department of Computer Science and Engineering. Course Hand Out

CSE P 501 Exam 8/5/04

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

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

UNIT-3. (if we were doing an infix to postfix translator) Figure: conceptual view of syntax directed translation.

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

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

Compiler construction in4303 lecture 3

Zhizheng Zhang. Southeast University

Lexical and Syntax Analysis

Chapter 3. Describing Syntax and Semantics ISBN

Introduction; Parsing LL Grammars

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

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

CMPT 379 Compilers. Anoop Sarkar. 11/13/07 1. TAC: Intermediate Representation. Language + Machine Independent TAC

Semantic Analysis. Lecture 9. February 7, 2018

Intermediate Code Generation

2.2 Syntax Definition

PRINCIPLES OF COMPILER DESIGN

Concepts of Programming Languages Recitation 1: Predictive Parsing

Intermediate Code Generation

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

Formal Languages and Compilers Lecture VI: Lexical Analysis

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

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

Time : 1 Hour Max Marks : 30

CSE302: Compiler Design

Three-address code (TAC) TDT4205 Lecture 16

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.

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

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

Lisp: Lab Information. Donald F. Ross

Syntax Analysis. Martin Sulzmann. Martin Sulzmann Syntax Analysis 1 / 38

Question Points Score

CSc 453 Lexical Analysis (Scanning)

Compiler Design Aug 1996

CS415 Compilers. Lexical Analysis

Lexical Analysis. Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata

Writing Evaluators MIF08. Laure Gonnord

Syntactic Analysis. Top-Down Parsing

Front End: Lexical Analysis. The Structure of a Compiler

CS 314 Principles of Programming Languages

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

Compiler Design (40-414)

Program Analysis ( 软件源代码分析技术 ) ZHENG LI ( 李征 )

Transcription:

Salman Bin Abdul Aziz University Collage of Computer Engineering and Sciences Computer Science Department 1433-1434 (2012-2013) First Term CS 4300 Compiler Construction 8 th Level Final Exam 120 Minutes In the Name of ALLAH, the Most Merciful, the Most Beneficent. Make sure your exam consists of 4 questions in 7 pages. Answer all questions. Time distribution: 4 questions 25 minutes = 100 minutes + 20 minutes over = 120 minutes. Name العربية)........ :(باللغة Uni ID:.... Marks Distribution (Do not write in this part.) Question No. 1 2 3 4 Total Degrees 10 10 10 10 40 1) State whether the following are true or false. 1. An interpreter can usually give better error diagnostics than a compiler, because it executes the source program statement by statement. ( ) 2. The task of collecting the source program is sometimes entrusted to a separate program, called assembler. ( ) 3. One task of the lexical analyzer is correlating error messages generated by the compiler with the source program. ( ) 4. A lexeme is a sequence of characters in the source program that matches the pattern for a token. ( ) 5. A language that can be generated by a grammar is said to be a regular language. ( ) 6. FIRST( ), where is any string of grammar symbols, is the set of terminals that begin strings derived from. ( ) 7. A parse tree, showing the value(s) of its attribute(s) is called a syntax tree. ( ) 8. A dependency graph depicts the flow of information among the attribute instances in a particular parse tree; an edge from one attribute instance to another means that the value of the first is needed to compute the second. Edges express constraints implied by the semantic rules. ( ) 9. Static checking includes type checking, which ensures that operators are applied to compatible operands. ( ) 10. All assignments in static single-assignment form are to variables with distinct names. ( ) Page No 1 (Please look at the next page )

2) a. Write the algorithm for simulating DFA. Page No 2 (Please look at the next page )

2) b. Construct a NFA for the RE (a b) * abb. Page No 3 (Please look at the next page )

3) a. Apply eliminating left recursion algorithm to the following grammar: S A a b A A c S d Page No 4 (Please look at the next page )

3) b. Consider the non-left-recursive grammar E T E' E' + T E' T F T' T' * F T' F ( E ) id Compute FIRST(E), FIRST(E'), FIRST(T), FIRST(T'), FIRST(F), FOLLOW(E), FOLLOW(E'), FOLLOW(T), FOLLOW(T'), and FOLLOW(F). Page No 5 (Please look at the next page )

4) a. Construct the annotated parse tree for the input string 3 * 5 + 4 n, using the given grammar and rules: Page No 6 (Please look at the next page )

4) b. What are the common three-address instructions? Page No 7 (The end of questions) Good Luck Dr. Ahmed Al-Hussain Naghamish

Salman Bin Abdul Aziz University Collage of Computer Engineering and Sciences Computer Science Department 1) 1433-1434 (2012-2013) First Term Answers CS 4300 Compiler Construction 8 th Level Final Exam 120 Minutes 2) 1. T 2. F 3. T 4. T 5. F 6. T 7. F 8. T 9. T 10. T a. Simulating a DFA algorithm: this algorithm shows how to apply a DFA to a string. Input: A DFA D with start state s 0, accepting states F, and transition function move. An input string x terminated by an end-of-file character eof. Output: Answer ''yes" if D accepts x; "no" otherwise. Method: Apply the following algorithm to the input string x. s = s 0 ; c = nextchar(); while ( c!= eof ) { s = move(s, c); c = nextchar(); } if ( s is in F ) return "yes"; else return "no"; b.

3) a. We order the nonterminals S, A. There is no immediate left recursion among the S-productions, so nothing happens during the outer loop for i = 1. For i = 2, we substitute for S in A S d to obtain the following A- productions: A A c A a d b d Eliminating the immediate left recursion among these A-productions: A A c A a d b d yields the following grammar: S A a b A b d A A A c A a d A b. FIRST(F) = FIRST(T) = FIRST(E) = {(, id}. FIRST(E ) = {+, }. FIRST(T ) = {*, }. FOLLOW(E) = FOLLOW(E ) = {), $}. FOLLOW(T) = FOLLOW(T ) = {+, ), $}. FOLLOW(F) = {*, +, ), $}.

4) a. b. 1. Assignment instructions of the form x = y op z. 2. Assignments of the form x = op y. 3. Copy instructions of the form x = y. 4. An unconditional jump goto L. 5. Conditional jumps of the form if x goto L and iffalse x goto L. 6. Conditional jumps such as if x relop y goto L. 7. Procedure calls and returns are implemented using the following instructions: param x for parameters; call p, n and y = call p, n for procedure and function calls, respectively; and return y, where y, representing a returned value, is optional. Their typical use is as the sequence of three-address instructions param x 1 param x 2. param x n call p, n generated as part of a call of the procedure p(x 1, x 2,, x n ). 8. Indexed copy instructions of the form x = y[i] and x[i] = y. 9. Address and pointer assignments of the form x = &y, x = *y, and *x = y.