Types of Parsers in Compiler Design

07 Jun, 2022
The parser is that phase of the compiler which takes a token string as input and with the help of existing grammar, converts it into the corresponding Intermediate Representation(IR). The parser is also known as Syntax Analyzer. 
Classification of Parser
The parser is mainly classified into two categories, i.e. Top-down Parser, and Bottom-up Parser. These are explained below: 
The top-down parser is the parser that generates parse for the given input string with the help of grammar productions by expanding the non-terminals i.e. it starts from the start symbol and ends on the terminals. It uses left most derivation. Further Top-down parser is classified into 2 types: A recursive descent parser, and Non-recursive descent parser. 
Recursive descent parser is also known as the Brute force parser or the backtracking parser. It basically generates the parse tree by using brute force and backtracking. Non-recursive descent parser is also known as LL(1) parser or predictive parser or without backtracking parser or dynamic parser. It uses a parsing table to generate the parse tree instead of backtracking.
Recursive descent parser is also known as the Brute force parser or the backtracking parser. It basically generates the parse tree by using brute force and backtracking. 
Non-recursive descent parser is also known as LL(1) parser or predictive parser or without backtracking parser or dynamic parser. It uses a parsing table to generate the parse tree instead of backtracking.
Bottom-up Parser is the parser that generates the parse tree for the given input string with the help of grammar productions by compressing the non-terminals i.e. it starts from non-terminals and ends on the start symbol. It uses the reverse of the rightmost derivation. Further Bottom-up parser is classified into two types: LR parser, and Operator precedence parser. 
LR parser is the bottom-up parser that generates the parse tree for the given string by using unambiguous grammar. It follows the reverse of the rightmost derivation. LR parser is of four types: 
(a)LR(0)
(b)SLR(1)
(c)LALR(1)
(d)CLR(1) 
Operator precedence parser generates the parse tree from given grammar and string but the only condition is two consecutive non-terminals and epsilon never appears on the right-hand side of any production. 
The operator precedence parsing techniques can be applied to Operator grammars.
Operator grammar: A grammar is said to be operator grammar if there does not exist any production rule on the right-hand side.      1. as ε(Epsilon)      2. Two non-terminals appear consecutively, that is, without any terminal between them operator precedence parsing is not a simple               technique to apply to most the language constructs, but it evolves into an easy technique to implement where a suitable grammar             may be produced.
jacobbridges3283
amandeepkaur93031
nwekechiemezie65
akash1908232
Compiler Design
GATE CS
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Issues in the design of a code generator
Peephole Optimization in Compiler Design
Directed Acyclic graph in Compiler Design (with examples)
Type Checking in Compiler Design
S - attributed and L - attributed SDTs in Syntax directed translation
Layers of OSI Model
ACID Properties in DBMS
Types of Operating Systems
TCP/IP Model
Page Replacement Algorithms in Operating Systems