{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

语法分析review

语法分析review

Info icon This preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
语语语语语语语语 语语语语语语 语语语语语语 语语 语语语语语语语语
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
语语语语语语 语语语语语语语语语语 LL 1 语语语 语语语语语语 - 语语语语语语语语 - 语语语语语语语
Image of page 2
语语语语语语语语语语 In the top-down parsing,we begin with the start symbol and at each step, expand one of the remaining nonterminals by replacing it with the right side of one its productions. We repeat until only terminals remain. The top- down parse create a leftmost derivation of the sentence.
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
LL 1 语语语 The first “L” means we scan the input from left to right; the second “L” means we create a leftmost derivation; and the 1 means one input symbol of lookahead. A grammar G is LL(1) iff whenever A –> u | v are two distinct productions of G, the following conditions hold: - for no terminal a do both u and v derive strings beginning with a (i.e. first sets are disjoint) - at most one of u and v can derive the empty string - if v =>* ε then u does not derive any string beginning with a terminal in Follow(A)
Image of page 4
The first set of a sequence of symbols u , written as First(u ) is the set of terminals which start all the sequences of symbols derivable from u . A bit more formally, consider all strings derivable from u by a leftmost derivation. If u =>* v , where v begins with some terminal, that terminal is in First(u). If u =>* ε , then ε is in First(u ). First
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Follow The follow set of a nonterminal A is the set of terminal symbols that can appear immediately to the right of A in a valid sentential form. A bit more formally, for every valid sentential form S =>* uAv , where v begins with some terminal, that terminal is in Follow(A).
Image of page 6
语语 First To calculate First(u) where u has the form X1X2...Xn , do the following: 1. If X1 is a terminal, then add X1 to First(u) , otherwise add First(X1) - ε to First(u ) . 2. If X1 is a nullable nonterminal, i.e., X1 =>* ε , add First(X2) - ε to First(u) . Furthermore, if X2 can also go to ε , then add First(X3) - ε and so on, through all Xn until the first nonnullable one. 3. If X1X2...Xn =>* ε , add ε to the first set.
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
语语 Follow For each nonterminal in the grammar, do the following: 1. Place # in Follow(S) where S is the start symbol and # is the input's right endmarker.The endmarker might be end of file, it might be newline, it might be a special symbol, whatever is the expected end of input indication for this grammar. We will typically use # as the endmarker. 2. For every production A –> uBv where u and v are any string of grammar symbols and B is a nonterminal, everything in First(v) except ε is placed in Follow(B). 3. For every production A –> uB , or a production A –> u Bv where First(v ) contains ε (i.e. v is nullable), then everything in Follow(A) is added to Follow(B).
Image of page 8
语语语语语语 Predictive parser is a non-backtracking top-down parser. A predictive parser is characterized by its ability to choose the production to apply solely on the basis of the next input symbol and the current nonterminal being processed.
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern