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.
s0X1s1X2……………………Xmsm$
Where X1, X2……………….Xm are grammar symbols
and s0, s1, s2………………..sm are states
s0X1s1X2 … … XmSm, ai, ai+1 … … an$
Stack
Input String (w)
Here
s = goto[sm−r, A]
r = length of β
Number of symbols popped = 2r (r state symbols + r grammar symbols)