SlideShare ist ein Scribd-Unternehmen logo
1 von 14
NADAR SARASWATHI COLLEGE OF
ARTS AND SCIENCE,
VADAPUTHUPATTI,THENI.
DEPARTEMENT OF COMPUTER SCIENCE
LR PARSERS
SUBMITTED BY:
S.AISHWARYA LAKSHMI I MSC(CS)
LR parser
 LR parser is a bottom-up parser for context-free grammar that is
very generally used by computer programming language compiler and
other associated tools.
 LR parser reads their input from left to right and produces a
right-most derivation.
 It is called a Bottom-up parser because it attempts to reduce the
top-level grammar productions by building up from the leaves.
 LR parsers are the most powerful parser of all deterministic
parsers in practice.
Description of LR parser :
 The term parser LR(k) parser, here the L refers to the left-to-
right scanning,
 R refers to the rightmost derivation in reverse and k refers to the
number of unconsumed “look ahead” input symbols that are used in
making parser decisions.
 Typically, k is 1 and is often omitted.
 A context-free grammar is called LR (k) if the LR (k) parser exists
for it.
 This first reduces the sequence of tokens to the left.
 But when we read from above, the derivation order first extends
to non-terminal.
Description of LR parser :
 The stack is empty, and we are looking to reduce the
rule by S’→S$.
 Using a “.” in the rule represents how many of the rules
are already on the stack.
 A dotted item, or simply, the item is a production rule
with a dot indicating how much RHS has so far been
recognized.
 Closing an item is used to see what production rules can
be used to expand the current structure.
Rules for LR parser :
 The rules of LR parser as follows.
 The first item from the given grammar rules adds itself
as the first closed set.
 If an object is present in the closure of the form A→ α.
β. γ,
 where the next symbol after the symbol is non-
terminal, add the symbol’s production rules where the
dot precedes the first item.
 Repeat steps (B) and (C) for new items added under (B).
LR parser algorithm :
 LR Parsing algorithm is the same for all the parser, but the parsing
table is different for each parser. It consists following components
as follows.
 Input Buffer –
It contains the given string, and it ends with a $ symbol.
 Stack –
The combination of state symbol and current input symbol is used
to refer to the parsing table in order to take the parsing decisions.
Parsing Table :
 Parsing table is divided into two parts- Action table and Go-To
table. The action table gives a grammar rule to implement the given
current state and current terminal in the input stream.
 There are four cases used in action table as follows.
 Shift Action- In shift action the present terminal is removed from
the input stream and the state n is pushed onto the stack, and it
becomes the new present state.
 Reduce Action- The number m is written to the output stream.
Parsing Table :
 The symbol m mentioned in the left-hand side of
rule m says that state is removed from the stack.
 The symbol m mentioned in the left-hand side of
rule m says that a new state is looked up in the goto
table and made the new current state by pushing it onto
the stack.
 R parsers are used to parse the large class of context
free grammars. This technique is called LR(k) parsing.
 L is left-to-right scanning of the input.
 R is for constructing a right most derivation in reverse.
Parsing Table :
 k is the number of input symbols of lookahead
that are used in making parsing decisions.
 There are three widely used algorithms
available for constructing an LR parser:
 SLR(l) – Simple LR
 Few number of states, hence very small table.
 Simple and fast construction.
 Works on smallest class of grammar.
Reasons for attractiveness of LR parser
 LR parsers can handle a large class of context-free
grammars.
 The LR parsing method is a most general non-back
tracking shift-reduce parsing method.
 An LR parser can detect the syntax errors as soon as
they can occur.
 LR grammars can describe more languages than LL
grammars.
Drawbacks of LR parsers
 It is too much work to construct LR parser by
hand. It needs an automated parser generator.
 If the grammar contains ambiguities or other
constructs then it is difficult to parse in a left-
to-right scan of the input.
Behavior of the LR parser
 1. If ACTION[sm, ai] = shift s. The parser executes the
shift move, it shifts the next state s onto the stack,
entering the configuration
a) Sm – the state on top of the stack.
b) ai– the current input symbol.
Behavior of the LR parser
 2. If ACTION[sm, ai] =reduce A—> β, then the parser
executes a reduce move, entering the configuration
(s0s1 … S(m-r)S, ai+l … an$)
a) where r is the length of β and s= GOTO[sm – r, A].
b) First popped r state symbols off the stack, exposing
state Sm-r·
THANK YOU!!!

Weitere ähnliche Inhalte

Was ist angesagt?

Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
Gerwin Ocsena
 

Was ist angesagt? (20)

Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
COMPILER DESIGN
COMPILER DESIGNCOMPILER DESIGN
COMPILER DESIGN
 
Syntactic analysis in NLP
Syntactic analysis in NLPSyntactic analysis in NLP
Syntactic analysis in NLP
 
Parsing
ParsingParsing
Parsing
 
CLR AND LALR PARSER
CLR AND LALR PARSERCLR AND LALR PARSER
CLR AND LALR PARSER
 
Lecture: Context-Free Grammars
Lecture: Context-Free GrammarsLecture: Context-Free Grammars
Lecture: Context-Free Grammars
 
COMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed TranslationCOMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed Translation
 
Compiler Design LR parsing SLR ,LALR CLR
Compiler Design LR parsing SLR ,LALR CLRCompiler Design LR parsing SLR ,LALR CLR
Compiler Design LR parsing SLR ,LALR CLR
 
Bottom up parser
Bottom up parserBottom up parser
Bottom up parser
 
LR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingLR(1) and SLR(1) parsing
LR(1) and SLR(1) parsing
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
Syntax and semantics of propositional logic
Syntax and semantics of propositional logicSyntax and semantics of propositional logic
Syntax and semantics of propositional logic
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Ch5a
Ch5aCh5a
Ch5a
 
Operator precedence
Operator precedenceOperator precedence
Operator precedence
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
LL(1) parsing
LL(1) parsingLL(1) parsing
LL(1) parsing
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
 
Hashing PPT
Hashing PPTHashing PPT
Hashing PPT
 

Ähnlich wie LR PARSE.pptx

Ähnlich wie LR PARSE.pptx (20)

compiler design.pdf
compiler design.pdfcompiler design.pdf
compiler design.pdf
 
COMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax AnalysisCOMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax Analysis
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsing
 
Bottom up parser
Bottom up parserBottom up parser
Bottom up parser
 
Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)
 
parsing.pptx
parsing.pptxparsing.pptx
parsing.pptx
 
07 top-down-parsing
07 top-down-parsing07 top-down-parsing
07 top-down-parsing
 
Lecture 12 Bottom-UP Parsing.pptx
Lecture 12 Bottom-UP Parsing.pptxLecture 12 Bottom-UP Parsing.pptx
Lecture 12 Bottom-UP Parsing.pptx
 
Pcd question bank
Pcd question bank Pcd question bank
Pcd question bank
 
Compiler design important questions
Compiler design   important questionsCompiler design   important questions
Compiler design important questions
 
Programming_Language_Syntax.ppt
Programming_Language_Syntax.pptProgramming_Language_Syntax.ppt
Programming_Language_Syntax.ppt
 
Chapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materialsChapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materials
 
Lecture 15 16
Lecture 15 16Lecture 15 16
Lecture 15 16
 
Introduction to R for beginners
Introduction to R for beginnersIntroduction to R for beginners
Introduction to R for beginners
 
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
 
Ch 2.pptx
Ch 2.pptxCh 2.pptx
Ch 2.pptx
 
Handout#02
Handout#02Handout#02
Handout#02
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 

Mehr von Aishwarya SenthilNathan (13)

cloud computing.pptx
cloud computing.pptxcloud computing.pptx
cloud computing.pptx
 
IOT.pptx
IOT.pptxIOT.pptx
IOT.pptx
 
women empowerment.pptx
women empowerment.pptxwomen empowerment.pptx
women empowerment.pptx
 
Digital Image Processing.pptx
Digital Image Processing.pptxDigital Image Processing.pptx
Digital Image Processing.pptx
 
Artifical Intelligence And Machine Learning Algorithum.pptx
Artifical Intelligence And Machine Learning Algorithum.pptxArtifical Intelligence And Machine Learning Algorithum.pptx
Artifical Intelligence And Machine Learning Algorithum.pptx
 
Cloud Computing.pptx
Cloud Computing.pptxCloud Computing.pptx
Cloud Computing.pptx
 
SENTIMENT ANALYSIS OF FEEDBACK DATA USING MACHINE LEARNING TECHNIQUE.pptx
SENTIMENT ANALYSIS OF FEEDBACK DATA USING MACHINE LEARNING TECHNIQUE.pptxSENTIMENT ANALYSIS OF FEEDBACK DATA USING MACHINE LEARNING TECHNIQUE.pptx
SENTIMENT ANALYSIS OF FEEDBACK DATA USING MACHINE LEARNING TECHNIQUE.pptx
 
2D Graphics animation - Bouncing ball(Python).pptx
2D Graphics animation - Bouncing ball(Python).pptx2D Graphics animation - Bouncing ball(Python).pptx
2D Graphics animation - Bouncing ball(Python).pptx
 
Growth Of IOT NETWORK.pptx
Growth Of IOT NETWORK.pptxGrowth Of IOT NETWORK.pptx
Growth Of IOT NETWORK.pptx
 
DATA MINING.pptx
DATA MINING.pptxDATA MINING.pptx
DATA MINING.pptx
 
Software Engineering.pptx
Software Engineering.pptxSoftware Engineering.pptx
Software Engineering.pptx
 
HUMANOID ROBOTS.pptx
HUMANOID ROBOTS.pptxHUMANOID ROBOTS.pptx
HUMANOID ROBOTS.pptx
 
APPLET.pptx
APPLET.pptxAPPLET.pptx
APPLET.pptx
 

Kürzlich hochgeladen

Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
amitlee9823
 
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in DammamAbortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
ahmedjiabur940
 
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
uodye
 
Just Call Vip call girls godhra Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls godhra Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls godhra Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls godhra Escorts ☎️9352988975 Two shot with one girl (...
gajnagarg
 
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
CHEAP Call Girls in Ashok Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Ashok Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Ashok Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Ashok Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
tufbav
 
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
amitlee9823
 
CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
amitlee9823
 

Kürzlich hochgeladen (20)

Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Sanjay Nagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Kothrud Call Me 7737669865 Budget Friendly No Advance Booking
 
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Th...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Th...Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Th...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Th...
 
Shikrapur Call Girls Most Awaited Fun 6297143586 High Profiles young Beautie...
Shikrapur Call Girls Most Awaited Fun  6297143586 High Profiles young Beautie...Shikrapur Call Girls Most Awaited Fun  6297143586 High Profiles young Beautie...
Shikrapur Call Girls Most Awaited Fun 6297143586 High Profiles young Beautie...
 
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in DammamAbortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
Abortion Pill for sale in Riyadh ((+918761049707) Get Cytotec in Dammam
 
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
一比一原版(Otago毕业证书)奥塔哥理工学院毕业证成绩单学位证靠谱定制
 
Top Rated Pune Call Girls Shirwal ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated  Pune Call Girls Shirwal ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...Top Rated  Pune Call Girls Shirwal ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated Pune Call Girls Shirwal ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
 
Just Call Vip call girls godhra Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls godhra Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls godhra Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls godhra Escorts ☎️9352988975 Two shot with one girl (...
 
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Bommasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
HLH PPT.ppt very important topic to discuss
HLH PPT.ppt very important topic to discussHLH PPT.ppt very important topic to discuss
HLH PPT.ppt very important topic to discuss
 
CHEAP Call Girls in Ashok Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Ashok Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Ashok Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Ashok Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Dharwad 7001035870 Whatsapp Number, 24/07 Booking
 
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
怎样办理维多利亚大学毕业证(UVic毕业证书)成绩单留信认证
 
Top Rated Pune Call Girls Ravet ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Ravet ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Ravet ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Ravet ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Pimple Saudagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Arekere ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
Top Rated Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Katraj ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
 
CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Vinay Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
Vip Mumbai Call Girls Andheri East Call On 9920725232 With Body to body massa...
 

LR PARSE.pptx

  • 1. NADAR SARASWATHI COLLEGE OF ARTS AND SCIENCE, VADAPUTHUPATTI,THENI. DEPARTEMENT OF COMPUTER SCIENCE LR PARSERS SUBMITTED BY: S.AISHWARYA LAKSHMI I MSC(CS)
  • 2. LR parser  LR parser is a bottom-up parser for context-free grammar that is very generally used by computer programming language compiler and other associated tools.  LR parser reads their input from left to right and produces a right-most derivation.  It is called a Bottom-up parser because it attempts to reduce the top-level grammar productions by building up from the leaves.  LR parsers are the most powerful parser of all deterministic parsers in practice.
  • 3. Description of LR parser :  The term parser LR(k) parser, here the L refers to the left-to- right scanning,  R refers to the rightmost derivation in reverse and k refers to the number of unconsumed “look ahead” input symbols that are used in making parser decisions.  Typically, k is 1 and is often omitted.  A context-free grammar is called LR (k) if the LR (k) parser exists for it.  This first reduces the sequence of tokens to the left.  But when we read from above, the derivation order first extends to non-terminal.
  • 4. Description of LR parser :  The stack is empty, and we are looking to reduce the rule by S’→S$.  Using a “.” in the rule represents how many of the rules are already on the stack.  A dotted item, or simply, the item is a production rule with a dot indicating how much RHS has so far been recognized.  Closing an item is used to see what production rules can be used to expand the current structure.
  • 5. Rules for LR parser :  The rules of LR parser as follows.  The first item from the given grammar rules adds itself as the first closed set.  If an object is present in the closure of the form A→ α. β. γ,  where the next symbol after the symbol is non- terminal, add the symbol’s production rules where the dot precedes the first item.  Repeat steps (B) and (C) for new items added under (B).
  • 6. LR parser algorithm :  LR Parsing algorithm is the same for all the parser, but the parsing table is different for each parser. It consists following components as follows.  Input Buffer – It contains the given string, and it ends with a $ symbol.  Stack – The combination of state symbol and current input symbol is used to refer to the parsing table in order to take the parsing decisions.
  • 7. Parsing Table :  Parsing table is divided into two parts- Action table and Go-To table. The action table gives a grammar rule to implement the given current state and current terminal in the input stream.  There are four cases used in action table as follows.  Shift Action- In shift action the present terminal is removed from the input stream and the state n is pushed onto the stack, and it becomes the new present state.  Reduce Action- The number m is written to the output stream.
  • 8. Parsing Table :  The symbol m mentioned in the left-hand side of rule m says that state is removed from the stack.  The symbol m mentioned in the left-hand side of rule m says that a new state is looked up in the goto table and made the new current state by pushing it onto the stack.  R parsers are used to parse the large class of context free grammars. This technique is called LR(k) parsing.  L is left-to-right scanning of the input.  R is for constructing a right most derivation in reverse.
  • 9. Parsing Table :  k is the number of input symbols of lookahead that are used in making parsing decisions.  There are three widely used algorithms available for constructing an LR parser:  SLR(l) – Simple LR  Few number of states, hence very small table.  Simple and fast construction.  Works on smallest class of grammar.
  • 10. Reasons for attractiveness of LR parser  LR parsers can handle a large class of context-free grammars.  The LR parsing method is a most general non-back tracking shift-reduce parsing method.  An LR parser can detect the syntax errors as soon as they can occur.  LR grammars can describe more languages than LL grammars.
  • 11. Drawbacks of LR parsers  It is too much work to construct LR parser by hand. It needs an automated parser generator.  If the grammar contains ambiguities or other constructs then it is difficult to parse in a left- to-right scan of the input.
  • 12. Behavior of the LR parser  1. If ACTION[sm, ai] = shift s. The parser executes the shift move, it shifts the next state s onto the stack, entering the configuration a) Sm – the state on top of the stack. b) ai– the current input symbol.
  • 13. Behavior of the LR parser  2. If ACTION[sm, ai] =reduce A—> β, then the parser executes a reduce move, entering the configuration (s0s1 … S(m-r)S, ai+l … an$) a) where r is the length of β and s= GOTO[sm – r, A]. b) First popped r state symbols off the stack, exposing state Sm-r·