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 stat 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. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Incremental Compiler in Compiler Design
- Difference between Native compiler and Cross compiler
- Parsing | Set 1 (Introduction, Ambiguity and Parsers)
- Bottom Up or Shift Reduce Parsers | Set 2
- SLR, CLR and LALR Parsers | Set 3
- Classification of Top Down Parsers
- Introduction to Syntax Analysis in Compiler Design
- Why FIRST and FOLLOW in Compiler Design?
- Runtime Environments in Compiler Design
- Syntax Directed Translation in Compiler Design
- Intermediate Code Generation in Compiler Design
- Peephole Optimization in Compiler Design
- Code Optimization in Compiler Design
- Introduction of Object Code in Compiler Design
- Introduction of Compiler Design
- Compiler Design | Syntax Directed Definition
- Error Handling in Compiler Design
- Compiler Design | Detection of a Loop in Three Address Code
- Labeling Algorithm in Compiler Design
- Transition diagram for Identifiers in Compiler Design
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.