SlideShare una empresa de Scribd logo
1 de 13
WELCOME TO A
JOURNEY TO
CS419

Dr. Hussien Sharaf
Computer Science Department

dr.sharaf@from-masr.com
Dr. Hussien M. Sharaf

LR PARSING


LR(1) parsing is a technique of bottom-up parsing.







L: scan input string from left to right.
R: uses right most derivation.
1: uses one token ahead to decide which rule to use for
reduction.

Consists of:




Parser stack: that holds grammar symbols: non-terminals and
tokens.
Parsing table: that specifies the parser actions (Shift,
Reduce, Accept, Error).
Driver function: that interacts with parser stack, parsing table, and
scanner.
Output
Scanner

Next
token

Parser
driver

Parsing
table

Parsing stack
Dr. Hussien M. Sharaf

BOTTOM-UP PARSER ACTIONS







Shift: parser shifts the next token on the
parser stack.
Reduce: parser reduces the RHS of a
production to its LHS.
Accept: parsed successfully.
Error: failure.
Dr. Hussien M. Sharaf

BOTTOM-UP PARSING
A parser is a bottom-up if it traverse a parse
tree bottom up.
 A right most derivation is applied to each
step.
 Bottom-up parsers are preferred in practice.
 They do not need left factoring.
 It reduces the input string to the starting
symbol by using the reverse of production
rules.

Dr. Hussien M. Sharaf

BOTTOM-UP (CONT.)
Consider the following grammar:
E→T+E|T
T → id * T | id | (E)
; Input string: id + id * id


Input string
id * id + id
id * T + id
T + id
T+T
T+E
E

Rules
T → id
T → id * T
T → id
E→T
E→T+E

Is there another parsing for the same input string
using bottom up algorithm?
Dr. Hussien M. Sharaf

BOTTOM-UP (CONT.)
Input string
id * id + id
id * id + T
id * T + T
T+T
T+E
E




Rules
T → id
T → id
T → id * T
E→T
E→T+E

Is there another parsing for the same input
string using bottom up algorithm?
What happens if “T + T” was reduced to “E +
T”? Would the parsing still continue?
Dr. Hussien M. Sharaf

PARSING TREE
E
Input string
id * id + id
id * id + T
id * T + T
T+T
T+E
E

E

T
T

T

i
d

*

i
d

+

i
d
Dr. Hussien M. Sharaf

PARSING TREE
Consider the following grammar:
E→T+E|T
T → id * T | id | (E)
; Input string: id + id * id


But what if we start with reducing the first id to T as
follows:
Input string
id * id + id
T * id + id


Rules

T → id

We would be stuck with “T * id” or “T * T” or “T * E”
Dr. Hussien M. Sharaf

CONFUSING POINTS


How does the parser choose whether to shift
or reduce?
 General

strategy is to reduce whenever it is
possible otherwise shift.



How does the parser handles the situations
when there is more than one choice for
reducing?
 Even

non-ambigious grammars can cause this
situation. The parser uses back-tracking to
decide which choice is correct.
Dr. Hussien M. Sharaf

Example 1
Consider the following grammar….
A(A) | a

Stack

Input

Action

$

((a))$

Shift

$(

(a))$

Shift

$((

a))$

Shift

$((a

))$

Reduce A a

$((A

))$

Shift

$((A)

)$

Reduce A (A)

$(A

)$

Shift

$(A)

$

Reduce A (A)

$A

$

Accept
Dr. Hussien M. Sharaf

LR Parsing Example 2
Stack

Input

Action

$
$ id
$T
$E
$E+
$E+(
$ E + ( id
$E+(T
$E+(E
$E+(E+
$ E + ( E + id
$E+(E+T
$E+(E
$E+(E)
$E+T
$E

id + ( id + id ) $
+ ( id + id ) $
+ ( id + id ) $
+ ( id + id ) $
( id + id ) $
id + id ) $
+ id ) $
+ id ) $
+ id ) $
id ) $
)$
)$
)$
$
$
$

S
R, G3
R, G2
S
S
S
R, G3
R, G2
S
S
R, G3
R, G1
S
R, G4
R, G1
A

G1:
G2:
G3:
G4:

E
E
T
T






E+T
T
id
(E)
Dr. Hussien M. Sharaf

Example 3
Dr. Hussien M. Sharaf

THANK YOU

Más contenido relacionado

La actualidad más candente (20)

Left factor put
Left factor putLeft factor put
Left factor put
 
LL(1) parsing
LL(1) parsingLL(1) parsing
LL(1) parsing
 
Module 11
Module 11Module 11
Module 11
 
Lecture 07 08 syntax analysis-4
Lecture 07 08 syntax analysis-4Lecture 07 08 syntax analysis-4
Lecture 07 08 syntax analysis-4
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
Top down parsing(sid) (1)
Top down parsing(sid) (1)Top down parsing(sid) (1)
Top down parsing(sid) (1)
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
 
Types of Parser
Types of ParserTypes of Parser
Types of Parser
 
Predictive parser
Predictive parserPredictive parser
Predictive parser
 
First and follow set
First and follow setFirst and follow set
First and follow set
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Bottomupparser
BottomupparserBottomupparser
Bottomupparser
 
Bottom up parser
Bottom up parserBottom up parser
Bottom up parser
 
Compiler: Syntax Analysis
Compiler: Syntax AnalysisCompiler: Syntax Analysis
Compiler: Syntax Analysis
 
Topdown parsing
Topdown parsingTopdown parsing
Topdown parsing
 
Operator precedence
Operator precedenceOperator precedence
Operator precedence
 
Parsing
ParsingParsing
Parsing
 
Parsing (Automata)
Parsing (Automata)Parsing (Automata)
Parsing (Automata)
 
Pcd(Mca)
Pcd(Mca)Pcd(Mca)
Pcd(Mca)
 

Destacado

Destacado (17)

Parsing
ParsingParsing
Parsing
 
Parsing example
Parsing exampleParsing example
Parsing example
 
Ch5a
Ch5aCh5a
Ch5a
 
1. pendahuluan kompilasi
1. pendahuluan kompilasi1. pendahuluan kompilasi
1. pendahuluan kompilasi
 
Pigeonhole
PigeonholePigeonhole
Pigeonhole
 
Bottomupparser
BottomupparserBottomupparser
Bottomupparser
 
Pigeonhole Principle
Pigeonhole PrinciplePigeonhole Principle
Pigeonhole Principle
 
Introduction to Parse
Introduction to ParseIntroduction to Parse
Introduction to Parse
 
Pigeonhole Principle,Cardinality,Countability
Pigeonhole Principle,Cardinality,CountabilityPigeonhole Principle,Cardinality,Countability
Pigeonhole Principle,Cardinality,Countability
 
Compiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR ParsingCompiler Components and their Generators - LR Parsing
Compiler Components and their Generators - LR Parsing
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Lecture7 syntax analysis_3
Lecture7 syntax analysis_3Lecture7 syntax analysis_3
Lecture7 syntax analysis_3
 
Lecture 06 syntax analysis 3
Lecture 06 syntax analysis 3Lecture 06 syntax analysis 3
Lecture 06 syntax analysis 3
 
Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2Lecture 05 syntax analysis 2
Lecture 05 syntax analysis 2
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Lecture 02 lexical analysis
Lecture 02 lexical analysisLecture 02 lexical analysis
Lecture 02 lexical analysis
 
LALR Parser Presentation ppt
LALR Parser Presentation pptLALR Parser Presentation ppt
LALR Parser Presentation ppt
 

Similar a Cs419 lec11 bottom-up parsing

Top down parsering and bottom up parsering.pptx
Top down parsering and bottom up parsering.pptxTop down parsering and bottom up parsering.pptx
Top down parsering and bottom up parsering.pptxLaibaFaisal3
 
Unitiv 111206005201-phpapp01
Unitiv 111206005201-phpapp01Unitiv 111206005201-phpapp01
Unitiv 111206005201-phpapp01riddhi viradiya
 
Similarity Search in High Dimensions via Hashing
Similarity Search in High Dimensions via HashingSimilarity Search in High Dimensions via Hashing
Similarity Search in High Dimensions via HashingMaruf Aytekin
 
Chapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materialsChapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materialsgadisaAdamu
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptxPython Homework Help
 
Quick and radix sort
Quick and radix sortQuick and radix sort
Quick and radix sortAaron Joaquin
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Languagevsssuresh
 
Bioinformatica 10-11-2011-t5-database searching
Bioinformatica 10-11-2011-t5-database searchingBioinformatica 10-11-2011-t5-database searching
Bioinformatica 10-11-2011-t5-database searchingProf. Wim Van Criekinge
 
Skiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingSkiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingzukun
 
Memorization of Various Calculator shortcuts
Memorization of Various Calculator shortcutsMemorization of Various Calculator shortcuts
Memorization of Various Calculator shortcutsPrincessNorberte
 
Syntactic analysis in NLP
Syntactic analysis in NLPSyntactic analysis in NLP
Syntactic analysis in NLPkartikaVashisht
 
VCE Unit 04vv.pptx
VCE Unit 04vv.pptxVCE Unit 04vv.pptx
VCE Unit 04vv.pptxskilljiolms
 
Open addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashingOpen addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashingHaripritha
 

Similar a Cs419 lec11 bottom-up parsing (20)

Top down parsering and bottom up parsering.pptx
Top down parsering and bottom up parsering.pptxTop down parsering and bottom up parsering.pptx
Top down parsering and bottom up parsering.pptx
 
Unitiv 111206005201-phpapp01
Unitiv 111206005201-phpapp01Unitiv 111206005201-phpapp01
Unitiv 111206005201-phpapp01
 
Chapter 4 ds
Chapter 4 dsChapter 4 ds
Chapter 4 ds
 
Similarity Search in High Dimensions via Hashing
Similarity Search in High Dimensions via HashingSimilarity Search in High Dimensions via Hashing
Similarity Search in High Dimensions via Hashing
 
Chapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materialsChapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materials
 
Introduction to Python Programming.pptx
Introduction to Python Programming.pptxIntroduction to Python Programming.pptx
Introduction to Python Programming.pptx
 
Quick and radix sort
Quick and radix sortQuick and radix sort
Quick and radix sort
 
Cd2 [autosaved]
Cd2 [autosaved]Cd2 [autosaved]
Cd2 [autosaved]
 
08 Hash Tables
08 Hash Tables08 Hash Tables
08 Hash Tables
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithm
 
Bioinformatica 10-11-2011-t5-database searching
Bioinformatica 10-11-2011-t5-database searchingBioinformatica 10-11-2011-t5-database searching
Bioinformatica 10-11-2011-t5-database searching
 
TamingStatistics
TamingStatisticsTamingStatistics
TamingStatistics
 
Skiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingSkiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sorting
 
Memorization of Various Calculator shortcuts
Memorization of Various Calculator shortcutsMemorization of Various Calculator shortcuts
Memorization of Various Calculator shortcuts
 
Syntactic analysis in NLP
Syntactic analysis in NLPSyntactic analysis in NLP
Syntactic analysis in NLP
 
VCE Unit 04vv.pptx
VCE Unit 04vv.pptxVCE Unit 04vv.pptx
VCE Unit 04vv.pptx
 
Data Structure
Data StructureData Structure
Data Structure
 
Open addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashingOpen addressing &amp rehashing,extendable hashing
Open addressing &amp rehashing,extendable hashing
 
Es272 ch2
Es272 ch2Es272 ch2
Es272 ch2
 

Más de Arab Open University and Cairo University

Más de Arab Open University and Cairo University (20)

Infos2014
Infos2014Infos2014
Infos2014
 
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
 
Model answer of compilers june spring 2013
Model answer of compilers june spring 2013Model answer of compilers june spring 2013
Model answer of compilers june spring 2013
 
Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013
 
Theory of computation Lec6
Theory of computation Lec6Theory of computation Lec6
Theory of computation Lec6
 
Lec4
Lec4Lec4
Lec4
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Setup python with eclipse
 
Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec7 cfg
 
Cs419 lec6 lexical analysis using nfa
Cs419 lec6   lexical analysis using nfaCs419 lec6   lexical analysis using nfa
Cs419 lec6 lexical analysis using nfa
 
Cs419 lec5 lexical analysis using dfa
Cs419 lec5   lexical analysis using dfaCs419 lec5   lexical analysis using dfa
Cs419 lec5 lexical analysis using dfa
 
Cs419 lec4 lexical analysis using re
Cs419 lec4   lexical analysis using reCs419 lec4   lexical analysis using re
Cs419 lec4 lexical analysis using re
 
Cs419 lec3 lexical analysis using re
Cs419 lec3   lexical analysis using reCs419 lec3   lexical analysis using re
Cs419 lec3 lexical analysis using re
 
Compilers Final spring 2013 model answer
 Compilers Final spring 2013 model answer Compilers Final spring 2013 model answer
Compilers Final spring 2013 model answer
 
Compilers midterm spring 2013 model answer
Compilers midterm spring 2013   model answerCompilers midterm spring 2013   model answer
Compilers midterm spring 2013 model answer
 

Último

Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 

Último (20)

Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 

Cs419 lec11 bottom-up parsing

  • 1. WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Computer Science Department dr.sharaf@from-masr.com
  • 2. Dr. Hussien M. Sharaf LR PARSING  LR(1) parsing is a technique of bottom-up parsing.     L: scan input string from left to right. R: uses right most derivation. 1: uses one token ahead to decide which rule to use for reduction. Consists of:    Parser stack: that holds grammar symbols: non-terminals and tokens. Parsing table: that specifies the parser actions (Shift, Reduce, Accept, Error). Driver function: that interacts with parser stack, parsing table, and scanner. Output Scanner Next token Parser driver Parsing table Parsing stack
  • 3. Dr. Hussien M. Sharaf BOTTOM-UP PARSER ACTIONS     Shift: parser shifts the next token on the parser stack. Reduce: parser reduces the RHS of a production to its LHS. Accept: parsed successfully. Error: failure.
  • 4. Dr. Hussien M. Sharaf BOTTOM-UP PARSING A parser is a bottom-up if it traverse a parse tree bottom up.  A right most derivation is applied to each step.  Bottom-up parsers are preferred in practice.  They do not need left factoring.  It reduces the input string to the starting symbol by using the reverse of production rules. 
  • 5. Dr. Hussien M. Sharaf BOTTOM-UP (CONT.) Consider the following grammar: E→T+E|T T → id * T | id | (E) ; Input string: id + id * id  Input string id * id + id id * T + id T + id T+T T+E E Rules T → id T → id * T T → id E→T E→T+E Is there another parsing for the same input string using bottom up algorithm?
  • 6. Dr. Hussien M. Sharaf BOTTOM-UP (CONT.) Input string id * id + id id * id + T id * T + T T+T T+E E   Rules T → id T → id T → id * T E→T E→T+E Is there another parsing for the same input string using bottom up algorithm? What happens if “T + T” was reduced to “E + T”? Would the parsing still continue?
  • 7. Dr. Hussien M. Sharaf PARSING TREE E Input string id * id + id id * id + T id * T + T T+T T+E E E T T T i d * i d + i d
  • 8. Dr. Hussien M. Sharaf PARSING TREE Consider the following grammar: E→T+E|T T → id * T | id | (E) ; Input string: id + id * id  But what if we start with reducing the first id to T as follows: Input string id * id + id T * id + id  Rules T → id We would be stuck with “T * id” or “T * T” or “T * E”
  • 9. Dr. Hussien M. Sharaf CONFUSING POINTS  How does the parser choose whether to shift or reduce?  General strategy is to reduce whenever it is possible otherwise shift.  How does the parser handles the situations when there is more than one choice for reducing?  Even non-ambigious grammars can cause this situation. The parser uses back-tracking to decide which choice is correct.
  • 10. Dr. Hussien M. Sharaf Example 1 Consider the following grammar…. A(A) | a Stack Input Action $ ((a))$ Shift $( (a))$ Shift $(( a))$ Shift $((a ))$ Reduce A a $((A ))$ Shift $((A) )$ Reduce A (A) $(A )$ Shift $(A) $ Reduce A (A) $A $ Accept
  • 11. Dr. Hussien M. Sharaf LR Parsing Example 2 Stack Input Action $ $ id $T $E $E+ $E+( $ E + ( id $E+(T $E+(E $E+(E+ $ E + ( E + id $E+(E+T $E+(E $E+(E) $E+T $E id + ( id + id ) $ + ( id + id ) $ + ( id + id ) $ + ( id + id ) $ ( id + id ) $ id + id ) $ + id ) $ + id ) $ + id ) $ id ) $ )$ )$ )$ $ $ $ S R, G3 R, G2 S S S R, G3 R, G2 S S R, G3 R, G1 S R, G4 R, G1 A G1: G2: G3: G4: E E T T     E+T T id (E)
  • 12. Dr. Hussien M. Sharaf Example 3
  • 13. Dr. Hussien M. Sharaf THANK YOU