1 / 13

top-down parsing

Delve into the concepts of top-down parsing strategies in COP4620 - Programming Language Translators under the guidance of Dr. Manuel E. Bermudez. Explore the game-like approach of syntactic dominoes, parsing techniques, and the use of Omniscient Parsing Functions (OPF) to decode complex grammars efficiently.

johnathann
Download Presentation

top-down parsing

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. top-down parsing COP4620 – Programming Language Translators Dr. Manuel E. Bermudez

  2. topics • The Game of Syntactic Dominoes • Strategies for parsing • Top-Down Parsing • Define OPF

  3. The grammar: E → E+T T → P*T P → (E) → T → P →i The playing pieces: An arbitrary supply of each piece (one per grammar rule). The game board: Start domino at the top. Bottom dominoes are the "input." The Game of Syntactic Dominoes

  4. SyntacticdominoesTheGameBoard

  5. Game rules: Add game pieces to the board. Match the flat parts and the symbols. Lines are infinitely elastic (and cannot cross). Object of the game: Connect start domino with the input dominoes. Leave no unmatched flat parts. The Game of Syntactic Dominoes

  6. Same as for the game of syntactic dominoes. “Top-down” parsing: start at the start symbol, work toward the input string. “Bottom-up” parsing: start at the input string, work towards the goal symbol. In either strategy, can process the input left-to-right  or right-to-left  Parsing Strategies

  7. Attempt a left-most derivation, by predicting the re-write that will match the remaining input. Use a string (a stack, really) from which the input can be derived. Start with S on the stack. At every step, two alternatives:  (the stack) begins with a terminal t: match t against input.  begins with a nonterminal A: Consult an OPF (Omniscient Parsing Function) to determine which production for A to use. Top-Down Parsing

  8. Sample top-downparse • E → E+T • → T • T → P*T • → P • P → (E) • → i

  9. Push (Stack, S); while not Empty (Stack) do if Top(Stack) ∊  then if Top(Stack) = Head(input) then input := tail(input) Pop(Stack) else error (Stack, input) else P:= OPF (Stack, input) Push (Pop(Stack), RHS(P)) od Classic Top-Down Parsing Algorithm

  10. top-down parsing: general scheme

  11. Most parsing methods (for PL’s) impose bounds: input lookahead: 1. We define OPF (A,t), where A: top element of the stack, and t: first symbol on the input. Storage requirements: O(n2), where n is the size of the grammar vocabulary (a few hundred). Top-Down Parsing

  12. S → A A → bAd → Sample opf Stack Input OPF S bdd S bbdd

  13. summary • The Game of Syntactic Dominoes • Strategies for parsing • Top-Down Parsing • Define OPF

More Related