this grammar generates the following language: Because this symbol will also be used in a later step, it receives the

Similar documents
CSCI 3130: Formal Languages and Automata Theory Lecture 12 The Chinese University of Hong Kong, Fall 2011

Definition of Regular Expression

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

LR Parsing, Part 2. Constructing Parse Tables. Need to Automatically Construct LR Parse Tables: Action and GOTO Table

Top-down vs Bottom-up. Bottom up parsing. Sentential form. Handles. Handles in expression example

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

CS 321 Programming Languages and Compilers. Bottom Up Parsing

Fig.25: the Role of LEX

Midterm I Solutions CS164, Spring 2006

Compilers Spring 2013 PRACTICE Midterm Exam

12 <= rm <digit> 2 <= rm <no> 2 <= rm <no> <digit> <= rm <no> <= rm <number>

Dr. D.M. Akbar Hussain

ECE 468/573 Midterm 1 September 28, 2012

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 4: Lexical Analyzers 28 Jan 08

CS 430 Spring Mike Lam, Professor. Parsing

Finite Automata. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 21, 2015

Deterministic. Finite Automata. And Regular Languages. Fall 2018 Costas Busch - RPI 1

CSE 401 Midterm Exam 11/5/10 Sample Solution

Languages. L((a (b)(c))*) = { ε,a,bc,aa,abc,bca,... } εw = wε = w. εabba = abbaε = abba. (a (b)(c)) *

Lexical analysis, scanners. Construction of a scanner

Problem Set 2 Fall 16 Due: Wednesday, September 21th, in class, before class begins.

CS 340, Fall 2014 Dec 11 th /13 th Final Exam Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

CS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

Lexical Analysis: Constructing a Scanner from Regular Expressions

Operator Precedence. Java CUP. E E + T T T * P P P id id id. Does a+b*c mean (a+b)*c or

Topic 2: Lexing and Flexing

CS143 Handout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexical Analysis

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

Reducing a DFA to a Minimal DFA

Implementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

2 Computing all Intersections of a Set of Segments Line Segment Intersection

UT1553B BCRT True Dual-port Memory Interface

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

1.1. Interval Notation and Set Notation Essential Question When is it convenient to use set-builder notation to represent a set of numbers?

TO REGULAR EXPRESSIONS

CSCE 531, Spring 2017, Midterm Exam Answer Key

Homework. Context Free Languages III. Languages. Plan for today. Context Free Languages. CFLs and Regular Languages. Homework #5 (due 10/22)

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

Applied Databases. Sebastian Maneth. Lecture 13 Online Pattern Matching on Strings. University of Edinburgh - February 29th, 2016

ASTs, Regex, Parsing, and Pretty Printing

stack of states and grammar symbols Stack-Bottom marker C. Kessler, IDA, Linköpings universitet. 1. <list> -> <list>, <element> 2.

Lecture 7: Integration Techniques

Assignment 4. Due 09/18/17

Slides for Data Mining by I. H. Witten and E. Frank

CS 432 Fall Mike Lam, Professor a (bc)* Regular Expressions and Finite Automata

Context-Free Grammars

EECS150 - Digital Design Lecture 23 - High-level Design and Optimization 3, Parallelism and Pipelining

CS 241 Week 4 Tutorial Solutions

acronyms possibly used in this test: CFG :acontext free grammar CFSM :acharacteristic finite state machine DFA :adeterministic finite automata

CMPSC 470: Compiler Construction

Java CUP. Java CUP Specifications. User Code Additions. Package and Import Specifications

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex

MTH 146 Conics Supplement

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS 1 COMPUTATION & LOGIC INSTRUCTIONS TO CANDIDATES

COMP 423 lecture 11 Jan. 28, 2008

CS311H: Discrete Mathematics. Graph Theory IV. A Non-planar Graph. Regions of a Planar Graph. Euler s Formula. Instructor: Işıl Dillig

Lab 1 - Counter. Create a project. Add files to the project. Compile design files. Run simulation. Debug results

CMSC 331 First Midterm Exam

Should be done. Do Soon. Structure of a Typical Compiler. Plan for Today. Lab hours and Office hours. Quiz 1 is due tonight, was posted Tuesday night

Example: Source Code. Lexical Analysis. The Lexical Structure. Tokens. What do we really care here? A Sample Toy Program:

File Manager Quick Reference Guide. June Prepared for the Mayo Clinic Enterprise Kahua Deployment

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus

Context-Free Grammars

From Dependencies to Evaluation Strategies

Theory of Computation CSE 105

Compiler Construction D7011E

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 3b Lexical Analysis Elias Athanasopoulos

A Tautology Checker loosely related to Stålmarck s Algorithm by Martin Richards

EXPONENTIAL & POWER GRAPHS

Lecture 10 Evolutionary Computation: Evolution strategies and genetic programming

Eliminating left recursion grammar transformation. The transformed expression grammar

Agilent Mass Hunter Software

Today. CS 188: Artificial Intelligence Fall Recap: Search. Example: Pancake Problem. Example: Pancake Problem. General Tree Search.

CS 241. Fall 2017 Midterm Review Solutions. October 24, Bits and Bytes 1. 3 MIPS Assembler 6. 4 Regular Languages 7.

1. SEQUENCES INVOLVING EXPONENTIAL GROWTH (GEOMETRIC SEQUENCES)

From Indexing Data Structures to de Bruijn Graphs

If you are at the university, either physically or via the VPN, you can download the chapters of this book as PDFs.

Some Thoughts on Grad School. Undergraduate Compilers Review and Intro to MJC. Structure of a Typical Compiler. Lexing and Parsing

Announcements. CS 188: Artificial Intelligence Fall Recap: Search. Today. Example: Pancake Problem. Example: Pancake Problem

2014 Haskell January Test Regular Expressions and Finite Automata

Scanner Termination. Multi Character Lookahead. to its physical end. Most parsers require an end of file token. Lex and Jlex automatically create an

The Fundamental Theorem of Calculus

Improper Integrals. October 4, 2017

MATH 25 CLASS 5 NOTES, SEP

Presentation Martin Randers

A dual of the rectangle-segmentation problem for binary matrices

Midterm 2 Sample solution

Video-rate Image Segmentation by means of Region Splitting and Merging

PARALLEL AND DISTRIBUTED COMPUTING

Matrices and Systems of Equations

An Event Structuring Approach to Real-Time Design Peter Gorm Larsen Abstract IFAD { Institute of Applied Computer Science Munkebjergvnget 17, DK-5230

Agenda & Reading. Class Exercise. COMPSCI 105 SS 2012 Principles of Computer Science. Arrays

Compilation

George Boole. IT 3123 Hardware and Software Concepts. Switching Algebra. Boolean Functions. Boolean Functions. Truth Tables

LETKF compared to 4DVAR for assimilation of surface pressure observations in IFS

Lists in Lisp and Scheme

CMSC 430, Practice Problems 1 (Solutions)

12-B FRACTIONS AND DECIMALS

Algorithm Design (5) Text Search

Heuristics for Thelen s Prime Implicant Method 1

Transcription:

LR() nlysis Drwcks of LR(). Look-hed symols s eplined efore, concerning LR(), it is possile to consult the net set to determine, in the reduction sttes, for which symols it would e possile to perform reductions. The key concept is the look-hed symol. Using this symol will llow us to er in mind, together with the input symol tht is eing studied, the net one tht ppers in the input. ecuse this symol will lso e used in lter step, it receives the nme of look-hed symol. In LR(), when we reduced rule R in stte s only for the elements in the net set, tht ction is like considering ll the look-hed symols for R in ll the possile sttes. LR() nlysis Drwcks of LR(): emple Rememer the ugmented grmmr: () () () () () () LR() nlysis Drwcks of LR(): emple We hve seen n emple grmmr which is not LR(): () () () () () this grmmr genertes the following lnguge: {} { n n n } LR() nlysis Drwcks of LR(): emple Deterministic finite utomt with the trnsitions s s s s s s s s s s

LR() nlysis Drwcks of LR(): emple nd this ws the nlysis tle for the LR() grmmr, with the conflict s s cc () () () () () () s /s s r r ction LR() nlysis Drwcks of LR(): emple The following ws the ugmented grmmr: () () + () * () i LR() nlysis Drwcks of LR(): emple The lst emple seen ws n emple of n miguous grmmr which ws not LR(). () + () * () i LR() nlysis Drwcks of LR(): emple Rememer the trnsition digrm in the LR() utomt () () + () * () i

LR() nlysis Drwcks of LR(): emple nd the LR() mtri showing the conflicts * + s () () + () * () i s r/s s r/s s s cc r r/s r/s r ction The grmmr is not LR() LR() nlysis ttes of the utomt in n LR() nlyser: introductory emple The emple used to illustrte LR() nd LLR() grmmrs will e the following: {, n n n } () () () () () This is not the simplest grmmr we cn uild for this lnguge, ut it is good emple, ecuse: It is not LR() It is LR() It is LLR, ut the utomt otined with this method will e different thn the one otined for n LR() prser We shll see, in this introductory emple, the initil stte s nd the trnsition from s to s. LR() nlysis Introduction to LR(k) with k= In the nlysis, t ech step, we shll tke into considertion: The current symol tht is eing treted The k symols tht cn follow it (k look-hed symols). ch stte in the utomt will hve severl copies, s mny s possile sequences of k symols tht cn follow the current stte. LR() nlysis Look-hed symols in n LR() nlyser: introductory emple For ech stte, we shll need to clculte the set of possile look-hed symols. This process cn e incorported to the construction of the utomt. It will suffice with: pecifying procedure for clculting ll the look-hed symols in ll the configurtions in ech stte. The new sttes will dd eplicitly, to ech configurtion, the set of lookhed symols tht re vlid, using the following nottion: s i = { <configurtion> {<look-hed> j }, <configurtion> i {<look-hed> ji }, <configurtion> n {<look-hed> jn } } i

LR() nlysis Look-hed symols in n LR() nlyser: introductory emple Considering the initil stte, s in LR() nd LR(), it ws clculted s the closure of the following configurtion: is the old iom, the non-terminl symol to which we should derive the complete derivtion tree fter we finish the nlysis. Therefore, the only look-hed symol tht we should epect t this position is the endof-progrm symol () Therefore, tht configurtion in the initil stte will hve the set of lookhed symols {} The net digrm shows this emple. LR() nlysis Look-hed symols in n LR() nlyser: introductory emple We cn continue the closure with the rules for : s ={ {}, {}, {}, {}, {}} s efore, ecuse ws t the end of the rule, fter the we my find nything tht we could find fter the (the look-hed symols for tht configurtion): {} The sme rgumenttion cn e followed to show tht the lookhed symols for the lst configurtion to e dded to this stte is lso {}: s ={ {}, {}, {}, {}, {}, {}} LR() nlysis Look-hed symols in n LR() nlyser: introductory emple Furthermore, the initil stte will contin the closure of the configurtion For clculting closures, we need to clculte the look-hed symols for ech of the new configurtions dded: This cse will e solved with the help of the first nd net sets. We shll use the prts of the right-hnd sides of the non-terminl symol tht follows the dot. For instnce, in the initil stte s s = { {}, {}, {}} the two new configurtions dded cn hve, s look-hed, nything tht could pper fter the in ecuse the ws t the end of the rule, nd the look-hed symol for tht rule ws, the look-hed symols for the new configurtions re the sme. LR() nlysis Look-hed symols in n LR() nlyser: introductory emple Deterministic Finite utomt with trnsitions s

LR() nlysis Look-hed symols in n LR() nlyser: introductory emple Deterministic Finite utomt with trnsitions s {} {} {} {} {} {} LR() nlysis Look-hed symols in n LR() nlyser: introductory emple The closure of {} implies the inclusion of two new configurtions: s this is the cse, we proly hve to chnge the sets of lookhed symols, s follows: The closure of {} forces us to keep the hypothesis tht we might now find ny right-hnd side of. On the other hnd, fter processing we shll lso need to shift nd, only fter we hve found the, we shll e prepred to reduce only in the presence of the look-hed symols in the set {}. This mens tht the three configurtions dded to the closure of {}, tht is,, or, will need to keep s look-hed symol, ecuse tht ppers right fter the ( {}). LR() nlysis Look-hed symols in n LR() nlyser: introductory emple Let us continue the emple with trnsition etween two sttes: gin, the closures will e solved with the help of the first nd net sets. For instnce, from the initil stte s s = { {}, {}, {}, {}, {}, {}} When we clculte s s the resulting stte of go_to(s,), the underlined configurtion cn e shifted to {} LR() nlysis Look-hed symols in n LR() nlyser: introductory emple In summry, with respect to the stte s, ecuse of the symol, oth hve the look-hed symol : {} {} The presence of {} in s forces us to etend the closure with ll the right-hnd sides of. The sitution in this cse is different, ecuse there is no symol fter the in the rule ( (*){}) In this cse, s in s efore, the closure does not modifies the set of look-hed symols, nd the element which will e look-hed symol of the configurtion will e {}

LR() nlysis Look-hed symols in n LR() nlyser: introductory emple o we cn conclude tht s = { {}, {}, {}, {} } s we cn see in the following digrm: LR() nlysis Look-hed symols in n LR() nlyser: introductory emple Deterministic Finite utomt with trnsitions s {} {} {} {} {} {} s {} {} {} {} LR() nlysis Look-hed symols in n LR() nlyser: introductory emple Deterministic Finite utomt with trnsitions s {} {} {} {} {} {} LR() nlysis Look-hed symols in n LR() nlyser: formlistion Formlly, to clculte the look-hed symols for the sttes trnsitions digrm, The initil configurtion in the initil stte hve the following look-hed symols: {} For clculting s j =closure(s i ) for the elements s i of the form P α Nβ{σ,...,σ n },, N we need to dd net(n), clculted using the previous rule, s look-hed symol for ll the new configurtions N... This net(n) set will e first(β{σ,...,σ n }) net(p) if β{σ,...,σ n } * λ Rememer, from the clcultion of the net set, tht, if β cn derive the empty word, we hve to dd not only first(β) to the set net(n), ut lso first(σ ), where σ is the symol tht follows β in the right-hnd side of the rule, nd net(p), if β is the lst symol in the right-hnd side!!!!

LR() nlysis Introductory eercise uild the LR() nlysis tle for the following grmmr tht genertes lnguge L={, n n n } () () () () () Use them to nlyse the following two strings: The first step is to otin the ugmented grmmr: () () () () () LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} {} {} {} {} {} first()={} () LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} s {} {} {} {} {} {} first()={} s {} s {} {} {} {} {} {} s {} first()={}

LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} s {} s {} {} {} {} {} {} s {} LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} s {} s {} {} {} {} {} {} s {} s {} {} {} {} {} {} first()={} first()={} first()={} first()={} LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} s {} s {} {} {} {} {} {} s {} {} {} LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} s {} s {} {} {} {} {} {} s {} s s {} {} {} {} {} {} {} first()={} first()={} first()={} first()={} s s s

LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} s {} s {} {} {} {} {} {} s {} s s {} {} {} {} {} s {} {} {} {} {} {} LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} s {} s {} {} {} {} {} {} s s {} s {} {} {} {} s {} s s {} {} {} {} {} {} {} s {} first()={} first()={} first()={} first()={} first()={} first()={} first()={} first()={} LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} s {} s {} {} {} {} {} {} s {} s s {} {} {} {} {} s {} {} {} {} {} {} s {} LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} s {} s {} s {} {} {} {} {} {} s s {} s {} {} {} {} s {} s s {} {} {} {} {} {} {} s {} first()={} first()={} first()={} first()={} first()={} first()={} first()={} first()={} s s

LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} s {} s {} s {} {} {} {} {} {} s s {} s {} {} {} {} s {} s s {} {} {} {} {} {} {} s {} LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} s {} s {} s {} {} {} {} {} {} s s {} s {} {} {} {} s {} s s {} {} {} {} {} {} {} s {} first()={} first()={} first()={} first()={} {} first()={} first()={} first()={} first()={} {} s s LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} s {} s {} s {} {} {} {} {} {} s s {} s s {} {} {} {} {} s s {} {} {} {} {} {} {} s {} LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} s {} s {} s {} {} {} {} {} {} s s {} s {} {} {} {} s {} s s {} {} {} {} {} {} {} s {} first()={} first()={} first()={} first()={} {} first()={} first()={} first()={} first()={} {} s s

LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s {} s {} {} {} {} {} {} s s {} {} {} s {} s s {} {} {} {} {} s {} s s {} {} {} {} {} s {} first()={} first()={} first()={} first()={} {} s {} s LR() nlysis Constructing LR() nlysis tles: method hifts in the tle: It is the sme s in LR() They cn e otined y following the trnsitions in the tle. If the utomt cn go from s i to s j y mens of symol X, then we shll dd the following ction: sj i X yntctic_tle[i,x]= j i X Reductions in the tle: In the cells for the sttes which contin reduction configurtions, of the form γ {σ,...,σ n } we hve to dd the reduction of the rule γ only in the columns for their look-hed non-terminl symols, i.e., {σ,...,σ n }. Therefore, this step is different to tht in LR() LR() nlysis Constructing LR() nlysis tles Deterministic Finite utomt with trnsitions s s {} {} {} {} {} {} {} s s {} {} {} s {} s s {} {} {} {} {} s s {} {} s {} s {} {} {} {} s {} first()={} first()={} first()={} first()={} {} s {} s LR() nlysis Constructing LR() nlysis tles: method ccepttion: It is the sme s in LR() nlysers If stte s i hs trnsition with the terminl symol to the finl stte with the configurtion iom iom, we hve to dd the ccept ction to yntctic_tle[i,]. Is it possile to find lterntive techniques for ccepttion in LR() prsers. rror: It is the sme s in LR() ll the empty cells hve ssocited the error ction.

nlysis tle The following is n emple of nlysis with two strings: LR() nlysis Constructing LR() nlysis tles: method s s s cc r s s r ction LR() nlysis: eercise {, n n n } s s cc r s s s () () () () () () r ction s s LR() nlysis: eercise {, n n n } s cc r s s s () () () () () () r ction LR() nlysis: eercise {, n n n } s cc r s s s () () () () () () r ction

s s LR() nlysis: eercise {, n n n } s cc r s s s () () () () () () r ction LR() nlysis: eercise {, n n n } s cc r s s s () () () () () () r ction s s LR() nlysis: eercise {, n n n } s cc r s s s () () () () () () r ction LR() nlysis: eercise {, n n n } s cc r s s s () () () () () () r ction

s s LR() nlysis: eercise {, n n n } s cc r s s s () () () () () () r ction LR() nlysis: eercise {, n n n } s cc r s s s () () () () () () r ction s s LR() nlysis: eercise {, n n n } s cc r s s s () () () () () () ction LR() nlysis: eercise {, n n n } s cc r s s s () () () () () () r ction

s s LR() nlysis: eercise {, n n n } s cc r s s s () () () () () () r ction LR() nlysis: eercise {, n n n } s cc r s s s () () () () () () r ction s s LR() nlysis: eercise {, n n n } s cc r s s s () () () () () () r ction LR() nlysis: eercise {, n n n } s cc r s s s () () () () () () r ction

LR() nlysis: eercise {, n n n } s s cc r s s s () () () () () () r ction LR(k) nlysis Generlistion to k look-hed symols (k > ) This sme technique cn e etended to consider ny numer of lookhed symols. This generlistion is out of the scope of this course. LR() nlysis vlution Power: It cn e shown tht LR() is the most powerful nlysis lgorithm mongst those tht nlyse the string from left to right using just look-hed symol. fficiency: s cn e oserved from the emples, there re considerly more sttes in LR() nlysers thn in LR() nlysers.