Parser is that phase of compiler which takes token string as input and with the help of existing grammar, converts it into the corresponding parse tree. Parser is also known as Syntax Analyzer.
Types of Parser:
Parser is mainly classified into 2 categories: Top-down Parser, and Bottom-up Parser. These are explained as following below.
1. Top-down Parser:
Top-down parser is the parser which 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: Recursive descent parser, and Non-recursive descent parser.
- (i). Recursive descent parser:
It is also known as Brute force parser or the with backtracking parser. It basically generates the parse tree by using brute force and backtracking.
- (ii). Non-recursive descent parser:
It is also known as LL(1) parser or predictive parser or without backtracking parser or dynamic parser. It uses parsing table to generate the parse tree instead of backtracking.
2. Bottom-up Parser:
Bottom-up Parser is the parser which 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 reverse of the right most derivation.
Further Bottom-up parser is classified into 2 types: LR parser, and Operator precedence parser.
- (i). LR parser:
LR parser is the bottom-up parser which generates the parse tree for the given string by using unambiguous grammar. It follow reverse of right most derivation.
LR parser is of 4 types:
(a). LR(0) (b). SLR(1) (c). LALR(1) (d). CLR(1)
- (ii). Operator precedence parser:
It generates the parse tree form given grammar and string but the only condition is two consecutive non-terminals and epsilon never appear in the right-hand side of any production.
Attention reader! Don’t stop learning now. Learn all GATE CS concepts with Free Live Classes on our youtube channel.