ECE 573 Midterm 1 September 29, 2009

Similar documents
ECE 468/573 Midterm 1 October 1, 2014

ECE 468/573 Midterm 1 September 30, 2015

Parsers. Xiaokang Qiu Purdue University. August 31, 2018 ECE 468

Let us construct the LR(1) items for the grammar given below to construct the LALR parsing table.

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

Wednesday, August 31, Parsers

Monday, September 13, Parsers

Wednesday, September 9, 15. Parsers

Parsers. What is a parser. Languages. Agenda. Terminology. Languages. A parser has two jobs:

Downloaded from Page 1. LR Parsing

Rational Functions with Removable Discontinuities

ECE468 Fall 2003, Final Exam

Lexical and Syntax Analysis. Bottom-Up Parsing

2068 (I) Attempt all questions.

UNIT III & IV. Bottom up parsing

LR Parsing Techniques

Midterm I (Solutions) CS164, Spring 2002

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

CS606- compiler instruction Solved MCQS From Midterm Papers

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

University of Technology Department of Computer Sciences. Final Examination st Term. Subject:Compilers Design

Compiler Design Aug 1996

LR Parsing - The Items

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

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

Parser Generation. Bottom-Up Parsing. Constructing LR Parser. LR Parsing. Construct parse tree bottom-up --- from leaves to the root

Principles of Programming Languages

shift-reduce parsing

Bottom-Up Parsing. Parser Generation. LR Parsing. Constructing LR Parser

CSE P 501 Compilers. LR Parsing Hal Perkins Spring UW CSE P 501 Spring 2018 D-1

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

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

Formal Languages and Compilers Lecture VII Part 3: Syntactic A

ECE 468/573 Midterm 1 September 28, 2012

MIT Parse Table Construction. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology

CS 403 Compiler Construction Lecture 8 Syntax Tree and Intermediate Code Generation [Based on Chapter 6 of Aho2] This Lecture

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

LECTURE NOTES ON COMPILER DESIGN P a g e 2

LALR stands for look ahead left right. It is a technique for deciding when reductions have to be made in shift/reduce parsing. Often, it can make the

CS 164 Programming Languages and Compilers Handout 9. Midterm I Solution

Compiler Construction Using

Parsing. Handle, viable prefix, items, closures, goto s LR(k): SLR(1), LR(1), LALR(1)

LR Parsing LALR Parser Generators

3. Syntax Analysis. Andrea Polini. Formal Languages and Compilers Master in Computer Science University of Camerino

Parser. Larissa von Witte. 11. Januar Institut für Softwaretechnik und Programmiersprachen. L. v. Witte 11. Januar /23

Conflicts in LR Parsing and More LR Parsing Types

Compilation 2012 Context-Free Languages Parsers and Scanners. Jan Midtgaard Michael I. Schwartzbach Aarhus University

CS453 : JavaCUP and error recovery. CS453 Shift-reduce Parsing 1

Syntax Analysis. Amitabha Sanyal. ( as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay

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

LR Parsing E T + E T 1 T

LR Parsing LALR Parser Generators

Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov Compiler Design (170701)

Lecture Bottom-Up Parsing

4. Lexical and Syntax Analysis

LALR Parsing. What Yacc and most compilers employ.

S Y N T A X A N A L Y S I S LR

4. Lexical and Syntax Analysis

Section A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous.

CS 4120 Introduction to Compilers

Compiling Regular Expressions COMP360

Total 100

Chapter 4. Lexical and Syntax Analysis

Implicit differentiation

In One Slide. Outline. LR Parsing. Table Construction

General Overview of Compiler

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

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

Bottom-up parsing. Bottom-Up Parsing. Recall. Goal: For a grammar G, withstartsymbols, any string α such that S α is called a sentential form

Algorithms for NLP. LR Parsing. Reading: Hopcroft and Ullman, Intro. to Automata Theory, Lang. and Comp. Section , pp.

CSE 401 Midterm Exam 11/5/10

Midterm I - Solution CS164, Spring 2014

Bottom-Up Parsing. Lecture 11-12

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

MODULE 14 SLR PARSER LR(0) ITEMS

Compiler Construction

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

Chapter 3 Parsing. time, arrow, banana, flies, like, a, an, the, fruit

CS 314 Principles of Programming Languages

Torben./Egidius Mogensen. Introduction. to Compiler Design. ^ Springer

CSE 582 Autumn 2002 Exam Sample Solution

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

Lecture 7: Deterministic Bottom-Up Parsing

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

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

5.2. Exploring Quotients of Polynomial Functions. EXPLORE the Math. Each row shows the graphs of two polynomial functions.

Compiler Construction

Bottom Up Parsing Handout. 1 Introduction. 2 Example illustrating bottom-up parsing

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

Bottom-Up Parsing. Lecture 11-12

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

LR Parsing Techniques

Example CFG. Lectures 16 & 17 Bottom-Up Parsing. LL(1) Predictor Table Review. Stacks in LR Parsing 1. Sʹ " S. 2. S " AyB. 3. A " ab. 4.

QUESTIONS RELATED TO UNIT I, II And III

Action Table for CSX-Lite. LALR Parser Driver. Example of LALR(1) Parsing. GoTo Table for CSX-Lite

Programming Language Syntax and Analysis

1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail.

FROWN An LALR(k) Parser Generator

Table-driven using an explicit stack (no recursion!). Stack can be viewed as containing both terminals and non-terminals.

CSE 582 Autumn 2002 Exam 11/26/02

Transcription:

ECE 573 Midterm 1 September 29, 2009 Name: Purdue email: Please sign the following: I affirm that the answers given on this test are mine and mine alone. I did not receive help from an person or material other than those eplicitl allowed). X Part Points Score 1 8 2 15 3 10 4 22 5 25 6 20 Total 100

Part 1: Short answers 8 points) 1) Place the following parts of a compiler in order and identif which are part of the front-end, and which are part of the back-end. Parser, Code generator, Scanner, Optimier of IR), Semantic routines 2 points) Scanner, Parser, Semantic routines, Optimier, Code generator. The first three are the front-end 2) Name two of four) different tpes of compilers, and provide a real-world eample for each that ou name 2 points) Source-to-source research compilers); source-to-assembl gcc, g++, etc.); source-tobtecode javac, C# compiler, etc.); btecode-to-assembl JIT compilers) 3) Eplain briefl ou shouldnʼt need more than one sentence) the difference between the snta of a language and its semantics 1 point) The snta of a language determines its structure, the semantics determine its meaning 4) Eplain the difference between a contet-free grammar and a contet-sensitive grammar 1 point) Contet-free grammar: non-terminals can be replaced b terminals independent of what surrounds them. Contet-sensitive grammar: some productions ma require that a nonterminal appear in a certain contet before the can be applied. 5) Wh do semantic routines need to be placed at the end of productions in LR grammars? 2 points) LR grammars are not predictive; the cannot recognie a production until the see the entire thing. Thus, the cannot appl semantic routines until theʼve reduced a production, so semantic routines can onl go at the end of a production i.e., at the point where the LR parser will reduce).

Part 2: Regular epressions, finite automata and scanners 15 points) 1) Describe, in one sentence, the strings captured b the following regular epression 2 points): ab) + c One or more instances of ab followed b ero or more c s 2) Give a finite automaton that accepts languages defined b the following regular epression this should be a non-deterministic F) 6 points): 1 2 3 ) )) 4 5 3) Give the deterministic equivalent of the NF ou created in problem 2 7 points) 6 7 8 State final? {1, 2, 3} {3, 4} {5} 1,2,3 {3, 4} {3} {4, 5} {6, 8} {5} {7, 8} {3} {3} {5} 3,4 5 {4, 5} {4} {6, 7, 8} 6,8 4,5 3 7,8 {4} {4} {6, 8} {6, 8} es {6, 7, 8} es 4 6,7,8 {7, 8} es

Part 3: Grammars 10 points) Let G be the grammar: S B B λ B B Using this grammar, answer the following questions. 1) What are the terminals and non-terminals of this grammar? 1 point) Terminals:,,. Non-terminals: S,, B 2) Give 4 eamples of strings in the language defined b this grammar. 2 points) Man possibilities. Some eamples:,,,, etc. 3) Draw the parse tree for the following partial derivation i.e., some of the leaves of our parse tree ma be non-terminals) 4 points) S S B B 4) Did this partial derivation get produced b left-derivation or right-derivation? 1 points) Left derivation 5) Give an eample of a partial derivation produced from S in 2 steps b right derivation 2 points) Two possibilities: S B S B B

Part 4: LL parsers 22 points) nswer the questions in this part using the following grammar: 1) Define the following sets: 8 points) S b$ bb) b) λ First b ) {, b} First b a b ) ) {} First b ) ) {} Follow ) {b} 2) Give the predict sets for the productions: 8 points) Predict1) {, b} Predict2) {} Predict3) {} Predict4) {b} 3) Fill in the LL1) parse table based on our predict sets 4 points) ) b $ S 1 1 2, 3 4 4) Is this an LL1) grammar? Wh or wh not? 2 points) This is not an LL1) grammar: if we are processing and the lookahead is, we will not know whether to predict production 2 or production 3.

Part 5: LR0) Parsers 25 points) Use the following grammar for the net two questions: 1) Fill in the missing states for the for the following CFSM 12 points) and fill in the missing edge labels 1 point) State 0 S b $ b) ) State 1 b State 2 $ S b $ S b $ State 4 b) State 6 b ) State 5 State 7 ) State 10 ) b) ) b) ) S b$ b) ) State 9 b ) b) ) ) State 3 S b$ State 8 b ) 2) List the actions the parser will take when parsing the following string. For shift actions, indicate which state the parser will go to; for reduce actions, indicate which rule is being reduced and which state the parser will go to after reducing. You do not have to show the parse stack or the remaining input though it ma help. ssume the parser accepts when it gets to state 2) 12 points) b ) ) b $ S5, S7, S5, S4, R4 goto 6) [after reducing, parser is in state 5], S10, R3 goto 8) [after reducing, parser is in state 7], S9, R2 goto 1) [after reducing, parser is in state 0], S2, ccept

Part 6: LR1) Parsers 20 points) Consider the grammar: S b$ b) ) λ 1) Is this grammar LR0)? Wh or wh not? 1 points) This is not LR0). In state 0, we do not know whether to shift or reduce. 2) Fill in the missing states in the partial LR1) machine given below 13 points) b State 0 State 5 State 6 S b $, {} b), {b} ), {b}, {b} b), {b} ), {b} b), {)} ), {)}, {)} b ), {b} b), {)} ), {)}, {)} State 1 S b $, {} State 7 b), {)} ), {)} b), {)} ), {)}, {)} 3) Fill in the action and goto tables for State 0 4 points) ction table Goto table b $ ) b $ ) S R4 Shift 5 1 4) How would an SLR parser differ from this LR1) parser? 1 point) n LLR parser? 1 point) SLR parser: would use Follow) to solve shift/reduce conflict in state 0 LLR parser: would combine states 5 and 7 because the onl differ in lookahead