- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are LR Parsers?
LR Parser is a class of Bottom-Up Parser that is used to parse Context-Free Grammars. LR Parsing is known as LR (K) parsing where
- L represents Left to Right Scanning of Input
- R represents Rightmost Derivation
- K is the number of input symbols of Look ahead that are used in developing parsing decisions.
LR parser is a shift-reduce parser that creates the use of deterministic finite automata, identifying the collection of all applicable prefixes by reading the stack from bottom to top.
It decides what handle, if any, is feasible. An achievable prefix of a right sentential form is that prefix that includes a handle, however no symbol to the right of the handle.
Thus, if a finite-state machine that recognizes viable prefixes of the right sentential forms is assembled, it can be used to influence the handle selection in the shiftreduce Parser.
Because the LR parser creates the use of a DFA that identifies viable prefixes to manage the selection of handles, it should maintain track of the states of the DFA. Therefore, the LR parser stack includes two kinds of symbols− state symbols can identify the states of the DFA and grammar symbols.
The parser begins with the initial state of a DFA, I0 on the stack. The parser operates by considering the next input symbol 'a' and the state symbol Ii on the top of the stack.
If there is a transition from the state Ii on 'a' in the DFA going to state Ij therefore the symbol a is followed by state symbol Ij onto the stack.
If there is no transition from Ii on a in the DFA, and if the state Ii on the top of the stack identifies, when listed a viable prefix that includes the handle A → a, thus the parser gives out the reduction by popping α and pushing A onto the stack.
This is similar to developing a backward transition from Ii on α in the DFA and then developing a forward transition on A. Each shift action of the parser correlates to a transition on a terminal symbol in the DFA.
Thus, the current state of the DFA and the next input symbol determines whether the parser shifts the next input symbol or goes for reduction.
If it can produce a table mapping each state and input symbol pair as either "shift", "reduce", "accept", or "error", we obtain a table that can be used to manage the parsing phase. Such a table is known as the parsing "action" table.
- Related Articles
- What is Components of LR Parsers in compiler design?
- What is Parsers?
- What is Implementation of LR Parsing Tables?
- html5lib and lxml parsers in Python
- What is types of LR Parser in compiler design?
- What is Canonical Collection of LR (0) items in compiler design?
- Find Canonical Parsing Table (CLR) or LR (1) Parsing Table for Grammar. S → CC C → c C | d
- Show that the following grammar is LR (1) S → A a |b A c |B c | b B a A → d B → d
- What are villi? Where are they located? What are their functions?
- What are Microwaves? What are they used for?
- Find the canonical collection of sets of LR (0) items for Grammar - E → E + T E → T T → T * F T → F F → (E) F → id
- What are carbohydrates? What are their advantages and disadvantages?
- What are villi? What are their location and function?
- What are scavengers?
- What are Incisors?
