written 8.5 years ago by | • modified 8.5 years ago |
S-> A
A-> aB| Ad
B->bBC|f
C→g
This question appears in Mumbai University > System programming and compiler construction subject
Marks: 10 M
Year: May 2015
written 8.5 years ago by | • modified 8.5 years ago |
S-> A
A-> aB| Ad
B->bBC|f
C→g
This question appears in Mumbai University > System programming and compiler construction subject
Marks: 10 M
Year: May 2015
written 8.5 years ago by | • modified 8.5 years ago |
Recursive decent parsing
Back Tracking
To understand this, take the following example of CFG:
S → rXd | rZd
X → oa | ea
Z → ai
Predictive Parsing
Stack:- It consist $ to indicate end of stack.
Driver Routine:- It is a function that drives the Parser.
Parser Table:- It determines the actions to be carried out by the parser
The goal of predictive parsing is to construct a top-down parser that never backtracks. To do so, we must transform a grammar in two ways:
Steps for designing Predictive Parser:
Example:
S-> A
A-> aB| Ad
B->bBC|f
C→g
Step 1:
A -> Ad/aB
LR
A -> aBA’
A’-> dA’|€
S -> A
B -> bBC|f
C -> g
Step 2
FIRST
FOLLOW
Step 3
Step 4
Repeat forever
{ Lest ‘X’ be the stack top symbol
And ‘a’ be the input symbol
If X=a=$ then accept and break
else if X=a=$
then
Pop X from stack
Remove a from input
Else
If M[X,a] = x y1,y2…….yk
Then
Pop X from stack
Push yk,yk+1…….y2,y1 on the stack
Else
ERROR()
}