![]() |
VOOZH | about |
In this article, we will discuss LR parser, and it's overview and then will discuss the algorithm. Also, we will discuss the parsing table and LR parser working diagram. Let's discuss it one by one.
LR parser :
LR parser is a bottom-up parser for context-free grammar that is very generally used by computer programming language compiler and other associated tools. LR parser reads their input from left to right and produces a right-most derivation. It is called a Bottom-up parser because it attempts to reduce the top-level grammar productions by building up from the leaves. LR parsers are the most powerful parser of all deterministic parsers in practice.
Description of LR parser :
The term parser LR(k) parser, here the L refers to the left-to-right scanning, R refers to the rightmost derivation in reverse and k refers to the number of unconsumed "look ahead" input symbols that are used in making parser decisions. Typically, k is 1 and is often omitted. A context-free grammar is called LR (k) if the LR (k) parser exists for it. This first reduces the sequence of tokens to the left. But when we read from above, the derivation order first extends to non-terminal.
Rules for LR parser :
The rules of LR parser as follows.
LR parser algorithm :
LR Parsing algorithm is the same for all the parser, but the parsing table is different for each parser. It consists following components as follows.
Parsing Table :
Parsing table is divided into two parts- Action table and Go-To table. The action table gives a grammar rule to implement the given current state and current terminal in the input stream. There are four cases used in action table as follows.
An accept - the string is accepted No action - a syntax error is reported
Note -
The go-to table indicates which state should proceed.
LR parser diagram :
👁 Image