πŸŽ“ Computer Science & Engineering Portal

Master Engineering Disciplines with Structured Notes

Comprehensive academic lecture notes, exam-oriented unit summaries, laboratory manuals, and previous year question papers designed strictly for university students.

πŸ“‘

University Syllabi

AKTU & AICTE aligned semester guidelines.

πŸ“

Exam Question Papers

Previous 5 years solved university papers.

πŸ’‘

Lab Manuals & Viva

Practical codes with outputs & interview Qs.

Core Subjects & Units Hub

Click on any specific unit to immediately view its lecture notes below

Viewing All Lectures

LR Parser

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 parsing, CLR parsing and LALR parsing.

LR algorithm:

The LR algorithm requires stack, input, output and parsing table. In all type of LR parsing, input, output and stack are same but parsing table is different.

LR Parser 1

Fig: Block diagram of LR parser

  • Input buffer is used to indicate end of input and it contains the string to be parsed followed by a $ Symbol.
  • A stack is used to contain a sequence of grammar symbols with a $ at the bottom of the stack.
  • Parsing table is a two dimensional array. It contains two parts: Action part and Go To part.

LR (1) Parsing

Various steps involved in the LR (1) Parsing:

  • For the given input string write a context free grammar.
  • Check the ambiguity of the grammar.
  • Add Augment production in the given grammar.
  • Create Canonical collection of LR (0) items.
  • Draw a data flow diagram (DFA).
  • Construct a LR (1) parsing table.

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

S β†’ AA  
A β†’ aA | b

The Augment grammar G` is represented by

S`β†’ S  
S β†’ AA  
A β†’ aA | b 

Labels: ,

Discussion & Queries (<$I18NNumComments$>):

<$CommentPager$>
<$I18NAtCommentTimeWithPermalink$>, <$I18NCommentAuthorSaid$>

<$BlogCommentBody$>

<$BlogCommentDeleteIcon$>
<$CommentPager$>