Process of compilation is divided into sub-task .So after receive token as its input generated from previous phase and produce a hierarchical structure called syntax tree or parse tree.
Parser or syntax analysis is the second phase of compilation. Lexical analyzer generates taken from the source code string and that token is collect parser and convert into syntax tree.
The process of deriving the string from a given grammar using the production of the grammar is known as parsing . Here input is stream of tokens and output will be the parse tree. if we get a success in generating the syntax tree then it means there is no grammatical mistakes in the string otherwise it means a grammatical error.
Types of parser
- Top-Down Parser
- Bottom up parser
- Top Down parsing without backtracking.
- Top down parser with backtracking.
- Shift reduce parser
- Operator precedence parser.
- LR parser.
- Parser can try all alternatives in any order till it successfully parses the string.
- exponential time to perform parsing because backtracking takes lot of time.
- A grammar can have left recursion.
- Lot of overhead .
- Difficult to find error.
- Information once inserted will be removed from symbol table while backtracking.
- Top down parser without backtracking take less time.
- Left recursion will be removed before doing parsing.
- No backtracking so less overhead.
- Easily find error in Top down parser without backtracking.
- Information once inserted will not be removed from symbol table because no backtracking.
- Parser can select correct alternative at each step because no left recursion or no left factor.
- Predictive parser.
- Recursive decent parser.
- Computation of FIRST and FOLLOW for different symbol of grammar.
- Construct predictive parsing table using FIRST and FOLLOW.
- Perform parsing of input string with the help of predictive parsing table.
- Shift reduce parser.
- Operator Precedence Parser.
- LR parser.
- SLR parser.
- CLR parser.
- LALR parser.
- That is Simple LR parser . But that is not more powerful because that is fails to produce parsing table for some class of grammar.
- SLR parser require less time and less space to parse the input string.
- That parser is easy to implement.
- SLR<=LALR<=CR.
- LALR is easy and cheap to implement.
- Error detection in LALR is not immediate.
- LALR parser require more time and space complexity.
- It is easy and cheap to implement.
- CLR parser is largest in size. Number of states are very large.
- It is more powerful and work large class of grammar.
- Error detection can be done immediately in CLR parser.
- It is expensive and difficult to implement.
- More space and time complexity.
0 Comments