SlideShare a Scribd company logo
3
Most read
5
Most read
9
Most read
LR(0) PARSER
Mr.Sameer Prembabu Mamadapure
Information Technology Department
International Institute of Information Technology, I²IT
www.isquareit.edu.in
LR(k) Parsers
• Left-to-right, rightmost derivation with k-token
lookahead.
• Most general parsing technique for deterministic
grammars.
• In general, not practical: tables too large (10^6
states for C++, Ada).
• Common subsets: SLR, LALR (1).
The states of the LR(0)
automaton
• An item is a point within a production, indicating that part
of the production has been recognized:
A a. Bb ,
seen the expansion of a, expect to see expansion of B
• A state is a set of items
• Transition within states are determined by terminals and
non-terminals
• Parsing tables are built from automaton:
action: shift / reduce depending on next symbol
goto: change state depending on synthesized non-terminal
Building LR (0) states
• If a state includes:
A a .Bb
• it also includes every state that is the start of B:
B . X Y Z
• Informally: if I expect to see B next, I expect to see
anything that B can start with, and so on:
X . G H I
• States are built by closure from individual items.
E’ E
E E + T | T; -- left-recursion ok here.
T T * F | F;
F id | (E)
S0 = { E’ .E, E .E + T, E .T,
F .id, F . ( E ) ,
T .T * F, T .F }
A grammar of expressions: initial state
Adding states
• If a state has item A a .a b,
and the next symbol in the input is a, we shift a on the
stack and enter a state that contains item
• A a a.b
(as well as all other items brought in by closure)
• if a state has as item A a. , this indicates the end of
a production: reduce action.
• If a state has an item A a .N b, then after a
reduction that find an N, go to a state with A a N. b
Construction of a predictive parsing
table
• The following rules are used to construct the
predictive parsing table:
– 1. for each terminal a in FIRST(α),
add A → α to matrix M[A,a]
– 2. if λ is in FIRST(α), then
for each terminal b in FOLLOW(A),
add A → α to matrix M[A,b]
The LR (0) states for expressions
• S1 = { E’ E., E E. + T }
• S2 = { E T., T T. * F }
• S3 = { T F. }
• S4 = { F (. E), } + S0 (by closure)
• S5 = { F id. }
• S6 = { E E +. T, T .T * F, T .F, F .id, F .(E)}
• S7 = { T T *. F, F .id, F .(E)}
• S8 = { F (E.), E E.+ T}
• S9 = { E E + T., T T.* F}
• S10 = { T T * F.}, S11 = {F (E).}
LR(0) Automaton
International Institute of Information Technology (I²IT)
P-14, Rajiv Gandhi Infotech Park, MIDC Phase – 1,
Hinjawadi, Pune – 411057, India
Email - info@isquareit.edu.in
Website - http://www.isquareit.edu.in/
THANK-YOU

More Related Content

PPTX
LR(1) and SLR(1) parsing
PPTX
Lecture 14 run time environment
PPT
NFA or Non deterministic finite automata
PPTX
Types of Parser
PPT
1.Role lexical Analyzer
PPT
Ll(1) Parser in Compilers
PPT
pushdown automata
PPTX
Three Address code
LR(1) and SLR(1) parsing
Lecture 14 run time environment
NFA or Non deterministic finite automata
Types of Parser
1.Role lexical Analyzer
Ll(1) Parser in Compilers
pushdown automata
Three Address code

What's hot (20)

PDF
Operator precedence
PPTX
Stressen's matrix multiplication
PPTX
Top down parsing
PPTX
Asymptotic Notation
PDF
Bottom up parser
PPTX
Asymptotic notations
PPT
POST’s CORRESPONDENCE PROBLEM
PPTX
Cs419 lec10 left recursion and left factoring
PPT
Chomsky & Greibach Normal Forms
PDF
NFA to DFA
PPT
Chapter 5 -Syntax Directed Translation - Copy.ppt
PPTX
Theory of automata and formal language
PPTX
Automata theory - NFA ε to DFA Conversion
PPTX
Context free grammar
PPTX
Type checking compiler construction Chapter #6
PPTX
Ambiguous & Unambiguous Grammar
PPT
Lecture 1 - Lexical Analysis.ppt
PPTX
Back patching
PPTX
2.1 & 2.2 grammar introduction – types of grammar
PPT
Chapter 5 Syntax Directed Translation
Operator precedence
Stressen's matrix multiplication
Top down parsing
Asymptotic Notation
Bottom up parser
Asymptotic notations
POST’s CORRESPONDENCE PROBLEM
Cs419 lec10 left recursion and left factoring
Chomsky & Greibach Normal Forms
NFA to DFA
Chapter 5 -Syntax Directed Translation - Copy.ppt
Theory of automata and formal language
Automata theory - NFA ε to DFA Conversion
Context free grammar
Type checking compiler construction Chapter #6
Ambiguous & Unambiguous Grammar
Lecture 1 - Lexical Analysis.ppt
Back patching
2.1 & 2.2 grammar introduction – types of grammar
Chapter 5 Syntax Directed Translation
Ad

Similar to LR(0) PARSER (20)

PPTX
sameermlr0parser-200701133032.pptx
PPTX
Compiler Design LR parsing SLR ,LALR CLR
PPT
Presentation mam saima kanwal
PPTX
BOTTOM UP PARSING GROUP 3.pptx
PPTX
Syntax Analysis - LR(0) Parsing in Compiler
PPT
Chapter Five(2)
PPT
LR-Parsing.ppt
PPTX
Lecture 09 syntax analysis 05
PPTX
Parsing LL(1), SLR, LR(1)
PPT
Lecture 15 16
DOCX
How do you learn Bottom-up Parsing Algorithm.docx
PDF
Lecture11 syntax analysis_7
PDF
Compiler unit 2&3
PPTX
LALR Parser Presentation ppt
PDF
Lecture4 lexical analysis2
PPT
Advance LISP (Artificial Intelligence)
PPT
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
PPT
(Ai lisp)
sameermlr0parser-200701133032.pptx
Compiler Design LR parsing SLR ,LALR CLR
Presentation mam saima kanwal
BOTTOM UP PARSING GROUP 3.pptx
Syntax Analysis - LR(0) Parsing in Compiler
Chapter Five(2)
LR-Parsing.ppt
Lecture 09 syntax analysis 05
Parsing LL(1), SLR, LR(1)
Lecture 15 16
How do you learn Bottom-up Parsing Algorithm.docx
Lecture11 syntax analysis_7
Compiler unit 2&3
LALR Parser Presentation ppt
Lecture4 lexical analysis2
Advance LISP (Artificial Intelligence)
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
(Ai lisp)
Ad

More from International Institute of Information Technology (I²IT) (20)

PPTX
Understanding Natural Language Processing
PPTX
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
PPTX
Writing Skills: Importance of Writing Skills
PPTX
Professional Communication | Introducing Oneself
PPTX
PPTX
What Is Jenkins? Features and How It Works
PPTX
Data Science, Big Data, Data Analytics
PPTX
PPTX
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
PPTX
Sentiment Analysis in Machine Learning
PPT
Importance of Theory of Computations
PPT
Java as Object Oriented Programming Language
PPTX
PPTX
Data Visualization - How to connect Microsoft Forms to Power BI
Understanding Natural Language Processing
Professional Ethics & Etiquette: What Are They & How Do I Get Them?
Writing Skills: Importance of Writing Skills
Professional Communication | Introducing Oneself
What Is Jenkins? Features and How It Works
Data Science, Big Data, Data Analytics
Difference Between AI(Artificial Intelligence), ML(Machine Learning), DL (Dee...
Sentiment Analysis in Machine Learning
Importance of Theory of Computations
Java as Object Oriented Programming Language
Data Visualization - How to connect Microsoft Forms to Power BI

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation theory and applications.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
KodekX | Application Modernization Development
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
cuic standard and advanced reporting.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Machine learning based COVID-19 study performance prediction
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectral efficient network and resource selection model in 5G networks
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation theory and applications.pdf
Understanding_Digital_Forensics_Presentation.pptx
Empathic Computing: Creating Shared Understanding
NewMind AI Monthly Chronicles - July 2025
KodekX | Application Modernization Development
Advanced methodologies resolving dimensionality complications for autism neur...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
cuic standard and advanced reporting.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Diabetes mellitus diagnosis method based random forest with bat algorithm
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Machine learning based COVID-19 study performance prediction

LR(0) PARSER

  • 1. LR(0) PARSER Mr.Sameer Prembabu Mamadapure Information Technology Department International Institute of Information Technology, I²IT www.isquareit.edu.in
  • 2. LR(k) Parsers • Left-to-right, rightmost derivation with k-token lookahead. • Most general parsing technique for deterministic grammars. • In general, not practical: tables too large (10^6 states for C++, Ada). • Common subsets: SLR, LALR (1).
  • 3. The states of the LR(0) automaton • An item is a point within a production, indicating that part of the production has been recognized: A a. Bb , seen the expansion of a, expect to see expansion of B • A state is a set of items • Transition within states are determined by terminals and non-terminals • Parsing tables are built from automaton: action: shift / reduce depending on next symbol goto: change state depending on synthesized non-terminal
  • 4. Building LR (0) states • If a state includes: A a .Bb • it also includes every state that is the start of B: B . X Y Z • Informally: if I expect to see B next, I expect to see anything that B can start with, and so on: X . G H I • States are built by closure from individual items.
  • 5. E’ E E E + T | T; -- left-recursion ok here. T T * F | F; F id | (E) S0 = { E’ .E, E .E + T, E .T, F .id, F . ( E ) , T .T * F, T .F } A grammar of expressions: initial state
  • 6. Adding states • If a state has item A a .a b, and the next symbol in the input is a, we shift a on the stack and enter a state that contains item • A a a.b (as well as all other items brought in by closure) • if a state has as item A a. , this indicates the end of a production: reduce action. • If a state has an item A a .N b, then after a reduction that find an N, go to a state with A a N. b
  • 7. Construction of a predictive parsing table • The following rules are used to construct the predictive parsing table: – 1. for each terminal a in FIRST(α), add A → α to matrix M[A,a] – 2. if λ is in FIRST(α), then for each terminal b in FOLLOW(A), add A → α to matrix M[A,b]
  • 8. The LR (0) states for expressions • S1 = { E’ E., E E. + T } • S2 = { E T., T T. * F } • S3 = { T F. } • S4 = { F (. E), } + S0 (by closure) • S5 = { F id. } • S6 = { E E +. T, T .T * F, T .F, F .id, F .(E)} • S7 = { T T *. F, F .id, F .(E)} • S8 = { F (E.), E E.+ T} • S9 = { E E + T., T T.* F} • S10 = { T T * F.}, S11 = {F (E).}
  • 10. International Institute of Information Technology (I²IT) P-14, Rajiv Gandhi Infotech Park, MIDC Phase – 1, Hinjawadi, Pune – 411057, India Email - info@isquareit.edu.in Website - http://www.isquareit.edu.in/ THANK-YOU