Compiler_Design_Full_QnA
Compiler_Design_Full_QnA
d) What is Bootstrapping?
Bootstrapping is the process of writing a compiler in the source programming language it is intended to compile.
For (a*b/bc*):
Start -> (a loop) -> b -> Accept
OR
Start -> b -> (c loop) -> Accept
Rightmost:
E -> E+E -> E+E*E -> E+id*E -> E+id*id -> id+id*id
d) Types of LR parsers:
- SLR(1): Simple LR.
- CLR(1): Canonical LR.
- LALR(1): Look-Ahead LR.
Operation: All use a parsing table and stack to shift and reduce symbols based on grammar.
FIRST:
FIRST(E) = FIRST(T) = FIRST(F) = { (, id }
FIRST(E') = { +, epsilon }
FIRST(T') = { *, epsilon }
FOLLOW:
FOLLOW(E) = { $, ) }
FOLLOW(E') = FOLLOW(E) = { $, ) }
FOLLOW(T) = FIRST(E') = { +, $, ) }
FOLLOW(T') = FOLLOW(T) = { +, $, ) }
FOLLOW(F) = FOLLOW(T) = { *, +, $, ) }
05. Parse string w = (a) using SLR parser for A -> (A) | a:
LR(0) Items:
1. [A -> .(A)]
2. [A -> ( .A)]
3. [A -> (A .)]
4. [A -> .a]
5. [A -> a .]
Parsing Steps:
Stack | Input | Action
------|-------|--------
$ | (a)$ | Shift (
$( | a)$ | Shift a
$(a | )$ | Reduce A -> a
$(A | )$ | Shift )
$(A) | $ | Reduce A -> (A)
$A |$ | Accept