Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 310 – Fall 2006 Pacific University CS310 Parsing with Context Free Grammars Today’s reference: Compilers: Principles, Techniques, and Tools by: Aho,

Similar presentations


Presentation on theme: "CS 310 – Fall 2006 Pacific University CS310 Parsing with Context Free Grammars Today’s reference: Compilers: Principles, Techniques, and Tools by: Aho,"— Presentation transcript:

1 CS 310 – Fall 2006 Pacific University 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 CS 310 – Fall 2006 Pacific University 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 CS 310 – Fall 2006 Pacific University 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 cbabccba bcbabbccba abbcba cbacbabba (1) S -> zAB (2) S -> AB (3) A -> aA (4) A -> BC (5) B -> cb (6) B -> b (7) C -> c zcbcb abcc zacbcb zabcbcb abcbcb aaacbbbcacb abbcb abcabc

4 CS 310 – Fall 2006 Pacific University LL(2) Parse Table Two lookahead symbols aaabac S A B (1) S -> AcB (2) A -> aAb (3) A -> aBb (4) B -> ccb (5) B -> b

5 CS 310 – Fall 2006 Pacific University 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 StackInputAction $ $ x x + x * x $ + x * x $ shift


Download ppt "CS 310 – Fall 2006 Pacific University CS310 Parsing with Context Free Grammars Today’s reference: Compilers: Principles, Techniques, and Tools by: Aho,"

Similar presentations


Ads by Google