1 / 8

Compilers

Compilers. ABHISHEK REDDY PAM (11cs30002) date : 07/10/2013. Viable Prefix. The set of prefixes of right sentential forms that can appear on the stack of a shift-reduce parser are called viable prefixes.

jock
Télécharger la présentation

Compilers

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. Compilers ABHISHEK REDDY PAM (11cs30002) date : 07/10/2013

  2. Viable Prefix • The set of prefixes of right sentential forms that can appear on the stack of a shift-reduce parser are called viable prefixes. • Right-Sentential Form : A sentential form that can be derived by a rightmost derivation • The prefix of the sentential form may not be the content of the stack.

  3. Example Consider: S  aABe A  Abc | b B  d Rightmost Derivation of the string abbcde: S  aABe  aAde  aAbcde  abbcde The (unique) handle is underlined for each step.

  4. Continuation… A viable prefix is : (1) a string that equals a prefix of a right-sentential form up to (and including) its unique handle. (2) any prefix of a string that satisfies (1) For given example : Viable prefixes: a, aA, aAd, aAbc, ab, aAb,… Not viable prefixes: aAde, Abc, aAA,…

  5. Shift/Reduce Parser All strings in the stack are viable prefixes

  6. When to shift/reduce ? • Sometimes on top of the stack something appears to be a handle (i.e., matches the RHS of a production). • But: maybe we have not shifted enough elements to identify the handle. • Observe the correct sequence of Shift and Reducesteps preserves the property that the stack IS a viable prefix. Example : $aAbcde$ Shift or Reduce? • If we shift we obtain aAbcin the stack (aA is the valid item for the viable prefix aAbc). Recall that Abcis a handle. • Instead if we reduce we obtain aAAin the stack. (this is NOT a viable prefix!!!)

  7. Valid Items DEFINITION: A α.β,{a} is a valid LR(1)-item for a viable prefix γα if there exists a right-most derivation. S γAy  γαβy Such that • a is the first symbol of y (or) • y = ε and a = $

  8. THE END • A DFA accepting viable prefixes. Its states are sets of LR(1)-items (that are valid for the corresponding viable prefixes) • Canonical LR Parser(LR(1) Parser) , States and encoding of valid items and viable prefixes are discussed in the next lecture.

More Related