Skip to content
Related Articles

Related Articles

Types of Parsers in Compiler Design

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Medium
  • Last Updated : 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

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 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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!