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.
- Introduction of Compiler Design
- Why FIRST and FOLLOW in Compiler Design?
- Bootstrapping in Compiler Design
- Basic Blocks in Compiler Design
- Peephole Optimization in Compiler Design
- Semantic Analysis in Compiler Design
- Input Buffering in Compiler Design
- Loop Optimization in Compiler Design
- Runtime Environments in Compiler Design
- Labeling Algorithm in Compiler Design
- Code Optimization in Compiler Design
- Error Handling in Compiler Design
- Intermediate Code Generation in Compiler Design
- Syntax Directed Translation in Compiler Design
- Introduction to Syntax Analysis 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 firstname.lastname@example.org. 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.