Header Ads Widget

Parser

Parser

Parser is a compiler that is used to break the data into smaller elements coming from lexical analysis phase.

A parser takes input in the form of sequence of tokens and produces output in the form of parse tree.

Parsing is of two types: top down parsing and bottom up parsing.

Parser

Top down paring

  • The top down parsing is known as recursive parsing or predictive parsing.
  • Bottom up parsing is used to construct a parse tree for an input string.
  • In the top down parsing, the parsing starts from the start symbol and transform it into the input symbol.

Parse Tree representation of input string "acdb" is as follows:

Parser 1

Bottom up parsing

  • Bottom up parsing is also known as shift-reduce parsing.
  • Bottom up parsing is used to construct a parse tree for an input string.
  • In the bottom up parsing, the parsing starts with the input symbol and construct the parse tree up to the start symbol by tracing out the rightmost derivations of string in reverse.

Example

Production

  1. E → T  
  2. T → T * F  
  3. T → id  
  4. F → T  
  5. F → id  

Parse Tree representation of input string "id * id" is as follows:

Parser 3
Parser 4

Bottom up parsing is classified in to various parsing. These are as follows:

  1. Shift-Reduce Parsing
  2. Operator Precedence Parsing
  3. Table Driven LR Parsing
  1. LR( 1 )
  2. SLR( 1 )
  3. CLR ( 1 )
  4. LALR( 1 )

Post a Comment

0 Comments