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

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

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

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

CPSC 320 Midterm 2. July 13, 2007

CPSC 121 Midterm 1 Friday October 14th, Signature: Section (circle one): 11:00 15:30 17:00

CPSC 121 Sample Final Examination December 2013

CPSC 121 Midterm 1 Friday February 5th, Signature: Section (circle one): Morning Afternoon

CPSC 411, 2015W Term 2 Midterm Exam Date: February 25, 2016; Instructor: Ron Garcia

CS 411 Midterm Feb 2008

CPSC 121 Some Sample Questions for the Final Exam Tuesday, April 15, 2014, 8:30AM

UNIVERSITY REGULATIONS

EXAMINATION INSTRUCTIONS

THE UNIVERSITY OF BRITISH COLUMBIA CPSC 110: MIDTERM 1 Part B May 26, Important notes about this examination

EXAMINATION INSTRUCTIONS

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012

Full Name: CS Account:

EXAMINATION INSTRUCTIONS

Computer Science 304

Question Points Score

UNIVERSITY REGULATIONS

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

CPSC 311, 2010W1 Midterm Exam #2

CS164: Midterm I. Fall 2003

CSE3322 Programming Languages and Implementation

This examination has 11 pages. Check that you have a complete paper.

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

THE UNIVERSITY OF BRITISH COLUMBIA CPSC 121: MIDTERM 2 Group March 12, 2014

The University of British Columbia Final Examination - December 02, 2014 Mathematics 308. Closed book examination. No calculators.

EXAMINATION INSTRUCTIONS

THE UNIVERSITY OF BRITISH COLUMBIA CPSC 261: MIDTERM 1 February 14, 2017

Class Information ANNOUCEMENTS

Midterm I (Solutions) CS164, Spring 2002

CSE 130 Programming Language Principles & Paradigms Lecture # 5. Chapter 4 Lexical and Syntax Analysis

CSE431 Translation of Computer Languages

8 Parsing. Parsing. Top Down Parsing Methods. Parsing complexity. Top down vs. bottom up parsing. Top down vs. bottom up parsing

First Midterm Exam CS164, Fall 2007 Oct 2, 2007

CS143 Midterm Sample Solution Fall 2010

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

Parsing III. (Top-down parsing: recursive descent & LL(1) )

Types of parsing. CMSC 430 Lecture 4, Page 1

Chapter 4. Lexical and Syntax Analysis

Syntax Analysis, III Comp 412

LL(k) Parsing. Predictive Parsers. LL(k) Parser Structure. Sample Parse Table. LL(1) Parsing Algorithm. Push RHS in Reverse Order 10/17/2012

Compilers. Predictive Parsing. Alex Aiken

CPSC 410 Advanced Software Engineering Mid-term Examination (Term I ): Solution Instructor: Gail Murphy

CPSC 126 SAMPLE FINAL EXAMINATION ANSWERS April, 2003

Sometimes an ambiguous grammar can be rewritten to eliminate the ambiguity.

CS1622. Today. A Recursive Descent Parser. Preliminaries. Lecture 9 Parsing (4)

The University of Oregon May 16, 2015 Oregon Invitational Mathematics Tournament:

CSE3322 Programming Languages and Implementation

The University of British Columbia Computer Science 304 Practice Final Examination

The Parsing Problem (cont d) Recursive-Descent Parsing. Recursive-Descent Parsing (cont d) ICOM 4036 Programming Languages. The Complexity of Parsing

CSCI Compiler Design

CPSC 410? Advanced Software Engineering Mid-term Examination (Term I ) SOLUTION Instructor: Gail Murphy

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

LL(1) predictive parsing

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

CS 536 Midterm Exam Spring 2013

Parsing. Roadmap. > Context-free grammars > Derivations and precedence > Top-down parsing > Left-recursion > Look-ahead > Table-driven parsing

Building a Parser III. CS164 3:30-5:00 TT 10 Evans. Prof. Bodik CS 164 Lecture 6 1

Compilers. Computer Science 431

EXAMINATION INSTRUCTIONS

MATH 253/101,102,103,105 Page 1 of 12 Student-No.:

Table-Driven Top-Down Parsers

CSCI312 Principles of Programming Languages

COL728 Minor1 Exam Compiler Design Sem II, Answer all 5 questions Max. Marks: 20

Parsing Techniques. CS152. Chris Pollett. Sep. 24, 2008.

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

COP 3402 Systems Software Top Down Parsing (Recursive Descent)

CA Compiler Construction

The University of Oregon May 16, 2015 Oregon Invitational Mathematics Tournament:

UNIVERSITY OF CALIFORNIA

Midterm I - Solution CS164, Spring 2014

Top down vs. bottom up parsing

BSCS Fall Mid Term Examination December 2012

Note that for recursive descent to work, if A ::= B1 B2 is a grammar rule we need First k (B1) disjoint from First k (B2).

4. Lexical and Syntax Analysis

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

Chapter 4: Syntax Analyzer

Syntax Analysis, III Comp 412

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

JavaCC Parser. The Compilation Task. Automated? JavaCC Parser

Lexical and Syntax Analysis (2)

4. Lexical and Syntax Analysis

3. Parsing. Oscar Nierstrasz

CSE3322 Programming Languages and Implementation

LECTURE 7. Lex and Intro to Parsing

Syntactic Analysis. Top-Down Parsing

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

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

Recursive Descent Parsers

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Syntax Analysis: Context-free Grammars, Pushdown Automata and Parsing Part - 4. Y.N. Srikant

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

READ AND OBSERVE THE FOLLOWING RULES:

CIT 3136 Lecture 7. Top-Down Parsing

Philadelphia University Faculty of Information Technology Department of Computer Science --- Semester, 2007/2008. Course Syllabus

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

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

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

Transcription:

CSC 460/660, Midterm March 14, 2005 Name: Student ID: Signature: You have 75 minutes to write the 7 questions on this examination. A total of 100 marks is available. Justify all of your answers You may use one page of handwritten notes. Keep your answers short. If you run out of space for a question, you have written too much. The number in square brackets to the right of the question number indicates the number of marks allocated for that question. Use these to help you determine how much time you should spend on each question. Question Marks 1 /20 2 /16 3 /7 4 /10 5 /16 6 /7 7 /24 Total /100 Use the back of the page for rough work. Good luck UNIVERSITY REGULATIONS: No candidate shall be permitted to enter the examination room after the expiration of one half hour, or to leave during the first half hour of the examination. CAUTION: Candidates guilty of any of the following, or similar, dishonest practices shall be immediately dismissed form the examination and shall be liable to disciplinary action. 1. Making use of any books, papers or memoranda, electronic equipment, or other memory aid devices, other than those authorized by the examiners. 2. Speaking or communicating with other candidates. 3. Purposely exposing written papers to the view of other candidates. The plea of accident or forgetfulness shall not be received. 1

FIRST and FOLLOW Sets Question 1 [20 points] Consider the following context-free grammar: A B C x ɛ B C y A C w z B [6/20] Compute F IRST (A), F IRST (B), F IRST (C) [9/20] Compute F OLLOW (A), F OLLOW (B), F OLLOW (C) (Question 1 continued on next page) 2

FIRST and FOLLOW Sets [5/20] Why is this grammar not LL(1)? (End of question 1) 3

Recursive Descent Parsing Question 2 [16 points] Consider the following context free grammar: A B C D B up C down C ɛ C open close D end Assume the following variables and functions already exist: token is a variable that contains the look-ahead symbol as a string. EOF is a predefined string variable that matches end-of-file. accept() is a function that accepts the next token on the input and updates token to be the next lookahead. error() is a function to signal that something went wrong and parsing has stopped. Write a recursive descent parser for this language using Java-like syntax (you can use == to compare strings). (End of question 2) 4

Lexical analyzers Question 3 [7 points] Recall the dangeling else problem exhibited by this grammar: If Stat if Expr then Statement if Expr then Statement else Statement Briefly explain why adding a fi terminal like this: If Stat if Expr then Statement fi if Expr then Statement else Statement fi resolves the problem of the dangeling else problem (End of question 3) 5

Left Factorization and Common Sub-Expression Elimination Question 4 [10 points] Consider the following context-free grammar G: A A a A c b A B B B a B a c B d G is clearly not parsable by recursive descent because of left-recursion and common sub-expressions. [5/10] Eliminate the left recursion of G, and show the resulting grammar. [5/10] Eliminate the common sub-expressions from the result you got by eleminitating the left-recursion and show the resulting grammar. (End of question 4) 6

Question 5 [16 points] Consider the following context-free grammar: E T E E + T E ɛ T F T T F T ɛ F ( E ) id Derivations and Parse Trees [4/16] Give a left-most derivation of the string id + id * id. [4/16] Give a right-most derivation of the string id + id * id. (Question 5 continued on next page) 7

Derivations and Parse Trees [4/16] Are the parse trees for the left-most and the right-most derivations the same? if yes, draw the tree, if no draw the two different trees. [4/16] Briefly explain why both derivations will always be of the same length if they produce the same syntax tree. (End of question 5) 8

Predictive Parsable? Question 6 [7 points] Consider one production for a context-free language G: A α 1 α 2... α n What must be satisfied with respect to the above production for G to be parsable using a predictive parser without backtracking? (End of question 6) 9

LL(1) parsers Question 7 [24 points] Consider the following grammar: E P ( E ) v T P f ɛ T + E ɛ We can compute the following F IRST and F OLLOW sets: X F IRST (X) F OLLOW (X) E {f, v, (} {$, )} P {f, ɛ} {(} T {+, ɛ} {$, )} P ( E ) {f, ɛ} N/A v T {v} N/A f {f} N/A + E {+} N/A ɛ {ɛ} N/A [16/24] Fill in the following LL(1) parse table: ( ) f + v $ E P T (Question 7 continued on next page) 10

LL(1) parsers [8/24] Show, using your parsing table, how a table driven parser would parse the string f(v). Stack Input Production $E f ( v ) (End of question 7) (End of the exam) 11