Left Recursion. Lecture 8 Section Robb T. Koether. Hampden-Sydney College. Wed, Feb 4, 2015

Similar documents
Compiler. --- Lexical Analysis: Principle&Implementation. Zhang Zhizheng.

Economics 101 Spring 2016 Answers to Homework #1 Due Tuesday, February 9, 2016

John Perry. Fall 2009

School Lunches Menu April September 2017

Pg. 2-3 CS 1.2: Comparing Ratios. Pg CS 1.4: Scaling to Solve Proportions Exit Ticket #1 Pg Inv. 1. Additional Practice.

Economics 101 Spring 2019 Answers to Homework #1 Due Thursday, February 7 th, Directions:

LIMPOPO DEPARTMENT OF EDUCATION LAERSKOOL WARMBAD

Language Homework - Day 1

Investigation 1: Ratios and Proportions and Investigation 2: Comparing and Scaling Rates

Investigation 1: Ratios and Proportions and Investigation 2: Comparing and Scaling Rates

Lecture 3: How Trade Creates Wealth. Benjamin Graham

Statistics 5303 Final Exam December 20, 2010 Gary W. Oehlert NAME ID#

Recent U.S. Trade Patterns (2000-9) PP542. World Trade 1929 versus U.S. Top Trading Partners (Nov 2009) Why Do Countries Trade?

Placing the OU logo on products not listed above constitutes an unauthorized use of the OU symbol, which is a federally registered trademark.

ProStart Level 1 Chapter 10 Serving Your Guest 1 point per question unless noted otherwise Points possible 132

US FOODS E-COMMERCE AND TECHNOLOGY OFFERINGS

Mini Project 3: Fermentation, Due Monday, October 29. For this Mini Project, please make sure you hand in the following, and only the following:

Economics. Interdependence and the Gains from Trade. Interdependence. Interdependence. Our Example. Production Possibilities in the U.S.

MAMA SID'S PIZZA by Faith Goddard-Allen

CLASSROOM NEWS Week of January 23, 2017! jmccool3rdgrade.weebly.com! (302)

Flavour Legislation Past Present and Future or From the Stone Age to the Internet Age and Beyond. Joy Hardinge

Chapter 3. Labor Productivity and Comparative Advantage: The Ricardian Model. Pearson Education Limited All rights reserved.

Consumer Perceptions: Dairy and Plant-based Milks Phase II. January 14, 2019

Chapter 1: The Ricardo Model

STAT 5302 Applied Regression Analysis. Hawkins

Preview. Introduction (cont.) Introduction. Comparative Advantage and Opportunity Cost (cont.) Comparative Advantage and Opportunity Cost

Chapter 3. Labor Productivity and Comparative Advantage: The Ricardian Model

Preview. Chapter 3. Labor Productivity and Comparative Advantage: The Ricardian Model

GEORGIA DEPARTMENT OF CORRECTIONS Standard Operating Procedures. Policy Number: Effective Date: 2/9/2018 Page Number: 1 of 5

Preview. Introduction. Chapter 3. Labor Productivity and Comparative Advantage: The Ricardian Model

Chapter 3 Labor Productivity and Comparative Advantage: The Ricardian Model

TRTP and TRTA in BDS Application per CDISC ADaM Standards Maggie Ci Jiang, Teva Pharmaceuticals, West Chester, PA

Cloud Computing CS

The Indirect Cooking Method

Materials and Methods

Global Product Classification

Dairy Marketing. Dr. Roger Ginder Econ 338a Fall 2009 Lecture # 2

Section 2.3 Fibonacci Numbers and the Golden Mean

TO WHOM IT MAY CONCERN: This is to certify that the following products, listed under their respective brand names, prepared by

KOREA MARKET REPORT: FRUIT AND VEGETABLES

LEVEL ZERO VOICE CATALYST (4 minutes, individual work): How often do you look at food labels? (Always, sometimes, never) Class vote.

essay article about qatar >>>CLICK HERE<<< It is my back writers with or on as a argument because assessing your essay for

Lesson 5. Bag a GO Lunch. In this lesson, students will:

EVENTS at VARSITY HOTEL

COMPARISON OF CORE AND PEEL SAMPLING METHODS FOR DRY MATTER MEASUREMENT IN HASS AVOCADO FRUIT

Recursion. John Perry. Spring 2016

Preview. Introduction. Chapter 3. Labor Productivity and Comparative Advantage: The Ricardian Model

SNAP-ON AND STRAP-ON PIPE MARKERS

What do consumers think about farm animal welfare in modern agriculture? Attitudes and shopping behaviour

Chapter 3: Labor Productivity and Comparative Advantage: The Ricardian Model

Biologist at Work! Experiment: Width across knuckles of: left hand. cm... right hand. cm. Analysis: Decision: /13 cm. Name

Duty/Task Crosswalk to ACF Standards

Gasoline Empirical Analysis: Competition Bureau March 2005

Mix It Up World of Cocktails

Better Punctuation Prediction with Hierarchical Phrase-Based Translation

94306 Vertical Flame Arrester. Features. Vertical Flame Arrester. Unitized tube bank design

Preview. Introduction. Chapter 3. Labor Productivity and Comparative Advantage: The Ricardian Model

1) The following(s) is/are the β-lactum antibiotic(s) 2) The amino acid(s) play(s) important role in the biosynthesis of cephalosporin is/are

Background Activities

Illinois Geometry Lab. Percolation Theory. Authors: Michelle Delcourt Kaiyue Hou Yang Song Zi Wang. Faculty Mentor: Kay Kirkpatrick

Effect of storage on stilbenes contents in cv. Pinot Noir grape canes collected at different times before pruning

raspador Documentation

The premium for organic wines

Fibonacci s Mathematical Contributions

Flexible Working Arrangements, Collaboration, ICT and Innovation

for Assembly, Operating & Maintenance of THIS CHARCOAL GRILL IS DESIGNED FOR OUTDOOR USE ONLY.

Lecture 9: Tuesday, February 10, 2015

Emerging Local Food Systems in the Caribbean and Southern USA July 6, 2014

Reading and Using Recipes

Questions? or

Buying Filberts On a Sample Basis

18 PHOTOSYNTHESIS AND CARBOHYDRATE PARTITIONING IN CRANBERRY

Apple Cinnamon Pancakes (Gluten-Free Recipe)

WINE; OTHER ALCOHOLIC BEVERAGES; PREPARATION THEREOF (beer

Develop the skills and knowledge to use a range of cookery methods to prepare menu items for the kitchen of a hospitality or catering operation.

Thought: The Great Coffee Experiment

New study says coffee is good for you

ECO231 Chapter 2 Homework. Name: Date:

Placing the OU logo on products not listed above constitutes an unauthorized use of the OU symbol, which is a federally registered trademark.

Valuing Health Risk Reductions from Air Quality Improvement: Evidence from a New Discrete Choice Experiment (DCE) in China

Semester 2, Week 9 Friday 7 December 2018

Coffee Eco-labeling: Profit, Prosperity, & Healthy Nature? Brian Crespi Andre Goncalves Janani Kannan Alexey Kudryavtsev Jessica Stern

Economics. Interdependence and the Gains from Trade CHAPTER. N. Gregory Mankiw. Principles of. Seventh Edition. Wojciech Gerson ( )

Neo-Latin Poetry In The British Isles READ ONLINE

MyPlate Style Guide and Conditions of Use for the Icon

Interdependence and the Gains from Trade

What is it? These are the departments in a supermarket/grocery store. Look at the items you can easily find in each department.

FOOD and DRINKS Question: What do you usually eat and drink for breakfast? Complete the paragraph on the right with the words on the left.

Name Date. Materials 1. Calculator 2. Colored pencils (optional) 3. Graph paper (optional) 4. Microsoft Excel (optional)

TECHNICAL SUPPORT MANUAL Split System Air Conditioner (C,H,T)4A3

Starbucks Case Study

Predictions for Algol type Eclipsing Binaries in June 2017

Vie de France Yamazaki, Inc., 2070 Chain Bridge Road SUITE 500, Vienna, VA

Pre- and Postharvest 1-MCP Technology for Apples

NEW YORK CITY COLLEGE OF TECHNOLOGY, CUNY DEPARTMENT OF HOSPITALITY MANAGEMENT COURSE OUTLINE COURSE#: HMGT 2305 COURSE TITLE: DINING ROOM OPERATIONS

2016 May 1 Sun 2016 May 2 Mon 2016 May 3 Tue. Y Leo 01(05)02L CM Lac 01(03)03D BH Dra 02(05)03D

IMISP MBA program - DRAFT PROGRAM STUCTURE -

Blackberry Variety Development and Crop Growing Systems. John R. Clark University Professor of Horticulture

COLT 45 / MALT LIQUOR / MALT LAGER VARIATIONS By Randy Karasek

Study Guide. Chapter 30. Grain Products. Name Date Class

Transcription:

Left Recursion Lecture 8 Section 4.3.3 Robb T. Koether Hampden-Sydney College Wed, Feb 4, 2015 Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 1 / 25

1 Problems with Recursive Descent 2 Left Recursion 3 Eliminating Left Recursion 4 Advantages of Left Recursion 5 Assignment Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 2 / 25

Outline 1 Problems with Recursive Descent 2 Left Recursion 3 Eliminating Left Recursion 4 Advantages of Left Recursion 5 Assignment Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 3 / 25

A Problem with Recursive Descent Parsers Suppose the grammar were S AB CD A BC CA a B CA DB b C BA AD a D AC BD b How could a top-down parser decide which production for S to use to derive babbb? Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 4 / 25

A Problem with Recursive Descent Parsers Suppose the grammar were S AB CD A BC CA a B CA DB b C BA AD a D AC BD b How could a top-down parser decide which production for S to use to derive babbb? Indeed, can babbb be derived? Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 4 / 25

Another Problem with Recursive Descent Parsers Suppose the grammar were S S S a How could the parser decide how many times to use the production S S S before using the production S a? Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 5 / 25

Futile Attempt Futile Attempt void S() // Match S -> S S a { if (token == a) match(a); else { S(); S(); } return; } Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 6 / 25

Outline 1 Problems with Recursive Descent 2 Left Recursion 3 Eliminating Left Recursion 4 Advantages of Left Recursion 5 Assignment Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 7 / 25

Left Recursion Definition (Left recursive production) A production is left recursive if it is of the form A Aα. for some nonterminal A and some string α. Definition (Left recursive grammar) A grammar is left recursive if there is a derivation A + Aα for some nonterminal A and some string α. Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 8 / 25

Left Recursion Left Recursion void A() // Match A -> Aα { A(); // Process α return; } Attempting to match the left-recursive production A Aα. Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 9 / 25

Left Recursion S AB CD A BC CA a B CA DB b C BA AD a D AC BD b Is this grammar left recursive? Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 10 / 25

Left Recursion Recall that in the earlier example, we added the production not the production Why? S SS ε, S S S ε. Are they equivalent as far as the language of the grammar is concerned? Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 11 / 25

Outline 1 Problems with Recursive Descent 2 Left Recursion 3 Eliminating Left Recursion 4 Advantages of Left Recursion 5 Assignment Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 12 / 25

Eliminating Left Recursion Left recursion in a production may be removed by transforming the grammar in the following way. Replace with where A is a new nonterminal. A Aα β A βa A αa ε. Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 13 / 25

Eliminating Left Recursion Under the original productions, a derivation of βααα is A Aα Aαα Aααα βααα. Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 14 / 25

Eliminating Left Recursion Under the new productions, a derivation of βααα is A βa βαa βααa βαααa βααα. Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 15 / 25

Example Example (Eliminating Left Recursion) Consider the left recursive grammar E E + T T T T F F F ( E ) id Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 16 / 25

Example Example (Eliminating Left Recursion) Apply the transformation to E: E T E E + T E ε. Then apply the transformation to T : T F T T F T ε. Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 17 / 25

Example Example (Eliminating Left Recursion) Now the grammar is E T E E + T E ε T F T T F T ε F ( E ) id Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 18 / 25

Eliminating Left Recursion Eliminating Left Recursion void Eprime() // Match E -> + T E { if (token == PLUS) { match(plus); T(); Eprime(); } return; } This is the function for E. Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 19 / 25

Outline 1 Problems with Recursive Descent 2 Left Recursion 3 Eliminating Left Recursion 4 Advantages of Left Recursion 5 Assignment Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 20 / 25

Advantages of Left Recursion A left recursive grammar is often more intuitive than the transformed grammar. A left recursive grammar will match expressions earlier, leading to shallower recursion. Bottom-up parsing takes advantage of the benefits of left recursion. Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 21 / 25

Example Consider the simple grammar E E + E num Convert it to E num E E + E E ε Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 22 / 25

Example ExpressionParser Run ExpressionParser. Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 23 / 25

Outline 1 Problems with Recursive Descent 2 Left Recursion 3 Eliminating Left Recursion 4 Advantages of Left Recursion 5 Assignment Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 24 / 25

Assignment Homework Page 216: 1, 2(a)(b)(d). The grammar R R R R R R ( R ) a b generates all regular expressions over the alphabet {a, b}. Rewrite the grammar to reflect the precedence rules. Eliminate left recursion. Robb T. Koether (Hampden-Sydney College) Left Recursion Wed, Feb 4, 2015 25 / 25