BOTTOM UP PARSING2

BOTTOM UP PARSING2 - BOTTOM UP PARSING contd. 1...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
1 BOTTOM UP PARSING contd….
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 shift/reduce and reduce/reduce conflicts If a state does not know whether it will make a shift operation or reduction for a terminal, we say that there is a shift/reduce conflict . If a state does not know whether it will make a reduction operation using the production rule i or j for a terminal, we say that there is a reduce/reduce conflict . If the SLR parsing table of a grammar G has a conflict, we say that that grammar is not SLR grammar.
Background image of page 2
3 Conflict Example S L=R I 0 : S’ .S I 1 : S’ S. I 6 : S L=.R I 9 : S L=R. S R S .L=R R .L L *R S .R I 2 : S L.=R L .*R L id L .*R R L. L .id R L 3 : S R. 4 : L *.R I 7 : L *R. Problem R .L FOLLOW(R)={=,$} L .*R I 8 : R L. = shift 6 L .id reduce by R L shift/reduce conflict I 5 : L id.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 LR(1) items A LR(1) item is: A α . β ,a where a is the look-head of the LR(1) item ( a is a terminal or end-marker.) When β ( in the LR(1) item A α . β ,a ) is not empty, the look-head does not have any affect. When β is empty (A α . ,a ), we do the reduction by A →α only if the next input symbol is a (not for any terminal in FOLLOW(A)). A state will contain A α . ,a 1 where {a 1 ,...,a n } FOLLOW(A) ...
Background image of page 4
5 Canonical Collection of Sets of LR(1) Items The construction of the canonical collection of the sets of LR(1) items are similar to the construction of the canonical collection of the sets of LR(0) items, except that closure and goto operations work a little bit different. closure(I) is: ( where I is a set of LR(1) items) every LR(1) item in I is in closure(I) if A →α . B β ,a in closure(I) and B →γ is a production rule of G; then B . γ ,b will be in the closure(I) for each terminal b in FIRST( β a) .
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 goto operation If I is a set of LR(1) items and X is a grammar symbol (terminal or non-terminal), then goto(I,X) is defined as follows: If A α .X β ,a in I then every item in closure({A α X. β ,a}) will be in goto(I,X).
Background image of page 6
7 Construction of The Canonical LR(1) Collection Algorithm : C is { closure({S’ .S,$}) } repeat the followings until no more set of LR(1) items can be added to C . for each I in C and each grammar symbol X if goto(I,X) is not empty and not in C add goto(I,X) to C goto function is a DFA on the sets in C.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 A Short Notation for The Sets of LR(1) Items A set of LR(1) items containing the following items A α . β ,a 1 ... A α . β ,a n can be written as A α . β ,a 1 /a 2 /.../a n
Background image of page 8
9 LR (1) Items -Example S CC C cC|d Augmented Grammar S’ S S CC C cC|d Start with closure { S’ .S,$} I 0 . {S’ .S, $ S .CC,$ C . cC, c/d C . d, c/d }
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 State 1 from State 0 (goto( I0,S) I1: { S’ S., $} S’ .S,$ S .CC,$ C .cC,c/d C .d, c/d S’ S.,$ I0 S I1
Background image of page 10
11 State 2 from State 0 ( GOTO (I0,C) State 3 from 0 ( GOTO ( I0,c) State 4 from 0 (GOTO (I0,d) I2: { S C.C,$ C .cC,$ C .d,$ } I3: { C c.C,c/d C .cC, c/d C .d,c/d } I4: { C d.,c/d } DFA upto this point is shown in the next slide
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
12 S’ .S,$ S .CC,$ C .cC,c/d C .d, c/d
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/20/2010 for the course CS 101 taught by Professor Aga during the Spring '10 term at Jaypee University IT.

Page1 / 44

BOTTOM UP PARSING2 - BOTTOM UP PARSING contd. 1...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online