语法分析review

语法分析review

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
语语语语语语语语 语语语语语语 语语语语语语 语语 语语语语语语语语
Background image of page 1

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

View Full DocumentRight Arrow Icon
语语语语语语 语语语语语语语语语语 LL 1 语语语 语语语语语语 - 语语语语语语语语 - 语语语语语语语
Background 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.
Background image of page 3

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

View Full DocumentRight 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)
Background 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
Background image of page 5

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

View Full DocumentRight 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).
Background 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.
Background image of page 7

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

View Full DocumentRight 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
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/23/2011 for the course CS Compile taught by Professor Weizhong during the Spring '05 term at Fudan University.

Page1 / 42

语法分析review

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online