Exercise: construct the SLR parsing table for grammar: - PowerPoint PPT Presentation

About This Presentation
Title:

Exercise: construct the SLR parsing table for grammar:

Description:

Using ambiguous grammars. ambiguous grammars will results in conflicts ... May result in a smaller parsing table in comparison to using un-ambiguous grammars. ... – PowerPoint PPT presentation

Number of Views:541
Avg rating:3.0/5.0
Slides: 8
Provided by: xyu
Learn more at: http://www.cs.fsu.edu
Category:

less

Transcript and Presenter's Notes

Title: Exercise: construct the SLR parsing table for grammar:


1
  • Exercise construct the SLR parsing table for
    grammar
  • S-gtLR,
  • S-gtR
  • L-gtR
  • L-gtid
  • R-gtL
  • 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 -gt S
  • S -gt CC
  • C -gtcC
  • C -gtd

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-gtEE
  • E-gtEE
  • E-gt(E)
  • E-gtid
Write a Comment
User Comments (0)
About PowerShow.com