Ambiguous sentences Characteristics and Problems - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Ambiguous sentences Characteristics and Problems

Description:

there may be exponentially many parse trees or even infinitely many of them. while predicting items it may stumble upon an empty prediction which means that the ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 22
Provided by: pla115
Category:

less

Transcript and Presenter's Notes

Title: Ambiguous sentences Characteristics and Problems


1
Ambiguous sentencesCharacteristics and Problems
  • More than one item can represent the same set
    which leads to ambiguity
  • the parse trees will be produced top-down
  • when searching a completed set for items of the
    form
  • there may be exponentially many parse trees or
    even infinitely many of them

2
(No Transcript)
3
(No Transcript)
4
  • while predicting items it may stumble upon an
    empty prediction which means that the
    non-terminal A has been completed just before
    symbol number and this completed item should be
    added to the completed set
  • run the Completer again and it will draw the
    consequences of the newly completed items
  • if it finds occurrences of the predicted
    non-terminal new predictions have to be done
    which means more work for the Completer

5
keep running the predictor and the completer in
turn
6
(No Transcript)
7
Prediction look-ahead
  • In a prediction step the next terminal is used as
    look-ahead and we check whether
  • it is a member of the first set of the RHS of
    the production we want to predict and only if it
    si positive we want to make the prediction
  • a Predictor that will never predict anything
    obviously erroneous all its predicted items will
    be either completed or active in the next set.(
    The predictions may however fail on the symbol
    after that).

8
(No Transcript)
9
(No Transcript)
10
  • The artificial grammar of figure 7.19 produces
    nothing but the three sentences p,q and pq,and
    does so in a straightforward way.The root is S
    rather than S

11
Parsing of the sentence q
  • Starting from the initial item,the Predictor
    predicts a list of 7 items.
  • looking at the next symbol,q,the Predictor
  • could easily avoid the prediction C?.p_at_1, but
    several of the other predictions are also false
  • the Predictor could avoid the first since it
    sees that it cannot begin with q
  • Itemset1 is empty,indicating that there is no waz
    for the input to continue
  • calculate the first sets of all non-terminals in
    the grammar

12
(No Transcript)
13
  • the Predictor starts again from the initial item
  • predictive look-ahead reduces the number
  • of items by 20 to 50 or even more on
    practical grammars

14
(No Transcript)
15
Reduction look-ahead
  • calculate the FIRST sets, we can use them for
    asecond type of look-ahead
  • reduction look-ahead reduces the number
  • of completed items
  • the redunduncy of the completed items
  • are only meaningful at the end of the input
  • keep,together with any item, a set of symbols
    which may come after that item,the reduction
    look-ahead setif the item seems completed but
    the next symbol is not in this set,the item is
    discarded

16
(No Transcript)
17
Construction of a look-ahead set
  • straightforward rules
  • the prediction look-ahead cannot be calculated
    in advance
  • a limited and less effective set could be
    calculated statically,using the FOLLOW sets
  • the initial item starts with a look-ahead set of
  • when the dot advances in an item, the look-
    ahead set remains the same
  • when a new item is created by the Predictor, a
    new look-ahead set must be composed
  • the look-ahead ... Is used to indicate that the
    look-ahead is not yet known but does not
    influence the look-ahead the item contributes

18
Suppose that the item is P?A . BCD a b c _at_n
  • What symbols may follow the occurrence of B in
    this item
  • any symbol C can start with
  • if C can produce the empty string ,any symbol D
    can start with
  • if D can also produce the empty string, any of
    the symbols a,b and c
  • the resulting new reduction look-ahead set is
    written as FIRST(CD abc)

19
(No Transcript)
20
Effectiveness of prediction look-ahead
  • not easily determined
  • Earley recommends the reduction look-ahead ,but
    does not take into account the effort required to
    calculate and maintain the look-ahead sets.
  • may easily double the number of items to be
    carried around
  • Implementation cost and overhead are considerable

21
J. Earley, An efficient context-free parsing
algorithm, Commun. ACM, vol. 13, no. 2, p.
94-102, Feb 1970
Write a Comment
User Comments (0)
About PowerShow.com