Open In App

Types of Parsers in Compiler Design

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

Types of Parser: 

The parser is mainly classified into two categories, i.e. Top-down Parser, and Bottom-up Parser. These are explained below: 



Top-Down Parser:

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. 

  1. 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. 
  2. 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: 

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 terminals i.e. it starts from 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. 



(a)LR(0)
(b)SLR(1)
(c)LALR(1)
(d)CLR(1) 
Article Tags :