Compiler Design (All Modules) - 13

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

 Reduce: When a sequence of tokens on the stack matches a grammar rule's right-hand side, it's reduced to the

corresponding non-terminal (like completing a wall section based on the blueprint).


 The parser table guides these shift-reduce actions

Q5. LR Parsers and it’s types

Ans: What are LR Parsers?

 They analyze code structure by building the parse tree from tokens (bottom-up) while considering some
lookahead tokens (limited number of tokens following the current one).
 Imagine building a house from the ground up (bricks) while peeking ahead at the blueprint (lookahead) to ensure
you're on the right track.
 There are 3 types of LR Parsers

1.LR (Simple LR): A basic version with limitations.

 Most basic LR parser


 SLR is a good starting point for simpler grammars.
 Good starting point for simpler grammars due to its efficiency.
 A basic version with limitations.
 Efficient but limited in grammar handling.
 May not be able to construct a parsing table for all grammars.

2.LALR (Lookahead LR): More powerful than SLR, handles some ambiguous grammars.

 More powerful than SLR


 LALR offers a balance of power and table size, making it a popular choice.
 More powerful than SLR, handles some ambiguous grammars..
 Often preferred choice for its balance of power and table size.
 Can handle some ambiguous grammars (grammars where a sequence can be parsed in multiple ways).
 Achieves this by using a more complex parsing table generation process that considers lookahead tokens.
 Smaller parsing tables compared to CLR.

3.CLR (Canonical LR): Most powerful but requires more complex table generation.

 Most powerful LR parser.


 used when maximum grammar handling is necessary.
 Most powerful but requires more complex table generation.
 Handles the widest range of grammars.
 Requires the most complex parsing table generation, making it potentially slower in practice.
 Used when maximum grammar handling capability is needed, even if it comes with some trade-offs in table size
and potentially speed.

Q6. Bottom-Up Parsing

Ans: Bottom-up parsing is a method used in computer science to analyze and understand the structure of a given text,
starting from the individual elements and building up to the higher-level structure. It's like solving a puzzle by putting
together the smallest pieces first, gradually forming a bigger picture.

Basic Idea:

 Starts with the tokens (smallest building blocks) and works its way up, combining them into larger structures
based on grammar rules.
 Imagine building a house brick by brick, following a blueprint (grammar) to create the final structure.

You might also like