12
CONSTRUCTINGPR EDICTIVE LL(1) PARSER TABLE By, S.Nandini(12R21A05A8) Sweta Panwar(12R21A05A9) A.Sirisha(12R21A0562)

Constructingpredictive Ll(1) Parser Table

Embed Size (px)

DESCRIPTION

MLRIT 3rd year CSE

Citation preview

Page 1: Constructingpredictive Ll(1) Parser Table

CONSTRUCTINGPREDICTIVE LL(1) PARSER TABLEBy, S.Nandini(12R21A05A8)Sweta Panwar(12R21A05A9)A.Sirisha(12R21A0562)

Page 2: Constructingpredictive Ll(1) Parser Table

INTRODUCTION What is a parser? In computer technology, a parser is a

program, usually part of a compiler, that receives input in the form of sequential source program instructions and breaks them up into parts.

Page 3: Constructingpredictive Ll(1) Parser Table

PREDICTIVE LL(1): A predictive parser is a recursive

descent parser that does not require backtracking.

L – Reading from left to right L – Leftmost Derivation 1- Indicates that parser takes one input

at a time.

Page 4: Constructingpredictive Ll(1) Parser Table

REQUIREMENTS OF CONSTRUCTING PARSING TABLE

Page 5: Constructingpredictive Ll(1) Parser Table

REQUIREMENTS OF CONSTRUCTING PARSING TABLE

Input buffer to take the input string. A Stack is used to hold two functions: Shift: It is to replace non terminal by terminal

at the time of pushing on to the stack. Reducing: It is used for popping the input terms

by replacing the starting symbols. In stack ‘$’ indicates that initially stack is

empty.

Page 6: Constructingpredictive Ll(1) Parser Table

REQUIREMENTS OF CONSTRUCTING PARSING TABLE

A table is basically of two dimensional array on given input by predictive parser.

Constructing of table requires the two functions: FIRST() FOLLOW()

Page 7: Constructingpredictive Ll(1) Parser Table

RULES FOR CONSTRUCTING FIRST() FUNCTION VALUES:

Suppose that A is a non-terminal ,‘’ is a terminal and X1,X2,…Xn are the terminals.

If A-> then FIRST(A)={}If A-> then FIRST(A)={}If A->X1/X2/../Xn then

FIRST(A)=FIRST(X1)=FIRST(X2)=…=FIRST(XN).

Page 8: Constructingpredictive Ll(1) Parser Table

RULES FOR CONSTRUCTING FOLLOW() FUNCTION VALUES:

If A is a starting symbol,then FOLLOW(A)={$}.o If A->Bβ then FIRST(β) to be placed

in the FOLLOW(B) without .o If A->Bβ (or) A->B where β->

(FIRST(β)={} then FOLLOW(A)=FOLLOW(B).

Page 9: Constructingpredictive Ll(1) Parser Table

RULES FOR CONSTRUCTION OF PREDICTIVE LL(1) PARSING TABLE:

Based on FIRST() function we fill the table.

If occurs in given production,then go for FOLLOW() and fill the table of corresponding cell with production Nt-> .

Thus, the predictive parser table can be constructed.

Page 10: Constructingpredictive Ll(1) Parser Table

PREDICTIVE PARSING TABLE

E -> TE’E -> TE’|εT -> FT’T’ -> *FT’|εF -> (E)|id

Page 11: Constructingpredictive Ll(1) Parser Table

PREDICTIVE LL(1)PARSER TABLE BY COMPUTER SIMULATION:

Page 12: Constructingpredictive Ll(1) Parser Table

Thank you ….