- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is types of LR Parser in compiler design?
There are three types of LR Parsers which are as follows −
Simple LR Parser (SLR) − SLR represents "Simple LR Parser". It is very easy and costeffective to execute. But it fails to make a parsing table for some class of grammars, i.e., why CLR and LALR are used which implements mainly all class or type of grammars. It constructs parsing tables which helps to perform parsing of input strings. SLR Parsing can be done if context-free Grammar will be given. In LR (0), 0 means there is no Look Ahead symbol.
The SLR parsing action and goto function from the deterministic finite automata that identifies viable prefixes. It will not make specifically represented parsing action tables for all grammars but does achieve on some grammars for programming languages. Given a grammar G. We augment G to produce G’, and from G’ it can construct C, the canonical collection of a set of items for G’.
Canonical Look Ahead LR Parser (CLR) − CLR defines canonical lookahead. CLR parsing uses the canonical collection of LR (1) items to construct the CLR (1) parsing table. CLR (1) parsing table makes more number of states as compared to the SLR (1) parsing. In the CLR (1), it can locate the reduce node only in the lookahead symbols.
Construction of LR (1) collection of items for Grammar
It requires three things
- Augmented Grammar
- Closure Function
- goto Function
Augmented Grammar − It is a new Grammar G′ which contains a new production S′ → S with all other productions of given grammar G.
- procedure closure (I)
- begin Repeat
- for each item A→α ∙B β, a in I,
- each production B→γ and
- each terminal b∈FIRST (β a)
- If B→ ∙ γ is not in I
- Add B→ ∙γ,b to I
- Until no more elements can be joined to I;
𝐠𝐨𝐭𝐨(𝐈, 𝐗)− If there is a production 𝐀 → 𝛂 ∙ 𝐗 𝛃, 𝐚 𝐢𝐧 𝐈 then 𝐠𝐨𝐭𝐨(𝐈, 𝐗) is the closure of the set of items of 𝐀 → 𝛂 𝐗 ∙ 𝛃, 𝐚.
Look Ahead LR Parser (LALR) − LALR Parser is Look Ahead LR Parser. It is intermediate in power between SLR and CLR parser. It is the compaction of CLR Parser, and hence tables obtained in this will be smaller than CLR Parsing Table.
Here, first of all, we will construct LR (1) items. Next, we will look for the items having the same first component, and they are merged to form a single set of items. It means the states have the same first component, but the different second component can be integrated into a single state or item.
- What is Components of LR Parsers in compiler design?
- What is Canonical Collection of LR (0) items in compiler design?
- What is Compiler Design?
- What is the difference between SLR, CLR, and LALR Parser in compiler design?
- What is assignment statements with Integer types in compiler design?
- What is Design of Lexical Analysis in Compiler Design?
- What are the types of the translator in compiler design?
- What is minimizing of DFA in compiler design?
- What is Chomsky Hierarchy in compiler design?
- What is error handling in compiler design?
- What is Input Buffering in Compiler Design?
- What is Finite Automata in Compiler Design?
- What is the Representation of DFA in compiler design?
- What is translation of control statements in compiler design?
- What is techniques of storage allocation in compiler design?