Compiler Construction Unit 3 Part-6 CLR (1) and LANR (1) Parser CSE

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

Compiler Construction

Unit 3 Part-6
CLR(1) and LANR(1) Parser
CSE

By Himanshu Swarnkar
Engineering College Banswara
Parser

Top Down Bottom Up Parser


Parser (BUP)
(TDP) SR Parser(shift Reduce)

TDP with Full TDP Without Operator LR Parser


Backtracking Backtracking Precedence (Scanning from L to R, Reverse
Parser of Right most derivation)

Brute force
Method Recursive Descent Non Recursive LR(0) LALR(1)
SLR(1) CLR(1)
Descent(LL(1))
CLR(1) Parser
 CLR refers to canonical lookahead LR parser.
 CLR parsing use the canonical collection of LR (1) items to build the CLR (1) parsing table.
 LR(1) item= LR(0) item + lookahead.
 CLR (1) parsing table produces the more number of states as compare to the SLR (1) parsing.
 In the CLR (1), we place the reduce node only in the lookahead symbols.
 Various steps involved in the SLR (1) Parsing
 For the given input string write a context free grammar
 Check the ambiguity of the grammar
 Add Augment production in the given grammar
 Create Canonical collection of LR (0) items
 Draw a data flow diagram (DFA)
 Construct a CLR (1) parsing table
S’ → S
S → AA r1
I5
A → aA r2 CLR(1) Parsing Table
S → AA.,$
A → b r3 I1 A I9
I0 S’ → S., $ A Action Goto
S A → aA.,$
S’ → .S, $ a I6 A→ a.A, $ (for Terminals) (for Variables)
I2 S → A.A, $ A→ .aA, $ a
S → .AA, $ A A→ .b, $
A → .aA , $ a b $ A S
A → .aA , a/b A → .b, $ b b I0 S3 S4 I2 I1
a
A → .b, a/b I7
A→ b., $
I3 A → a.A, a/b I1 Accept
A → .aA, a/b A I2 S6 S7 I5
b A →.b, a/b
a I8 A → aA., a/b I3 S3
I4 S4 I8
b
A → b., a/b I4 r3 r3
States I5 r1
I6 S6 S7 I9
Note:
1. Lookahead is calculated after the one symbol of dot. I7 r3
2.While applying the transition lookahead in not change but I8 r2 r2
while applying the closure lookahed might be change
I9 r2
Remember:
1. I3 and I6, I4 and I7 & I8 and I9 are same but different
lookahead, use to generate LALR(1) parsing table. Number of states in CLR(1)>= LR(0)=SLR(1).
The difference in only in reduce move.

You might also like