1 / 7

Exercise: construct the SLR parsing table for grammar: S->L=R, S->R L->*R L->id R->L The grammar can have

Exercise: construct the SLR parsing table for grammar: S->L=R, S->R L->*R L->id R->L The grammar can have shift/reduce conflict or reduce/reduce conflict. What about shift/shift conflict?.

yeshaya
Télécharger la présentation

Exercise: construct the SLR parsing table for grammar: S->L=R, S->R L->*R L->id R->L The grammar can have

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Exercise: construct the SLR parsing table for grammar: S->L=R, S->R L->*R L->id R->L • The grammar can have shift/reduce conflict or reduce/reduce conflict. • What about shift/shift conflict?

  2. SLR does not always remember the right context -- using the follow set to determine when to reduce is sometimes too general. • LR(1) parsing table has more context information in its items. • An LR(1) item is of the form • terminal a has not effect when is not . • When is , an item of the form means to reduce only when the next input symbol is a.

  3. Computing sets of LR(1) items. • Closure(I) is now slightly different • Start the construction of the set of LR(1) items by computing the closure of

  4. Example 1: first page • Example 2: S’ -> S S -> CC C ->cC C ->d

  5. Constructing the LR(1) parsing table

  6. The number of states in LR(1) parsing table is much more than that in SLR parsing table. • LALR reduces the number of states in LR(1) parsing table. • LALR (LookAhead LR) is less powerful than LR(1) • reducing states may introduce reduce-reduce conflict, but not shift-reduce conflict. • LALR has the same number of states as SLR, but more powerful. • Constructing LALR parsing table. • Combine LR(1) sets with the same sets of first parts (ignore lookahead). • Algorithms exist that skip constructing the LR(1) sets.

  7. Using ambiguous grammars • ambiguous grammars will results in conflicts • Can use precedence and assocativity to resolve the conflicts • May result in a smaller parsing table in comparison to using un-ambiguous grammars. • Example: E->E+E E->E*E E->(E) E->id

More Related