- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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 is Components of LR Parsers in compiler design?
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. 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 available. A viable prefix of a right sequential form is that prefix that includes a handle, but no symbol to the right of the handle. Thus, if a finite state machine that identifies viable prefixes of the right sentential form is constructed, it is used to guide the handle selection in the shift-reduce parser.
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.
There are various components of LR Parser which are as follows.
- Input Buffer − It includes the string to be parsed, followed by $, a symbol used as the right end marker to denote the end of the string.
- Stack − It is used to store grammar symbols and states.
Where X1, X2……………….Xm are grammar symbols
and s0, s1, s2………………..sm are states
- Parsing Table: Parsing Table is divided into two sections −
- Actions: Actions can be a shift, reduce, accept and error.
- goto: It takes state and Grammar symbols as arguments and produces a state example, goto (s, X).
- Parsing Program: It is a driving program that performs the following functions:
- It maintains Initial configuration (s0,w$) where s0 is starting state, w is a string.
- It supports the following configuration
s0X1s1X2 … … XmSm, ai, ai+1 … … an$
Stack Input String (w)
- It determines Sm the state currently on top of the stack and ai the current input symbol.
- It takes Actions depending on the entry action [Sm,ai] in the Parsing Table.
- Actions− Actions taken by Parsers are of the following types−
- Shift − If Action [Sm, ai] = shift s then shift ai with state s onto the stack, i.e., the configuration becomes.
- Reduce − If Action [Sm, ai] = reduce A → β, then Parser perform reduction, i.e., the configuration becomes.
s = goto[sm−r, A]
r = length of β
Number of symbols popped = 2r (r state symbols + r grammar symbols)
- Accept − If Action [sm, ai] =accept, Parsing is completed.
- Error − If Action [sm, ai] = error, Parser calls an error-correcting function.
- Related Articles
- What is types of LR Parser in compiler design?
- What is Canonical Collection of LR (0) items in compiler design?
- What are LR Parsers?
- What is Design of Lexical Analysis in Compiler Design?
- What is Compiler Design?
- What is minimizing of DFA in compiler design?
- What is Chomsky Hierarchy in compiler design?
- What is error handling in compiler design?
- What is Input Buffering in Compiler Design?
- What is Finite Automata in Compiler Design?
- What is techniques of storage allocation in compiler design?
- What is the Representation of DFA in compiler design?
- What is translation of control statements in compiler design?
- What is Language Processing Systems in Compiler Design?
- What is role of different data structures in compiler design?