0% found this document useful (0 votes)
23 views

LR Parser-Part-I

The document discusses LR parsing which is a bottom up parsing technique. It breaks down LR parsing into different types including LR(0), SLR(1), CLR(1), and LALR(1). It also describes the key steps to construct an LR parsing table including writing a context free grammar, checking for ambiguity, augmenting the grammar, creating LR items, drawing a DFA, and constructing the actual parsing table.

Uploaded by

Gladwin Tirkey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

LR Parser-Part-I

The document discusses LR parsing which is a bottom up parsing technique. It breaks down LR parsing into different types including LR(0), SLR(1), CLR(1), and LALR(1). It also describes the key steps to construct an LR parsing table including writing a context free grammar, checking for ambiguity, augmenting the grammar, creating LR items, drawing a DFA, and constructing the actual parsing table.

Uploaded by

Gladwin Tirkey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

LR Parser

LR parsing is one type of bottom up parsing. It is used to parse the large class of grammars.

In the LR parsing, "L" stands for left-to-right scanning of the input.

"R" stands for constructing a right most derivation in reverse.

"K" is the number of input symbols of the look ahead used to make number of parsing decision.

LR parsing is divided into four parts: LR (0) parsing, SLR(1) parsing, CLR(1) parsing and
LALR(1) parsing.

NOTE that LR(0) Parsing Table Algorithm is not in your Course Syllabus
Fig: Block diagram of LR parser
More Details:-
Construction of LR Parsing Table

Various steps involved in the LR Parsing Table Construction:

o For the given input string write a context free grammar.


o Check the ambiguity of the grammar.
o Add Augment production in the given grammar.
o Create Canonical collection of LR (0) items [For Creating LR(0) &
SLR(1) Parsing Table] And LR(1) items For Creating LR(0) & SLR(1)
Parsing Table] using Corresponding Closure and Successor/Goto
Functions [These Functions are different for LR(0) items & LR(1)
items].
o Draw a Deterministic Finite Automata (DFA) diagram [directly or indirectly
after NFA construction].
o Construct a LR parsing table.

NOTE that LR(0) Parsing Table Algorithm is not in your Course Syllabus
Augment Grammar

Augmented grammar G` will be generated if we add one more production in the


given grammar G. It helps the parser to identify when to stop the parsing and
announce the acceptance of the input.

Example

Given grammar

1. S → AA
2. A → aA | b

The Augment grammar G` is represented by

1. S`→ S
2. S → AA
3. A → aA | b
More Details
Finally
Step 3: DFA
Step 4: Construction of SLR(1) Parsing Table using Algorithm.

Use the common LR Parsing Program Algorithm

You might also like