slr parser
Download
Skip this Video
Download Presentation
SLR Parser

Loading in 2 Seconds...

play fullscreen
1 / 4

SLR Parser - PowerPoint PPT Presentation


  • 163 Views
  • Uploaded on

SLR Parser. Problems. • Problems with SLR parser: The SLR parser discussed in the earlier class has certain flaws. 1. A state may include a final item (one in which the position marker is at the end) and a non- final item. This may result in a shift-reduce conflict .

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'SLR Parser' - saeran


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slr parser

SLR Parser

Problems

slide2

• Problems with SLR parser:

The SLR parser discussed in the earlier class has certain flaws.

1. A state may include a final item (one in which the position marker is at the end) and a non- final item. This may result in a shift-reduce conflict .

2. A state may include two different final items. This might result in a reduce-reduce conflict .

• Can we have reduce-reduce conflicts in unambiguous grammars?

• Can we have a shift-shift conflict ?

However SLR reduces only when the next token is in Follow of the left-hand side of the production. Proper choices may help to resolve reduce-reduce conflicts.However, still similar conflicts exist:

->Shift-reduce conflicts include the case in which

Follow of the lhs nonterminal of any final item overlaps with first token after the dot in any of the remaining items in that item set.

Reduce-reduce conflicts include the case Follow of left-hand-sides of more than one final items in an item set overlap.

This grammar is called LR(0.5) or SLR.This is because when we reduce,we do not really consider the lookahead.The production is placed in the table corresponding to the entire follow set of the nonterminal.Hence this cannot strictly be referred to as LR(1).

slide3

Let us consider the grammar.

0. S’->S

1. S->E

2. E->L=R

3. E->R

4. L->*R

5. L->id

6. R->L

Construcing the item set:

Io={S’->.S, S->.E, E->.L=R, E->.R, L->.*R, L->.id, R->.L}

I1= {S’->S.}

I2 = {S  .E}

I3 = {E L.=R , RL.}

I4 = { E L=.R , R.L ,L  .*R , L.id}

I5 = {E  L=R.}

I6 = {E  R.}

I7 = { L  *.R , R.L ,L  .*R , L.id}

I8 = { L  *R. }

I9 = {L id.}

slide4

So in the Parsing table we have the following conflict when the follow ‘=’ appears.

|.…..……………………………………

| …. ….. ‘=’ ….. ……

I3 …. ….. s4/r6 ….. ……. -> shift reduce conflict

Hence our next approach is to try LR(1) parser.

Ridhima Kedia

04CS1021

ad