1 / 5

CS310

CS310. Parsing with Context Free Grammars Today’s reference: Compilers: Principles, Techniques, and Tools by: Aho, Sethi, Ullman aka: The Dragon Book Section 4.4 – 4.8 October 30, 2006. Top-Down Parsing. LL(1) parser parse from Left to right produces a Leftmost derivation

hateya
Download Presentation

CS310

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. CS310 Parsing with Context Free Grammars Today’s reference: Compilers: Principles, Techniques, and Tools by: Aho, Sethi, Ullman aka: The Dragon Book Section 4.4 – 4.8 October 30, 2006

  2. Top-Down Parsing • LL(1) parser • parse from Left to right • produces a Leftmost derivation • always replace the left-most nonterminal first • with 1 lookahead symbol • LL(1) Grammars • FIRST and FOLLOW uniquely determine which productions to use to parse a string • not all grammars are LL(1) • common prefixes • left recursion (talked about Wednesday)

  3. Parsing with JFLAP • FIRST? FOLLOW? Parse Table? (1) S -> AcB (2) A -> aAb (3) A ->aBb (4) B -> ccb (5) B -> b (1) S -> AcB (2) A -> aAb (3) A ->Bb (4) B -> bBb (5) B -> cba (1) S -> zAB (2) S -> AB (3) A ->aA (4) A -> BC (5) B -> cb (6) B -> b (7) C -> c cbabccba bcbabbccba abbcba cbacbabba aaacbbbcacb abbcb abcabc zcbcb abcc zacbcb zabcbcb abcbcb

  4. LL(2) Parse Table (1) S -> AcB (2) A -> aAb (3) A ->aBb (4) B -> ccb (5) B -> b • Two lookahead symbols

  5. Bottom Up Parsing • Shift-reduce parsing • used in many automatic parser generators, YACC/Bison • Reduce the string to the start symbol • Shift a symbol from the string on to a stack (1) E -> E +E (2) E -> E * E (3) E ->( E ) (4) E -> x

More Related