SlideShare a Scribd company logo
BOTTOM-UP PARSING
Bottom-Up Parsing
o Bottom-Up Parser : Constructs a parse tree for an input string
beginning at the leaves(the bottom) and working up towards the
root(the top)
o We can think of this process as one of “reducing” a string w to the start
symbol of a grammar
o Bottom-up parsing is also known as shift-reduce parsing because its
two main actions are shift and reduce.
 At each shift action, the current symbol in the input string is pushed to
a stack.
At each reduction step, the symbols at the top of the stack (this symbol
sequence is the right side of a production) will replaced by the non-
terminal at the left side of that production.
Shift-Reduce Parsing
o A shift-reduce parser tries to reduce the given input string into the
starting symbol.
a string  the starting symbol
reduced to
o At each reduction step, a substring of the input matching to the right
side of a production rule is replaced by the non-terminal at the left side
of that production rule.
o If the substring is chosen correctly, the right most derivation of that
string is created in the reverse order.
Rightmost Derivation: S  
Shift-Reduce Parser finds:   ...  S
rm
rm
rm
*
Shift–Reduce Parsing-Example
o Consider the grammar Input string : abbcde
S aABe aAbcde
A Abc | b aAde  reduction
B d aABe
S
We can scan abbcde looking for a substring that matches the right side of some
production.The substrings b and d qualify.Let us choose left most b and replace it by
A,the left side of the production Ab;we thus obtain the string aAbcde.Now the
substrings Abc,b and d match the right side of some production.Although b is the
leftmost substring that matches the right side of the some production,we choose to
replace the substring Abc by A,the left side of the production AAbc.We obtain
aAde.Then replacing d by B,and then replacing the entire string by S.Thus,by a
sequence of four reductions we are able to reduce abbcde to S
Shift–Reduce Parsing-Example
o These reductions infact trace out the following right-most derivation in
reverse
S  aABe  aAde  aAbcde  abbcde
o How do we know which substring to be replaced at each reduction step?
rm rm rm rm
Right Sentential Forms
Handle
rm rm
*
o Informally, a “handle” of a string is a substring that matches the right side
of the production,and whose reduction to nonterminal on the left side of the
production represents one step along the reverse of a rightmost derivation
▫ But not every substring matches the right side of a production rule is handle.
o Formally , a “handle” of a right sentential form γ ( ) is a production
rule A   and a position of  where the string  may be found and replaced
by A to produce the previous right-sentential form in a rightmost
derivation of .
S  A  
then Aβ in the position following α is a handle of αβω
o The string  to the right of the handle contains only terminal symbols.
Example
o Consider the example discussed in the beginning,abbcde is a right
sentential form whose handle is Ab at position 2.Likewise,aAbcde is a
right sentential form whose handle is AAbc at position 2.
o Sometimes we say “the substring β is a handle of αβω” if the
position of β and the production Aβ we have in mind are clear.
Handle Pruning
o A rightmost derivation in reverse can be obtained by “handle pruning”.That
is,we start with a string of terminals w that we wish to parse.If ω is a
sentence of grammar at hand,then ω = γ,where γn is the nth right-sentential
form of some as yet unknown rightmost derivation
S = 0  1  2  ...  n-1  n= 
Input string
rm rm rm rm rm
Handle Pruning
S = 0  1  2  ...  n-1  n= 
o Start from n, find a handle Ann in n,
and replace n in by An to get n-1.
o Then find a handle An-1n-1 in n-1,
and replace n-1 in by An-1 to get n-2.
o Repeat this, until we reach S.
rm rm rm rm
rm
A Shift-Reduce Parser
E  E+T | T Right-Most Derivation of id+id*id
T  T*F | F E  E+T  E+T*F  E+T*id  E+F*id
F  (E) | id  E+id*id  T+id*id  F+id*id  id+id*id
Right-Most Sentential form HANDLE Reducing Production
id+id*id
F+id*id
T+id*id
E+id*id
E+F*id
E+T*id
E+T*F
E+T
E
id
F
T
id
F
Id
T*F
E+T
Fid
TF
ET
Fid
TF
Fid
TT*F
EE+T
A Stack Implementation of a Shift-Reduce Parser
o There are four possible actions of a shift-parser action:
1.Shift : The next input symbol is shifted onto the top of the stack.
2.Reduce: Replace the handle on the top of the stack by the non-terminal.
3.Accept: Successful completion of parsing.
4.Error: Parser discovers a syntax error, and calls an error recovery routine.
o Initial stack just contains only the end-marker $.
o The end of the input string is marked by the end-marker $.
A Stack Implementation of A Shift-Reduce Parser
Stack Input Action
$
$id
$F
$T
$E
$E+
$E+id
$E+F
$E+T
$E+T*
$E+T*id
$E+T*F
$E+T
$E
id+id*id$shift
+id*id$
+id*id$
+id*id$
+id*id$
Id*id$
*id$
*id$
*id$
id$
$
$
$
$
Reduce by Fid
Reduce by TF
Reduce by ET
Shift
Shift
Reduce by Fid
Reduce by TF
Shift
Shift
Reduce by Fid
Reduce by TT*F
Reduce by E E+T
Accept
Parse Tree
E 8
E 3 T 7
+
T 5 F 6
*
F 4
F 1
T 2
id id
id

More Related Content

Similar to parsing in compiler design presentation .pptx

Assignment8
Assignment8Assignment8
Assignment8
Sunita Milind Dol
 
Reduction & Handle Pruning
Reduction & Handle PruningReduction & Handle Pruning
Reduction & Handle Pruning
MdAshikJiddney
 
Compiler Design Material 2
Compiler Design Material 2Compiler Design Material 2
Compiler Design Material 2
Dr. C.V. Suresh Babu
 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysis
Dattatray Gandhmal
 
Pcd(Mca)
Pcd(Mca)Pcd(Mca)
Pcd(Mca)
guestf07b62f
 
Pcd(Mca)
Pcd(Mca)Pcd(Mca)
Pcd(Mca)
guestf07b62f
 
PCD ?s(MCA)
PCD ?s(MCA)PCD ?s(MCA)
PCD ?s(MCA)
guestf07b62f
 
Principles of Compiler Design
Principles of Compiler DesignPrinciples of Compiler Design
Principles of Compiler Design
Babu Pushkaran
 
Assignment7
Assignment7Assignment7
Assignment7
Sunita Milind Dol
 
Ch06
Ch06Ch06
Ch06
Hankyo
 
Lecture9 syntax analysis_5
Lecture9 syntax analysis_5Lecture9 syntax analysis_5
Lecture9 syntax analysis_5
Mahesh Kumar Chelimilla
 
Cd2 [autosaved]
Cd2 [autosaved]Cd2 [autosaved]
Cd2 [autosaved]
BBDITM LUCKNOW
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
Tanzeela_Hussain
 
cfl2.pdf
cfl2.pdfcfl2.pdf
cfl2.pdf
TayNamBeng
 
LR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingLR(1) and SLR(1) parsing
LR(1) and SLR(1) parsing
R Islam
 
Parsing
ParsingParsing
lec02-Syntax Analysis and LL(1).pdf
lec02-Syntax Analysis and LL(1).pdflec02-Syntax Analysis and LL(1).pdf
lec02-Syntax Analysis and LL(1).pdf
wigewej294
 
Control chap7
Control chap7Control chap7
Control chap7
Mohd Ashraf Shabarshah
 
Turing machine-TOC
Turing machine-TOCTuring machine-TOC
Turing machine-TOC
Maulik Togadiya
 
Mathematical Statistics Assignment Help
Mathematical Statistics Assignment HelpMathematical Statistics Assignment Help
Mathematical Statistics Assignment Help
Excel Homework Help
 

Similar to parsing in compiler design presentation .pptx (20)

Assignment8
Assignment8Assignment8
Assignment8
 
Reduction & Handle Pruning
Reduction & Handle PruningReduction & Handle Pruning
Reduction & Handle Pruning
 
Compiler Design Material 2
Compiler Design Material 2Compiler Design Material 2
Compiler Design Material 2
 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysis
 
Pcd(Mca)
Pcd(Mca)Pcd(Mca)
Pcd(Mca)
 
Pcd(Mca)
Pcd(Mca)Pcd(Mca)
Pcd(Mca)
 
PCD ?s(MCA)
PCD ?s(MCA)PCD ?s(MCA)
PCD ?s(MCA)
 
Principles of Compiler Design
Principles of Compiler DesignPrinciples of Compiler Design
Principles of Compiler Design
 
Assignment7
Assignment7Assignment7
Assignment7
 
Ch06
Ch06Ch06
Ch06
 
Lecture9 syntax analysis_5
Lecture9 syntax analysis_5Lecture9 syntax analysis_5
Lecture9 syntax analysis_5
 
Cd2 [autosaved]
Cd2 [autosaved]Cd2 [autosaved]
Cd2 [autosaved]
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
cfl2.pdf
cfl2.pdfcfl2.pdf
cfl2.pdf
 
LR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingLR(1) and SLR(1) parsing
LR(1) and SLR(1) parsing
 
Parsing
ParsingParsing
Parsing
 
lec02-Syntax Analysis and LL(1).pdf
lec02-Syntax Analysis and LL(1).pdflec02-Syntax Analysis and LL(1).pdf
lec02-Syntax Analysis and LL(1).pdf
 
Control chap7
Control chap7Control chap7
Control chap7
 
Turing machine-TOC
Turing machine-TOCTuring machine-TOC
Turing machine-TOC
 
Mathematical Statistics Assignment Help
Mathematical Statistics Assignment HelpMathematical Statistics Assignment Help
Mathematical Statistics Assignment Help
 

Recently uploaded

University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
soxrziqu
 
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging DataPredictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Kiwi Creative
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
apvysm8
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
Sm321
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
aqzctr7x
 
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
zsjl4mimo
 
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
g4dpvqap0
 
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
g4dpvqap0
 
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
nyfuhyz
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
Sachin Paul
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
Roger Valdez
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
roli9797
 
Experts live - Improving user adoption with AI
Experts live - Improving user adoption with AIExperts live - Improving user adoption with AI
Experts live - Improving user adoption with AI
jitskeb
 
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdfUdemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Fernanda Palhano
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
nuttdpt
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
jerlynmaetalle
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
manishkhaire30
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
Social Samosa
 

Recently uploaded (20)

University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
 
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging DataPredictably Improve Your B2B Tech Company's Performance by Leveraging Data
Predictably Improve Your B2B Tech Company's Performance by Leveraging Data
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
 
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
 
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证如何办理
 
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
一比一原版(UMN文凭证书)明尼苏达大学毕业证如何办理
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
 
Analysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performanceAnalysis insight about a Flyball dog competition team's performance
Analysis insight about a Flyball dog competition team's performance
 
Experts live - Improving user adoption with AI
Experts live - Improving user adoption with AIExperts live - Improving user adoption with AI
Experts live - Improving user adoption with AI
 
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdfUdemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
一比一原版(UCSB文凭证书)圣芭芭拉分校毕业证如何办理
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
 

parsing in compiler design presentation .pptx

  • 2. Bottom-Up Parsing o Bottom-Up Parser : Constructs a parse tree for an input string beginning at the leaves(the bottom) and working up towards the root(the top) o We can think of this process as one of “reducing” a string w to the start symbol of a grammar o Bottom-up parsing is also known as shift-reduce parsing because its two main actions are shift and reduce.  At each shift action, the current symbol in the input string is pushed to a stack. At each reduction step, the symbols at the top of the stack (this symbol sequence is the right side of a production) will replaced by the non- terminal at the left side of that production.
  • 3. Shift-Reduce Parsing o A shift-reduce parser tries to reduce the given input string into the starting symbol. a string  the starting symbol reduced to o At each reduction step, a substring of the input matching to the right side of a production rule is replaced by the non-terminal at the left side of that production rule. o If the substring is chosen correctly, the right most derivation of that string is created in the reverse order. Rightmost Derivation: S   Shift-Reduce Parser finds:   ...  S rm rm rm *
  • 4. Shift–Reduce Parsing-Example o Consider the grammar Input string : abbcde S aABe aAbcde A Abc | b aAde  reduction B d aABe S We can scan abbcde looking for a substring that matches the right side of some production.The substrings b and d qualify.Let us choose left most b and replace it by A,the left side of the production Ab;we thus obtain the string aAbcde.Now the substrings Abc,b and d match the right side of some production.Although b is the leftmost substring that matches the right side of the some production,we choose to replace the substring Abc by A,the left side of the production AAbc.We obtain aAde.Then replacing d by B,and then replacing the entire string by S.Thus,by a sequence of four reductions we are able to reduce abbcde to S
  • 5. Shift–Reduce Parsing-Example o These reductions infact trace out the following right-most derivation in reverse S  aABe  aAde  aAbcde  abbcde o How do we know which substring to be replaced at each reduction step? rm rm rm rm Right Sentential Forms
  • 6. Handle rm rm * o Informally, a “handle” of a string is a substring that matches the right side of the production,and whose reduction to nonterminal on the left side of the production represents one step along the reverse of a rightmost derivation ▫ But not every substring matches the right side of a production rule is handle. o Formally , a “handle” of a right sentential form γ ( ) is a production rule A   and a position of  where the string  may be found and replaced by A to produce the previous right-sentential form in a rightmost derivation of . S  A   then Aβ in the position following α is a handle of αβω o The string  to the right of the handle contains only terminal symbols.
  • 7. Example o Consider the example discussed in the beginning,abbcde is a right sentential form whose handle is Ab at position 2.Likewise,aAbcde is a right sentential form whose handle is AAbc at position 2. o Sometimes we say “the substring β is a handle of αβω” if the position of β and the production Aβ we have in mind are clear.
  • 8. Handle Pruning o A rightmost derivation in reverse can be obtained by “handle pruning”.That is,we start with a string of terminals w that we wish to parse.If ω is a sentence of grammar at hand,then ω = γ,where γn is the nth right-sentential form of some as yet unknown rightmost derivation S = 0  1  2  ...  n-1  n=  Input string rm rm rm rm rm
  • 9. Handle Pruning S = 0  1  2  ...  n-1  n=  o Start from n, find a handle Ann in n, and replace n in by An to get n-1. o Then find a handle An-1n-1 in n-1, and replace n-1 in by An-1 to get n-2. o Repeat this, until we reach S. rm rm rm rm rm
  • 10. A Shift-Reduce Parser E  E+T | T Right-Most Derivation of id+id*id T  T*F | F E  E+T  E+T*F  E+T*id  E+F*id F  (E) | id  E+id*id  T+id*id  F+id*id  id+id*id Right-Most Sentential form HANDLE Reducing Production id+id*id F+id*id T+id*id E+id*id E+F*id E+T*id E+T*F E+T E id F T id F Id T*F E+T Fid TF ET Fid TF Fid TT*F EE+T
  • 11. A Stack Implementation of a Shift-Reduce Parser o There are four possible actions of a shift-parser action: 1.Shift : The next input symbol is shifted onto the top of the stack. 2.Reduce: Replace the handle on the top of the stack by the non-terminal. 3.Accept: Successful completion of parsing. 4.Error: Parser discovers a syntax error, and calls an error recovery routine. o Initial stack just contains only the end-marker $. o The end of the input string is marked by the end-marker $.
  • 12. A Stack Implementation of A Shift-Reduce Parser Stack Input Action $ $id $F $T $E $E+ $E+id $E+F $E+T $E+T* $E+T*id $E+T*F $E+T $E id+id*id$shift +id*id$ +id*id$ +id*id$ +id*id$ Id*id$ *id$ *id$ *id$ id$ $ $ $ $ Reduce by Fid Reduce by TF Reduce by ET Shift Shift Reduce by Fid Reduce by TF Shift Shift Reduce by Fid Reduce by TT*F Reduce by E E+T Accept Parse Tree E 8 E 3 T 7 + T 5 F 6 * F 4 F 1 T 2 id id id