You are on page 1of 128

Compiler Design (CD)

GTU # 2170701

Unit – 3
Parsing Theory (I)

Prof. Dixita B. Kagathara


Computer Engineering Department
Darshan Institute of Engineering & Technology, Rajkot
dixita.kagathara@darshan.ac.in
+91 - 97277 47317 (CE Department)
Topics to be covered
 Looping
• Role of parser
• Context free grammar
• Derivation & Ambiguity
• Left recursion & Left factoring
• Classification of parsing
• Backtracking
• LL(1) parsing
• Recursive descent paring
• Shift reduce parsing
• Operator precedence parsing
• LR parsing
Role of Parser
Role of parser
Token Parse
Source Lexical Parse tree
end
IR
Parser
tree Rest of front
program analyzer
Get next token

Symbol table

 Parser obtains a string of token from the lexical analyzer and reports syntax error if any
otherwise generates syntax tree.
 There are two types of parser:
1. Top-down parser
2. Bottom-up parser

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 4
Context free grammar
Context free grammar
 A context free grammar (CFG) is a 4-tuple where,
is finite set of non terminals,
is disjoint finite set of terminals,
is an element of and it’s a start symbol,
is a finite set formulas of the form where and

 Nonterminal symbol:
 The name of syntax category of a language, e.g., noun, verb, etc.
 The It is written as a single capital letter, or as a name enclosed between < … >, e.g., A or
<Noun>
<Noun Phrase> → <Article><Noun>
<Article> → a | an | the
<Noun> → boy | apple

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 6
Context free grammar
 A context free grammar (CFG) is a 4-tuple where,
is finite set of non terminals,
is disjoint finite set of terminals,
is an element of and it’s a start symbol,
is a finite set formulas of the form where and

 Terminal symbol:
 A symbol in the alphabet.
 It is denoted by lower case letter and punctuation marks used in language.

<Noun Phrase> → <Article><Noun>


<Article> → a | an | the
<Noun> → boy | apple

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 7
Context free grammar
 A context free grammar (CFG) is a 4-tuple where,
is finite set of non terminals,
is disjoint finite set of terminals,
is an element of and it’s a start symbol,
is a finite set formulas of the form where and

 Start symbol:
 First nonterminal symbol of the grammar is called start symbol.

<Noun Phrase> → <Article><Noun>


<Article> → a | an | the
<Noun> → boy | apple

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 8
Context free grammar
 A context free grammar (CFG) is a 4-tuple where,
is finite set of non terminals,
is disjoint finite set of terminals,
is an element of and it’s a start symbol,
is a finite set formulas of the form where and

 Production:
 A production, also called a rewriting rule, is a rule of grammar. It has the form of
A nonterminal symbol → String of terminal and nonterminal symbols

<Noun Phrase> → <Article><Noun>


<Article> → a | an | the
<Noun> → boy | apple

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 9
Example: Grammar
Write terminals, non terminals, start symbol, and productions for following grammar.
E  E O E| (E) | -E | id
O+|-|*|/ |↑

Terminals: id + - * / ↑ ( )

Non terminals: E, O

Start symbol: E
Productions: E  E O E| (E) | -E | id
O+|-|*|/ |↑

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 10
Derivation & Ambiguity
Derivation
 Derivation is used to find whether the string belongs to a given grammar or not.
 Types of derivations are:
1. Leftmost derivation
2. Rightmost derivation

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 12
Leftmost derivation
 A derivation of a string in a grammar is a left most derivation if at every step the left most non
terminal is replaced.
 Grammar: SS+S | S-S | S*S | S/S | a Output string: a*a-a

S S
S-S Parse tree represents the
structure of derivation S - S
S*S-S
a*S-S S S
* a
a*a-S
a*a-a a a
Leftmost Derivation Parse tree

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 13
Rightmost derivation
 A derivation of a string in a grammar is a right most derivation if at every step the right most
non terminal is replaced.
 It is all called canonical derivation.
 Grammar: SS+S | S-S | S*S | S/S | a Output string: a*a-a

S
S
S*S
S * S
S*S-S
S*S-a a S S
-
S*a-a
a*a-a a a
Rightmost Derivation Parse Tree
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 14
Exercise: Derivation
1. Perform leftmost derivation and draw parse tree.
SA1B
A0A | 𝜖
B0B | 1B | 𝜖
Output string: 1001
2. Perform leftmost derivation and draw parse tree.
S0S1 | 01 Output string: 000111
3. Perform rightmost derivation and draw parse tree.
EE+E | E*E | id | (E) | -E
Output string: id + id * id

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 15
Ambiguous grammar
Ambiguity
 Ambiguity, is a word, phrase, or statement which contains more than one meaning.

A long thin piece of potato

Chip

A small piece of silicon

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 17
Ambiguity
 In formal language grammar, ambiguity would arise if identical string can occur on the RHS of
two or more productions.
 Grammar:
𝑵𝟏 𝑵𝟐 Replaced by
or ?

 can be derived from either N1 or N2 𝜶

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 18
Ambiguous grammar
 Ambiguous grammar is one that produces more than one leftmost or more then one rightmost
derivation for the same sentence.
 Grammar: SS+S | S*S | (S) | a Output string: a+a*a

S S S S
S*S S+S
S * S S + S
S+S*S a+S
a+S*S S + a+S*S
S a a S * S
a+a*S a+a*S
a+a*a a a+a*a
a a a
 Here, Two leftmost derivation for string a+a*a is possible hence, above grammar is ambiguous.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 19
Exercise: Ambiguous Grammar
Check Ambiguity in following grammars:
1. S aS | Sa | 𝜖 (output string: aaaa)
2. S aSbS | bSaS | 𝜖 (output string: abab)
3. S SS+ | SS* | a (output string: aa+a*)
4. <exp> → <exp> + <term> | <term>
<term> → <term> * <letter> | <letter>
<letter> → a|b|c|…|z (output string: a+b*c)
5. Prove that the CFG with productions: S  a | Sa | bSS | SSb | SbS is ambiguous (Hint:
consider output string yourself)

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 20
Left recursion & Left factoring
Left recursion
 A grammar is said to be left recursive if it has a non terminal such that there is a derivation for
some string
Algorithm to eliminate left recursion
1. Arrange the non terminals in some order  
2. For  do begin
for  do begin
  replace each production of the form  
by the productions ,
where are all the current productions;
   end
  eliminate the immediate left recursion among the  - productions
end

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 22
Left recursion elimination

𝐴→𝐴𝛼∨¿
𝛼 𝛽

 𝐴 ’𝜖
𝐴’

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 23
Examples: Left recursion elimination
EE+T | T
ETE’
E’+TE’ | ε
TT*F | F
TFT’
T’*FT’ | ε
XX%Y | Z
XZX’
X’%YX’ | ε

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 24
Exercise: Left recursion
1. AAbd | Aa | a
BBe | b
2. AAB | AC | a | b
3. SA | B
AABC | Acd | a | aa
BBee | b
4. ExpExp+term | Exp-term | term

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 25
Left factoring
Left factoring is a grammar transformation that is useful for producing a grammar suitable for
predictive parsing.
Algorithm to left factor a grammar
Input: Grammar G
Output: An equivalent left factored grammar.
Method:
For each non terminal A find the longest prefix  common to two or more of its alternatives. If ,
i.e.,  there is a non trivial common prefix, replace all the productions where  represents all
alternatives that do not begin with  by

Here A' is new non terminal. Repeatedly apply this transformation until no two alternatives for a
non-terminal have a common prefix.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 26
Left factoring elimination

𝛼𝛽| 𝛼δ

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 27
Example: Left factoring elimination
SaAB | aCD
SaS’
S’AB | CD
A xByA | xByAzA | a

A xByAA’ | a
A’ Є | zA
A aAB | aA |a
AaA’
A’AB | A | 𝜖
A’AA’’ | 𝜖
A’’B | 𝜖
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 28
Exercise
1. SiEtS | iEtSeS | a
2. A ad | a | ab | abc | x

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 29
Parsing
Parsing
 Parsing is a technique that takes input string and produces output either a parse tree if string is
valid sentence of grammar, or an error message indicating that string is not a valid.
 Types of parsing are:
1. Top down parsing: In top down parsing parser build parse tree from top to bottom.
2. Bottom up parsing: Bottom up parser starts from leaves and work up to the root.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 31
Classification of parsing methods
Parsing

Top down parsing Bottom up parsing (Shift reduce)

Back tracking Operator precedence

Parsing without
backtracking (predictive LR parsing
parsing)
SLR
LL(1)
CLR
Recursive
descent LALR

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 13 – Basic
Parsing
Probability
Theory (I) 32
Backtracking
 In backtracking, expansion of nonterminal symbol we choose one alternative and if any
mismatch occurs then we try another alternative.
 Grammar: S cAd Input string: cad
A ab | a

S S S

c A d c A d c A d
Make prediction Make prediction

a b Backtrack a Parsing done

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 33
Exercise
1. E 5+T | 3-T
T V | V*V | V+V
V a | b
String: 3-a+b

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 34
Parsing Methods
Parsing

Top down parsing Bottom up parsing (Shift reduce)

Back tracking Operator precedence

Parsing without
backtracking (predictive LR parsing
parsing)
SLR
LL(1)
CLR
Recursive
descent LALR

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 13 – Basic
Parsing
Probability
Theory (I) 35
LL(1) parser (predictive parser)
 LL(1) is non recursive top down parser.
1. First L indicates input is scanned from left to right.
2. The second L means it uses leftmost derivation for input string
3. 1 means it uses only input symbol to predict the parsing process.

a + b $ INPUT

X
Predictive
Y
Stack parsing OUTPUT
Z program
$

Parsing table M

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 36
LL(1) parsing (predictive parsing)
Steps to construct LL(1) parser
1. Remove left recursion / Perform left factoring (if any).
2. Compute FIRST and FOLLOW of non terminals.
3. Construct predictive parsing table.
4. Parse the input string using parsing table.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 37
Rules to compute first of non terminal
1. If and is terminal, add to .
2. If , add to .
3. If is nonterminal and is a production, then place in if for some , a is in , and 𝜖 is in all of that
is . If 𝜖 is in for all then add 𝜖 to .
Everything in is surely in If does not derive 𝜖, then we do nothing more to , but if , then we
add and so on.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 38
Rules to compute first of non terminal
Simplification of Rule 3
If ,
• If does not derives
• If derives

• If & Y2 derives ∈

• If , Y2 & Y3 derives ∈

• If , Y2 , Y3 …..YK all derives ∈


(note: if all non terminals derives ∈ then add ∈ to FIRST(A))

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 39
Rules to compute FOLLOW of non terminal
1. Place S is start symbol)
2. If then everything in except for 𝜖 is placed in
3. If there is a production or a production where contains then everything in

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 40
How to apply rules to find FOLLOW of non terminal?

A→𝛼 𝐵 𝛽

𝛽𝑖𝑠 𝑎𝑏𝑠𝑒𝑛𝑡 𝛽𝑖𝑠 𝑝𝑟𝑒𝑠𝑒𝑛𝑡

𝑅𝑢𝑙𝑒 3 𝛽is terminal 𝛽𝑖𝑠 𝑁𝑜𝑛𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑙

𝑅𝑢𝑙𝑒 2 𝜖 𝜖

𝑅𝑢𝑙𝑒 2 𝑅𝑢𝑙𝑒2+ 𝑅𝑢𝑙𝑒3

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 41
Rules to construct predictive parsing table
1. For each production of the grammar, do steps 2 and 3.
2. For each terminal in , Add to .
3. If is in , Add to for each terminal in . If is in , and is in , add to .
4. Make each undefined entry of M be error.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 42
Example-1: LL(1) parsing
SaBa
BbB |
NT First
ϵ
Step 1: Not required S {a}

Step 2: Compute FIRST B {b,𝜖}

First(S) S  a B a Rule 1
SaBa A  add to
FIRST(S)={ a }

First(B)
BbB B𝜖

B  b B  𝜖
B
 Rule 1
A A 
add to Rule 2
add to
FIRST(B)={ b , 𝜖 }
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 43
Example-1: LL(1) parsing
SaBa
BbB | NT First Follow
ϵ S {a} {$}
Step 2: Compute FOLLOW B {b,𝜖} {a}
Follow(S)
Rule 1: Place $ in FOLLOW(S)
Follow(S)={ $ }

Follow(B)
SaBa BbB

S  a B a Rule 2 B  b B Rule 3
A  B First( A  B Follow(A)=follow(B)

Follow(B)={ a }
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 44
Example-1: LL(1) parsing
SaBa
BbB | NT First Follow
ϵ S {a} {$}
Step 3: Prepare predictive parsing table B {b,𝜖} {a}

NT Input Symbol
a b $
S SaBa
B

SaBa
Rule: 2
a=FIRST(aBa)={ a } A
a = first()
M[S,a]=SaBa M[A,a] = A

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 45
Example-1: LL(1) parsing
SaBa
BbB | NT First Follow
ϵ S {a} {$}
Step 3: Prepare predictive parsing table B {b,𝜖} {a}

NT Input Symbol
a b $
S SaBa
B BbB

BbB
Rule: 2
a=FIRST(bB)={ b } A
a = first()
M[B,b]=BbB M[A,a] = A

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 46
Example-1: LL(1) parsing
SaBa
BbB | NT First Follow
ϵ S {a} {$}
Step 3: Prepare predictive parsing table B {b,𝜖} {a}

NT Input Symbol
a b $
S SaBa Error Error
B Bϵ BbB Error

Bϵ
Rule: 3
b=FOLLOW(B)={ a } A
b = follow(A)
M[B,a]=B𝜖 M[A,b] = A

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 47
Example-2: LL(1) parsing
SaB | ϵ
BbC |
ϵ
CcS | ϵ
Step 1: Not required
NT First
Step 2: Compute FIRST S { a, 𝜖 }
First(S) B {b,𝜖}
SaB S𝜖 C {c,𝜖}

S  a B  𝜖
S
Rule 1 Rule 2
A  A 
add to add to

FIRST(S)={ a , 𝜖 }

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 48
Example-2: LL(1) parsing
SaB | ϵ
BbC |
ϵ
CcS | ϵ
Step 1: Not required
NT First
Step 2: Compute FIRST S { a, 𝜖 }
First(B) B {b,𝜖}
BbC B𝜖 C {c,𝜖}

B  b C  𝜖
B
Rule 1 Rule 2
A  A 
add to add to

FIRST(B)={ b , 𝜖 }

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 49
Example-2: LL(1) parsing
SaB | ϵ
BbC |
ϵ
CcS | ϵ
Step 1: Not required
NT First
Step 2: Compute FIRST S { a, 𝜖 }
First(C) B {b,𝜖}
CcS C𝜖 C {c,𝜖}

C  c S  𝜖
C
Rule 1 Rule 2
A  A 
add to add to

FIRST(B)={ c , 𝜖 }

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 50
Example-2: LL(1) parsing
Step 2: Compute FOLLOW
Follow(S) Rule 1: Place $ in FOLLOW(S)
Follow(S)={ $ }
CcS SaB | ϵ
BbC |
C  c S Rule 3 ϵ
A  B Follow(A)=follow(B) CcS | ϵ
Follow(S)=Follow(C) ={$}
NT First Follow
S {a,𝜖} {$}
BbC SaB B {b,𝜖} {$}

 C {c,𝜖} {$}
B  b C Rule 3 S a B Rule 3
A  B Follow(A)=follow(B) A  B Follow(A)=follow(B)
Follow(C)=Follow(B) ={$} Follow(B)=Follow(S) ={$}

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 13 – Basic
Parsing
Probability
Theory (I) 51
Example-2: LL(1) parsing
SaB | ϵ
NT First Follow
BbC |
S {a,𝜖} {$}
ϵ
B {b,𝜖} {$}
CcS
Step 3: |Prepare
ϵ predictive parsing table C {c,𝜖} {$}

N Input Symbol
T a b c $

S SaB
B
C
SaB Rule: 2
A
a=FIRST(aB)={ a } a = first()
M[S,a]=SaB M[A,a] = A

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 52
Example-2: LL(1) parsing
SaB | ϵ
NT First Follow
BbC |
S {a} {$}
ϵ
B {b,𝜖} {$}
CcS
Step 3: |Prepare
ϵ predictive parsing table C {c,𝜖} {$}

N Input Symbol
T a b c $

S SaB S𝜖
B
C
S𝜖 Rule: 3
A
b=FOLLOW(S)={ $ } b = follow(A)
M[S,$]=S𝜖 M[A,b] = A

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 53
Example-2: LL(1) parsing
SaB | ϵ
NT First Follow
BbC |
S {a} {$}
ϵ
B {b,𝜖} {$}
CcS
Step 3: |Prepare
ϵ predictive parsing table C {c,𝜖} {$}

N Input Symbol
T a b c $

S SaB S𝜖
B BbC
C
BbC Rule: 2
A
a=FIRST(bC)={ b } a = first()
M[B,b]=BbC M[A,a] = A

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 54
Example-2: LL(1) parsing
SaB | ϵ
NT First Follow
BbC |
S {a} {$}
ϵ
B {b,𝜖} {$}
CcS
Step 3: |Prepare
ϵ predictive parsing table C {c,𝜖} {$}

N Input Symbol
T a b c $

S SaB S𝜖
B BbC B𝜖
C
B𝜖 Rule: 3
A
b=FOLLOW(B)={ $ } b = follow(A)
M[B,$]=B𝜖 M[A,b] = A

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 55
Example-2: LL(1) parsing
SaB | ϵ
NT First Follow
BbC |
S {a} {$}
ϵ
B {b,𝜖} {$}
CcS
Step 3: |Prepare
ϵ predictive parsing table C {c,𝜖} {$}

N Input Symbol
T a b c $

S SaB S𝜖
B BbC B𝜖
C CcS
CcS Rule: 2
A
a=FIRST(cS)={ c } a = first()
M[C,c]=CcS M[A,a] = A

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 56
Example-2: LL(1) parsing
SaB | ϵ
NT First Follow
BbC |
S {a} {$}
ϵ
B {b,𝜖} {$}
CcS
Step 3: |Prepare
ϵ predictive parsing table C {c,𝜖} {$}

N Input Symbol
T a b c $

S SaB Error Error S𝜖


B Error BbB Error B𝜖
C Error Error CcS C𝜖
C𝜖 Rule: 3
A
b=FOLLOW(C)={ $ } b = follow(A)
M[C,$]=C𝜖 M[A,b] = A

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 57
Example-3: LL(1) parsing
EE+T | T
TT*F | F
F(E) | id
Step 1: Remove left recursion
ETE’
E’+TE’ | ϵ
TFT’
T’*FT’ | ϵ
F(E) | id

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 58
Example-3: LL(1) parsing
Step 2: Compute FIRST ETE’
First(E) E’+TE’ | ϵ
E  T E’ Rule 3 TFT’
ETE’ A  Y1 Y2 First(A)=First(Y1) T’*FT’ | ϵ
F(E) | id
FIRST(E)=FIRST(T) = {(, id }

NT First
First(T) E { (,id }
T  F T’ Rule 3
TFT’ E’
A  Y1 Y2 First(A)=First(Y1)
T { (,id }
FIRST(T)=FIRST(F)= {(, id } T’
First(F) F { (,id }
F(E) 
Fid 
F ( E ) F id
A  Rule 1 A  Rule 1
add to add to
FIRST(F)={ ( , id }
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 59
Example-3: LL(1) parsing
Step 2: Compute FIRST ETE’
First(E’) E’+TE’ | ϵ
TFT’
E’+TE’ T’*FT’ | ϵ
F(E) | id
E’  + T E’ Rule 1
 add to
A NT First
E { (,id }
E’𝜖 E’ { +, 𝜖 }
T { (,id }
T’
E’  Rule 2
F { (,id }
A  add to

FIRST(E’)={ + , 𝜖 }
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 60
Example-3: LL(1) parsing
Step 2: Compute FIRST ETE’
First(T’) E’+TE’ | ϵ
TFT’
T’*FT’ T’*FT’ | ϵ
F(E) | id
T’  * F T’ Rule 1
 add to
A NT First
E { (,id }
T’𝜖 E’ { +, 𝜖 }
T { (,id }
T’ { *, 𝜖 }
T’  Rule 2
F { (,id }
A  add to

FIRST(T’)={ * , 𝜖 }
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 61
Example-3: LL(1) parsing
Step 2: Compute FOLLOW ETE’
FOLLOW(E) E’+TE’ | ϵ
TFT’
Rule 1: Place $ in FOLLOW(E) T’*FT’ | ϵ
F(E) | id
F(E)
NT First Follow
E { (,id } { $,) }
E’ { +, 𝜖 }
F  ( E ) Rule 2
T { (,id }
A  B
T’ { *, 𝜖 }
F { (,id }

FOLLOW(E)={ $, ) }

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 62
Example-3: LL(1) parsing
ETE’
Step 2: Compute FOLLOW E’+TE’ | ϵ
FOLLOW(E’) TFT’
T’*FT’ | ϵ
ETE’ F(E) | id
NT First Follow
E  T E’ Rule 3 E { (,id } { $,) }
A  B
E’ { +, 𝜖 } { $,) }
T { (,id }
E’+TE’ T’ { *, 𝜖 }
F { (,id }
E’  +T E’ Rule 3
A  B

FOLLOW(E’)={ $,) }

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 63
Example-3: LL(1) parsing
Step 2: Compute FOLLOW ETE’
FOLLOW(T) E’+TE’ | ϵ
TFT’
ETE’ T’*FT’ | ϵ
F(E) | id
NT First Follow
E  T E’ Rule 2 E { (,id } { $,) }
A  B
E’ { +, 𝜖 } { $,) }
T { (,id }
T’ { *, 𝜖 }
F { (,id }
E  T E’ Rule 3
A  B

FOLLOW(T)={ +, $, )
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 64
Example-3: LL(1) parsing
Step 2: Compute FOLLOW ETE’
FOLLOW(T) E’+TE’ | ϵ
TFT’
E’+TE’ T’*FT’ | ϵ
F(E) | id
NT First Follow
E’  + T E’ Rule 2 E { (,id } { $,) }
A  B
E’ { +, 𝜖 } { $,) }
T { (,id } { +,$,) }
T’ { *, 𝜖 }
F { (,id }
E’  + T E’ Rule 3
A  B

FOLLOW(T)={ +, $, ) }
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 65
Example-3: LL(1) parsing
Step 2: Compute FOLLOW ETE’
FOLLOW(T’) E’+TE’ | ϵ
TFT’
TFT’ T’*FT’ | ϵ
F(E) | id
NT First Follow
T  F T’ Rule 3 E { (,id } { $,) }
A  B
E’ { +, 𝜖 } { $,) }
T’*FT’ T { (,id } { +,$,) }
T’ { *, 𝜖 } { +,$,) }
F { (,id }
T’  *F T’ Rule 3
A  B

FOLLOW(T’)={+ $,) }
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 66
Example-3: LL(1) parsing
Step 2: Compute FOLLOW ETE’
FOLLOW(F) E’+TE’ | ϵ
TFT’
TFT’ T’*FT’ | ϵ
F(E) | id
NT First Follow
T  F T’ Rule 2 E { (,id } { $,) }
A  B
E’ { +, 𝜖 } { $,) }
T { (,id } { +,$,) }
T’ { *, 𝜖 } { +,$,) }
F { (,id }
T  F T’ Rule 3
A  B

FOLLOW(F)={ *, + ,$ , )
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 67
Example-3: LL(1) parsing
Step 2: Compute FOLLOW ETE’
FOLLOW(F) E’+TE’ | ϵ
TFT’
T’*FT’ T’*FT’ | ϵ
F(E) | id
NT First Follow
T’  * F T’ Rule 2 E { (,id } { $,) }
A  B
E’ { +, 𝜖 } { $,) }
T { (,id } { +,$,) }
T’ { *, 𝜖 } { +,$,) }
F { (,id } {*,+,$,)}
T’  * F T’ Rule 3
A  B

FOLLOW(F)={ *,+, $, ) }
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 68
Example-3: LL(1) parsing
Step 3: Construct predictive parsing table ETE’
E’+TE’ | ϵ
TFT’
NT Input Symbol
T’*FT’ | ϵ
id + * ( ) $ F(E) | id
E ETE’ ETE’
E’ NT First Follow

T E { (,id } { $,) }

T’ E’ { +, 𝜖 } { $,) }
T { (,id } { +,$,) }
F
T’ { *, 𝜖 } { +,$,) }
ETE’ F { (,id } {*,+,$,)}
Rule: 2
a=FIRST(TE’)={ (,id } A
a = first()
M[E,(]=ETE’ M[A,a] = A
M[E,id]=ETE’
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 69
Example-3: LL(1) parsing
Step 3: Construct predictive parsing table ETE’
E’+TE’ | ϵ
TFT’
NT Input Symbol
T’*FT’ | ϵ
id + * ( ) $ F(E) | id
E ETE’ ETE’
E’ E’+TE’ NT First Follow

T E { (,id } { $,) }

T’ E’ { +, 𝜖 } { $,) }
T { (,id } { +,$,) }
F
T’ { *, 𝜖 } { +,$,) }
E’+TE’ F { (,id } {*,+,$,)}
Rule: 2
a=FIRST(+TE’)={ + } A
a = first()
M[E’,+]=E’+TE’ M[A,a] = A

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 70
Example-3: LL(1) parsing
Step 3: Construct predictive parsing table ETE’
E’+TE’ | ϵ
TFT’
NT Input Symbol
T’*FT’ | ϵ
id + * ( ) $ F(E) | id
E ETE’ ETE’
E’ E’+TE’ E’𝜖 E’𝜖 NT First Follow

T E { (,id } { $,) }

T’ E’ { +, 𝜖 } { $,) }
T { (,id } { +,$,) }
F
T’ { *, 𝜖 } { +,$,) }
E’𝜖 F { (,id } {*,+,$,)}
Rule: 3
b=FOLLOW(E’)={ $,) } A
b = follow(A)
M[E’,$]=E’𝜖 M[A,b] = A
M[E’,)]=E’𝜖
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 71
Example-3: LL(1) parsing
Step 3: Construct predictive parsing table ETE’
E’+TE’ | ϵ
TFT’
NT Input Symbol
T’*FT’ | ϵ
id + * ( ) $ F(E) | id
E ETE’ ETE’
E’ E’+TE’ E’𝜖 E’𝜖 NT First Follow

T TFT’ TFT’ E { (,id } { $,) }

T’ E’ { +, 𝜖 } { $,) }
T { (,id } { +,$,) }
F
T’ { *, 𝜖 } { +,$,) }
TFT’ F { (,id } {*,+,$,)}
Rule: 2
a=FIRST(FT’)={ (,id } A
a = first()
M[T,(]=TFT’ M[A,a] = A
M[T,id]=TFT’
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 72
Example-3: LL(1) parsing
Step 3: Construct predictive parsing table ETE’
E’+TE’ | ϵ
TFT’
NT Input Symbol
T’*FT’ | ϵ
id + * ( ) $ F(E) | id
E ETE’ ETE’
E’ E’+TE’ E’𝜖 E’𝜖 NT First Follow

T TFT’ TFT’ E { (,id } { $,) }

T’ T’*FT’ E’ { +, 𝜖 } { $,) }
T { (,id } { +,$,) }
F
T’ { *, 𝜖 } { +,$,) }
T’*FT’ F { (,id } {*,+,$,)}
Rule: 2
a=FIRST(*FT’)={ * } A
a = first()
M[T’,*]=T’*FT’ M[A,a] = A

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 73
Example-3: LL(1) parsing
Step 3: Construct predictive parsing table ETE’
E’+TE’ | ϵ
NT Input Symbol TFT’
id + * ( ) $ T’*FT’ | ϵ
F(E) | id
E ETE’ ETE’
E’ E’+TE’ E’𝜖 E’𝜖
NT First Follow
T TFT’ TFT’
E { (,id } { $,) }
T’ T’𝜖 T’*FT’ T’𝜖 T’𝜖
E’ { +, 𝜖 } { $,) }
F T { (,id } { +,$,) }
T’𝜖 T’ { *, 𝜖 } { +,$,) }
b=FOLLOW(T’)={ +,$,) } F { (,id } {*,+,$,)}
Rule: 3
M[T’,+]=T’𝜖 A
b = follow(A)
M[T’,$]=T’𝜖 M[A,b] = A
M[T’,)]=T’𝜖
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 74
Example-3: LL(1) parsing
Step 3: Construct predictive parsing table ETE’
E’+TE’ | ϵ
TFT’
NT Input Symbol
T’*FT’ | ϵ
id + * ( ) $ F(E) | id
E ETE’ ETE’
E’ E’+TE’ E’𝜖 E’𝜖 NT First Follow

T TFT’ TFT’ E { (,id } { $,) }

T’ T’𝜖 T’*FT’ T’𝜖 T’𝜖 E’ { +, 𝜖 } { $,) }


T { (,id } { +,$,) }
F F(E)
T’ { *, 𝜖 } { +,$,) }
F { (,id } {*,+,$,)}
Rule: 2
F(E) A
a = first()
a=FIRST((E))={ ( } M[A,a] = A
M[F,(]=F(E)
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 75
Example-3: LL(1) parsing
Step 3: Construct predictive parsing table ETE’
E’+TE’ | ϵ
TFT’
NT Input Symbol
T’*FT’ | ϵ
id + * ( ) $ F(E) | id
E ETE’ ETE’
E’ E’+TE’ E’𝜖 E’𝜖 NT First Follow

T TFT’ TFT’ E { (,id } { $,) }

T’ T’𝜖 T’*FT’ T’𝜖 T’𝜖 E’ { +, 𝜖 } { $,) }


T { (,id } { +,$,) }
F Fid F(E)
T’ { *, 𝜖 } { +,$,) }
F { (,id } {*,+,$,)}
Rule: 2
Fid A
a = first()
a=FIRST(id)={ id } M[A,a] = A
M[F,id]=Fid
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 76
Example-3: LL(1) parsing
 Step 4: Make each undefined entry of table be Error
NT Input Symbol
id + * ( ) $
E ETE’ Error Error ETE’ Error Error
E’ Error E’+TE’ Error Error E’𝜖 E’𝜖
T TFT’ Error Error TFT’ Error Error
T’ Error T’𝜖 T’*FT’ Error T’𝜖 T’𝜖
F Fid Error Error F(E) Error Error

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 77
Example-3: LL(1) parsing
Step 4: Parse the string : id + id * id $
NT Input Symbol
id + * ( ) $
STACK INPUT OUTPUT
E ETE’ Error Error ETE’ Error Error
E$ id+id*id$
E’ Error E’+TE’ Error Error E’𝜖 E’𝜖
TE’$ id+id*id$ ETE’
T TFT’ Error Error TFT’ Error Error
FT’E’$ id+id*id$ TFT’
T’ Error T’𝜖 T’*FT’ Error T’𝜖 T’𝜖
idT’E’$ id+id*id$ Fid
F Fid Error Error F(E) Error Error
T’E’$ +id*id$
E’$ +id*id$ T’𝜖
+TE’$ +id*id$ E’+TE’
TE’$ id*id$ FT’E’$ id$
FT’E’$ id*id$ TFT’ idT’E’$ id$ Fid
idT’E’$ id*id$ Fid T’E’$ $
T’E’$ *id$ E’$ $ T’𝜖
*FT’E’$ *id$ T*FT’ $ $ E’𝜖
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 78
Parsing methods
Parsing

Top down parsing Bottom up parsing (Shift reduce)

Back tracking Operator precedence

Parsing without
backtracking (predictive LR parsing
parsing)
SLR
LL(1)
CLR
Recursive
descent LALR

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 13 – Basic
Parsing
Probability
Theory (I) 79
Recursive descent parsing
 A top down parsing that executes a set of recursive procedure to process the input without
backtracking is called recursive descent parser.
 There is a procedure for each non terminal in the grammar.
 Consider RHS of any production rule as definition of the procedure.
 As it reads expected input symbol, it advances input pointer to next position.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 80
Example: Recursive descent parsing
Procedure E Procedure T Proceduce Match(token t)
{ { {
If lookahead=num If lookahead=’*’ If lookahead=t
{ { lookahead=next_token;
Match(num); Match(‘*’); Else
T(); If lookahead=num Error();
} { }
Else Match(num);
Error(); T(); Procedure Error
If lookahead=$ } {
{ Else Print(“Error”);
Declare success; Error(); }
}  
Else }
Error(); Else
} NULL E num T
} T * num T | 𝜖
3 * 4 $ Success

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 81
Example: Recursive descent parsing
Procedure E Procedure T Proceduce Match(token t)
{ { {
If lookahead=num If lookahead=’*’ If lookahead=t
{ { lookahead=next_token;
Match(num); Match(‘*’); Else
T(); If lookahead=num Error();
} { }
Else Match(num);
Error(); T(); Procedure Error
If lookahead=$ } {
{ Else Print(“Error”);
Declare success; Error(); }
}  
Else }
Error(); Else
} NULL E num T
} T * num T | 𝜖
3 * 4 $ Success 3 4 * $ Error
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 82
Parsing Methods
Parsing

Top down parsing Bottom up parsing (Shift reduce)

Back tracking Operator precedence

Parsing without
backtracking (predictive LR parsing
Parsing)
SLR
LL(1)
CLR
Recursive
descent LALR

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 13 – Basic
Parsing
Probability
Theory (I) 83
Handle & Handle pruning
 Handle: A “handle” of a string is a substring of the string that matches the right side of a
production, and whose reduction to the non terminal of the production is one step along the
reverse of rightmost derivation.
 Handle pruning: The process of discovering a handle and reducing it to appropriate left hand
side non terminal is known as handle pruning.
EE+E
EE*E String: id1+id2*id3
Eid
Rightmost Derivation Right sentential form Handle Production
E id1+id2*id3 id1 Eid
E+E E+id2*id3 id2 Eid
E+E*E E+E*id3 id3 Eid
E+E*id3 E+E*E E*E EE*E
E+id2*id3 E+E E+E EE+E
id1+id2*id3 E
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 84
Shift reduce parser
 The shift reduce parser performs following basic operations:
1. Shift: Moving of the symbols from input buffer onto the stack, this action is called shift.
2. Reduce: If handle appears on the top of the stack then reduction of it by appropriate rule is
done. This action is called reduce action.
3. Accept: If stack contains start symbol only and input buffer is empty at the same time then
that action is called accept.
4. Error: A situation in which parser cannot either shift or reduce the symbols, it cannot even
perform accept action then it is called error action.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 85
Example: Shift reduce parser
Grammar: Stack Input Buffer Action
EE+T | T $ id+id*id$ Shift
TT*F | F $id +id*id$ Reduce Fid
Fid $F +id*id$ Reduce TF
String: id+id*id $T +id*id$ Reduce ET
$E +id*id$ Shift
$E+ id*id$ Shift
$E+id *id$ Reduce Fid
$E+F *id$ Reduce TF
$E+T *id$ Shift
$E+T* id$ Shift
$E+T*id $ Reduce Fid
$E+T*F $ Reduce TT*F
$E+T $ Reduce EE+T
$E $ Accept
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 86
Viable Prefix
 The set of prefixes of right sentential forms that can appear on the stack of a shift-reduce
parser are called viable prefixes.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 87
Parsing Methods

Parsing

Top down parsing Bottom up parsing (Shift reduce)

Back tracking Operator precedence

Parsing without
backtracking (predictive LR parsing
Parsing)
SLR
LL(1)
CLR
Recursive
descent LALR

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 13 – Basic
Parsing
Probability
Theory (I) 88
Operator precedence parsing
 Operator Grammar: A Grammar in which there is no Є in RHS of any production or no adjacent
non terminals is called operator grammar.
 Example: E EAE | (E) | id
A + | * | -
 Above grammar is not operator grammar because right side EAE has consecutive non
terminals.
 In operator precedence parsing we define following disjoint relations:

Relation Meaning
a<.b a “yields precedence to” b
a=b a “has the same precedence as” b
a.>b a “takes precedence over” b

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 89
Precedence & associativity of operators

Operator Precedence Associative


↑ 1 right
*, / 2 left
+, - 3 left

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 90
Steps of operator precedence parsing
1. Find Leading and trailing of non terminal
2. Establish relation
3. Creation of table
4. Parse the string

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 91
Leading & Trailing
Leading:- Leading of a non terminal is the first terminal or operator in production of that non
terminal.
Trailing:- Trailing of a non terminal is the last terminal or operator in production of that non
terminal.
Example: EE+T | T
TT*F | F
Fid

Non terminal Leading Trailing


E {+,*,id} {+,*,id}
T {*,id} {*,id}
F {id} {id}

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 92
Rules to establish a relation
1. For a = b, , where is or a single non terminal [e.g : (E)]
2. a <.b [e.g : +T]
3. a .>b [e.g : E+]
4. $ <. Leading (start symbol)
5. Trailing (start symbol) .> $

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 93
Example: Operator precedence parsing
Step 1: Find Leading & Trailing of NT
E E +T| T
Nonterminal Leading Trailing T T *F| F
E {+,*,id} {+,*,id} F id
T {*,id} {*,id}
F {id} {id}

Step 2: Establish Relation Step3: Creation of Table


+ * id $
1. a <.b + .
> <. <. .
>
* .
> .
> <. .
>
id .
> .
>   .
>
$ <. <. <.  

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 94
Example: Operator precedence parsing
Step 1: Find Leading & Trailing of NT
E E+ T| T
Nonterminal Leading Trailing T T* F| F
E {+,*,id} {+,*,id} F id
T {*,id} {*,id}
F {id} {id}

Step2: Establish Relation Step3: Creation of Table


1. a .>b + * id $
+ .
> <. <. .
>
* .
> .
> <. .
>
id .
> .
>   .
>
$ <. <. <.  

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 95
Example: Operator precedence parsing
Step 1: Find Leading & Trailing of NT
E E+ T| T
Nonterminal Leading Trailing T T* F| F
E {+,*,id} {+,*,id} F id
T {*,id} {*,id}
F {id} {id}

Step 2: Establish Relation Step 3: Creation of Table


+ * id $
1. $< Leading (start symbol)
.
+ .
> <. <. .
>
2. $ <. * .
> .
> <. .
>
3. Trailing (start symbol) .> $ id .
> .
>   .
>
$ <. <. <.  

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 96
Example: Operator precedence parsing
Step 4: Parse the string using precedence table
Assign precedence operator between terminals
String: id+id*id
+ * id $
$ id+id*id $ + .
> <. <. .
>
$ <. id+id*id$ * .
> .
> <. .
>
$ <. id .> +id*id$ id .
> .
>   .
>
$ < .
<. <.  
$ < id > + < id*id$
. . .

$ <. id .> + <. id .> *id$


$ <. id .> + <. id .> *<. id$
$ <. id .> + <. id .> *<. id .> $

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 97
Example: Operator precedence parsing
Step 4: Parse the string using precedence table
1. Scan the input string until first .> is encountered.
2. Scan backward until <. is encountered.
3. The handle is string between <. and .>
$ <. Id .> + <. Id .> * <. Id .> $ Handle id is obtained between <. and .>
Reduce this by Fid
$ F + <. Id .> * <. Id .> $ Handle id is obtained between <. and .>
Reduce this by Fid
$ F + F * <. Id .> $ Handle id is obtained between <. and .>
Reduce this by Fid
$F+F*F$ Perform appropriate reductions of all nonterminals.
$E+T*F$ Remove all non terminals.
$ + * $ Place relation between operators
$ <. + <. * >$ The * operator is surrounded by <. and .>. This
indicates * becomes handle so reduce by TT*F.
$ <. + >$ + becomes handle. Hence reduce by EE+T.

$ $ Parsing Done

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 98
Operator precedence function
Algorithm for constructing precedence functions
1. Create functions and for each that is terminal or .
2. Partition the symbols in as many as groups possible, in such a way that and are in the same
group if .
3. Create a directed graph whose nodes are in the groups, next for each symbols do:
a) if , place an edge from the group of to the group of
b) if , place an edge from the group of to the group of
4. If the constructed graph has a cycle then no precedence functions exist. When there are no cycles
collect the length of the longest paths from the groups of and respectively.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 99
Operator precedence function
1. Create functions fa and ga for each a that is terminal or $. E E+T | T
T T*F | F F
id

f+ f* fid f$

g+ g* gid g$

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 100
Operator precedence function
 Partition the
. symbols in as many as groups possible, in such a way that f a and gb are in the same
group if a = b.

+ * id $
+ .
> <. <. .
>
gid fid
* .
> .
> <. .
>
id .
> .
>   .
>
$ <. <. <.  
f* g*

g+ f+

f$ g$

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 101
Operator precedence function
3. if a <· b, place an edge from the group of g b to the group of fa
if a ·> b, place an edge from the group of f a to the group of gb

g
+ * id $
+ .
> <. <. .
>
gid fid
f * .
> .
> <. .
>
id .
> .
>   .
>
f* g* $ <. <. <.  

g+ f+
f+ .> g+ f+  g+
f * . > g+ f*  g+
fid .> g+ fid  g+
f$ g$ f$ <. g+ f$  g+

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 102
Operator precedence function
3. if a <· b, place an edge from the group of g b to the group of fa
if a ·> b, place an edge from the group of f a to the group of gb

g
+ * id $
+ .
> <. <. .
>
gid fid
f * .
> .
> <. .
>
id .
> .
>   .
>
f* g* $ <. <. <.  

g+ f+
f+ <. g* f+  g*
f * . > g* f*  g*
fid .> g* fid  g*
f$ g$ f$ <. g* f$  g*

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 103
Operator precedence function
3. if a <· b, place an edge from the group of g b to the group of fa
if a ·> b, place an edge from the group of f a to the group of gb

g
+ * id $
+ .
> <. <. .
>
gid fid
f * .
> .
> <. .
>
id .
> .
>   .
>
f* g* $ <. <. <.  

g+ f+
f+ <. gid f+  gid
f* <. gid f*  gid
f$ <. gid f$  gid
f$ g$

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 104
Operator precedence function
3. if a <· b, place an edge from the group of g b to the group of fa
if a ·> b, place an edge from the group of f a to the group of gb

g
+ * id $
+ .
> <. <. .
>
gid fid
f * .
> .
> <. .
>
id .
> .
>   .
>
f* g* $ <. <. <.  

g+ f+
f+ <. g$ f+  g$
f* <. g$ f*  g$
fid <. g$ fid  g$
f$ g$

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 105
Operator precedence function

+ * id $
f 2
gid fid
g

f* g* 4. If the constructed graph


has a cycle then no
precedence functions exist.
g+ f+ When there are no cycles
collect the length of the
longest paths from the
f$ g$
groups of fa and gb
respectively.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 106
Operator precedence function

+ * id $
f 2
gid fid
g 1

f* g*

g+ f+

f$ g$

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 107
Operator precedence function

+ * id $
f 2 4
gid fid
g 1

f* g*

g+ f+

f$ g$

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 108
Operator precedence function

+ * id $
f 2 4
gid fid
g 1 3

f* g*

g+ f+

f$ g$

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 109
Operator precedence function

+ * id $
f 2 4 4
gid fid
g 1 3

f* g*

g+ f+

f$ g$

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 110
Operator precedence function

+ * id $
f 2 4 4
gid fid
g 1 3 5

f* g*

g+ f+

f$ g$

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 111
Operator precedence function

+ * id $
f 2 4 4 0
gid fid
g 1 3 5 0

f* g*

g+ f+

f$ g$

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 112
Parsing Methods
Parsing

Top down parsing Bottom up parsing (Shift reduce)

Back tracking Operator precedence

Parsing without
backtracking (predictive LR parsing
Parsing)
SLR
LL(1)
CLR
Recursive
descent LALR

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 13 – Basic
Parsing
Probability
Theory (I) 113
LR parser
 LR parsing is most efficient method of bottom up parsing which can be used to parse large
class of context free grammar.
 The technique is called LR(k) parsing:
1. The “L” is for left to right scanning of input symbol,
2. The “R” for constructing right most derivation in reverse,
3. The “k” for the number of input symbols of look ahead that are used in making parsing
decision. INPUT
a + b $

X
LR parsing
Y
program OUTPUT
Z
$
Parsing Table
Action Goto
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 114
Parsing Methods
Parsing

Top down parsing Bottom up parsing (Shift reduce)

Back tracking Operator precedence

Parsing without
backtracking (predictive LR parsing
parsing)
SLR
LL(1)
CLR
Recursive
descent LALR

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 13 – Basic
Parsing
Probability
Theory (I) 115
Computation of closure & go to function
X Xb
Closure(I):
X X b .
Goto(I,X)
X X b .

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 116
Steps to construct SLR parser
1. Construct Canonical set of LR(0) items
2. Construct SLR parsing table
3. Parse the input string

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 117
Example: SLR(1)- simple LR
S  AA
S AA . 5
A  aA | b S’ S. 𝑰𝟏
𝑰𝟐 𝐺𝑜𝑡𝑜(𝐼2, 𝐴) A a . A
𝑰𝟎 𝐺𝑜𝑡𝑜(𝐼0,𝑆) A. aA 3

S A . A
2 ,𝑎 ) A. b
S’.S
, 𝐴 ) A. aA 𝑡𝑜 ( 𝐼
( 𝐼 0 𝐺 𝑜
𝑜 𝑡𝑜
S. AA
A. aA
𝐺 A. b
𝐺𝑜𝑡𝑜(𝐼2,𝑏)
A b. 4

𝐺𝑜 𝑡
A. b 𝑜 (𝐼 𝐴 )
0 , 𝑎) 3
( 𝐼 3 , A aA . 6 LR(0) item set
Augmented
𝑜 𝑡 𝑜
grammar A a . A 𝐺
𝐺𝑜𝑡𝑜(𝐼0,𝑏) A. aA 𝐺𝑜𝑡𝑜(𝐼3,𝑎) A a . A
A b. 4 A. b 𝐺𝑜 𝑡 A. aA 3

𝑜(𝐼
3,𝑏 A. b
)
A b. 4

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 118
Rules to construct SLR parsing table
1. Construct , the collection of sets of LR(0) items for
2. Stateis constructed from . The parsing actions for state are determined as follow :
a) If is in  and GOTO  , then set to “shift j”. Here a must be terminal.
b) If is in , then set to “reduce A ” for all a in ; here A may not be S’.
c) If is in , then set action to “accept”.
3. The goto transitions for state i are constructed for all non terminals A using the
4. All entries not defined by rules 2 and 3 are made error.

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 119
Example: SLR(1)- simple LR
S AA . 5
S’ S. 𝑰𝟏
𝑰𝟐 𝐺𝑜𝑡𝑜(𝐼2, 𝐴) A a . A
𝑰𝟎 𝐺𝑜𝑡𝑜(𝐼0,𝑆) A. aA 3

S A . A ) A. b
𝐼( 2 , 𝑎
Action Go to
S’. S
0 , 𝐴 ) A. aA 𝑜 𝑡 𝑜
S. AA 𝑡𝑜 ( 𝐼 𝐺 Item a b $ S A

A. aA
𝐺𝑜 A. b
𝐺𝑜𝑡𝑜(𝐼2,𝑏)
A b. 4 set
𝐺𝑜 𝑡 0 S3 S4 1 2
A. b 𝑜 (𝐼 𝐴 )
0,𝑎 3
( 𝐼 3 , A aA . 6 1 Accept
) 𝑜𝑡 𝑜
A a . A 𝐺 2 S3 S4 5
𝐺𝑜𝑡𝑜(𝐼0,𝑏) A. aA 𝐺𝑜𝑡𝑜(𝐼3,𝑎) A a . A 3 S3 S4 6

A b. 4 A. b 𝐺𝑜 𝑡 A. aA 3 4 R3 R3 R3
𝑜(𝐼
3,𝑏 A. b 5 R1
S  AA
) 6 R2 R2 R2
A  aA | b A b. 4

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 120
Parsing Methods

Parsing

Top down parsing Bottom up parsing (Shift reduce)

Back tracking Operator precedence

Parsing without
backtracking (predictive LR parsing
Parsing)
SLR
LL(1)
CLR
Recursive
descent LALR

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 13 – Basic
Parsing
Probability
Theory (I) 121
How to calculate look ahead?
How to calculate look ahead?
SCC
S’  . S , $
C cC | d
A  . X ,
Closure(I)
S’.S,$
S.CC, $
C.cC, c|d S  . C C , $
C.d, c|d A  . X ,

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 122
Example: CLR(1)- canonical LR
5
S AA. ,$ 6 A aA.,$ 9

S’ S., $ 𝑰𝟏 A a.A,$


𝑜 ( 𝐼 6 , 𝐴 ) 6

𝐺𝑜𝑡𝑜(𝐼2, 𝐴) 𝐺𝑜 𝑡 A a.A,$
𝑰 𝟎 𝐺𝑜𝑡𝑜(𝐼0,𝑆)
𝑰𝟐 A. aA,$
𝐺𝑜 𝑡𝑜 ( 𝐼 6 , 𝑎 ) A. aA,$
𝐺𝑜 𝑡𝑜 ( 𝐼 6 , 𝑏)

, 𝑎)
A. b, $

(𝐼 2
S A.A,$ A. b, $
S’.S,$ ) A.aA, $

𝑡𝑜
A b. ,S
, 𝐴
𝐺𝑜
𝐼0
7 7
S.AA,$
𝑡 𝑜 ( A b. ,$
𝐺𝑜
A. b, $
A.aA, a|b 𝐺𝑜𝑡𝑜(𝐼2,𝑏)
8
A.b, a|b
, 𝐴 ) A aA.,a|b
3
( 𝐼 3 LR(1) item set
𝐺𝑜

Augmented
𝑜𝑡 𝑜
𝑡𝑜

grammar 𝐺
(𝐼 0

Aa.A, a|b 3

𝐺𝑜𝑡𝑜(𝐼0,𝑏)
,𝑎)

A.aA ,a|b 𝐺𝑜𝑡𝑜(𝐼3,𝑎) A a.A , a|b


A. b, a|b 𝐺 A.aA , a|b
A b., a|b 4 𝑜 𝑡𝑜
( 𝐼 3 A.b , a|b
, 𝑏)
S  AA
A  aA | b 4
A b., a|b

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 123
Example: CLR(1)- canonical LR
5
S AA. ,$ 6 A aA.,$ 9

S’ S., $ 𝑰𝟏 A a.A,$


𝑜 ( 𝐼 6 , 𝐴 ) 6

𝐺𝑜𝑡𝑜(𝐼2, 𝐴) 𝐺𝑜 𝑡 A a.A,$
𝑰 𝟎 𝐺𝑜𝑡𝑜(𝐼0,𝑆)
𝑰𝟐 A. aA,$
𝐺𝑜 𝑡𝑜 ( 𝐼 6 , 𝑎 ) A. aA,$
𝐺𝑜 𝑡𝑜 ( 𝐼 6 , 𝑏)

, 𝑎)
A. b, $

(𝐼 2
S A.A,$ A. b, $
S’.S,$ ) A.aA, $

𝑡𝑜
A b. ,S
, 𝐴
𝐺𝑜
𝐼0
7 7
S.AA,$
𝑡 𝑜 ( A b. ,S
𝐺𝑜
A. b, $
A.aA, a|b 𝐺𝑜𝑡𝑜(𝐼2,𝑏) Item Action Go to
8 set a b $ S A
A.b, a|b
, 𝐴 ) A aA.,a|b
3
( 𝐼 3
𝐺𝑜

𝑜𝑡 𝑜
𝑡𝑜

𝐺 0 S3 S4 1 2
(𝐼 0

Aa.A, a|b 3
1 Accept
𝐺𝑜𝑡𝑜(𝐼0,𝑏)
,𝑎)

A.aA ,a|b 𝐺𝑜𝑡𝑜(𝐼3,𝑎) A a.A , a|b 2 S6 S7 5


A. b, a|b 𝐺 A.aA , a|b 3 S3 S4 8
A b., a|b 4 𝑜 𝑡𝑜
( 𝐼 3 A.b , a|b 4 R3 R3
, 𝑏) 5 R1
S  AA 6 S6 S7 9
A  aA | b 4
A b., a|b 7 R3
8 R2 R2
Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 124
Parsing Methods
Parsing

Top down parsing Bottom up parsing (Shift reduce)

Back tracking Operator precedence

Parsing without
backtracking (predictive LR parsing
Parsing)
SLR
LL(1)
CLR
Recursive
descent LALR

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 13 – Basic
Parsing
Probability
Theory (I) 125
Example: LALR(1)- look ahead LR
5
S AA. ,$ 6 A aA.,$ 9

S’ S., $ 𝑰𝟏 A a.A,$


𝑡𝑜 ( 𝐼 6 , 𝐴) 6

𝑰 𝟐 𝐺𝑜𝑡𝑜(𝐼2, 𝐴) 𝐺𝑜 A a.A,$
𝑰𝟎 𝐺𝑜𝑡𝑜(𝐼0,𝑆)
A. aA,$
𝐺𝑜 𝑡𝑜 ( 𝐼 6 , 𝑎 ) A. aA,$
𝐺𝑜 𝑡𝑜 ( 𝐼 6 , 𝑏)

, 𝑎)
A. b, $

(𝐼 2
S A.A,$ A. b, $
S’.S,$ ) A.aA, $

𝑡𝑜
A b. ,$
, 𝐴

𝐺𝑜
𝐼0
7 7
S.AA,$
𝑡𝑜 ( A b. ,$
𝐺𝑜
A. b, $
A.aA, a|b 𝐺𝑜𝑡𝑜(𝐼2,𝑏) 36 CLR
8
A.b, a|b
, 𝐴 ) A aA.,a|b
3
( 𝐼 3 Aa.A, a|b|$
𝐺𝑜

𝑜𝑡 𝑜
𝑡𝑜

𝐺 A.aA , a|b|$
(𝐼 0

Aa.A, a|b 3
A. b, a|b|$
𝐺𝑜𝑡𝑜(𝐼0,𝑏)
,𝑎)

A.aA ,a|b 𝐺𝑜𝑡𝑜(𝐼3,𝑎) A a.A , a|b


A. b, a|b 𝐺 A.aA , a|b
A b., a|b 4 𝑜 𝑡𝑜 47

( 𝐼 3 A.b , a|b A b., a|b|$


, 𝑏)
S  AA 89

A  aA | b 4
A b., a|b A aA.,a|b|$

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 126
Example: LALR(1)- look ahead LR

Item Action Go to
set a b $ S A
Item Action Go to
0 S3 S4 1 2 set a b $ S A
1 Accept
2 S6 S7 5 0 S36 S47 1 2
3 S3 S4 8 1 Accept
4 R3 R3 2 S36 S47 5
5 R1 36 S36 S47 89
6 S6 S7 9 47 R3 R3 R3
7 R3 5 R1
8 R2 R2 89 R2 R2 R2
9 CLR Parsing Table
R2 LALR Parsing Table

Prof. Dixita
Jay R Dhamsaniya
B Kagathara #2170701
#3130006(CD)
(PS)  Unit 31 – Parsing
Basic Probability
Theory (I) 127
Thank You

You might also like