③苇大 Fo|low集 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)
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)
③苇大 计算 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)-s to First(u) 2. If X1 is a nullable nonterminal. i e. x1=>c. add First(X2)-8 to First(u). Furthermore if X2 can also go to s, then add First(X3 )-8 and so on, through all xn until the first nonnullable one 3. If X1X2.Xn =>8. add s to the first set
计算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
③苇大 计算Foow集 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 s is placed in Follow(B) 3. For every production A-> uB, or a production A-> u Bv where First(v)contains s(i.e. v is nullable), then everything in Follow (A) is added to Follow (B)
计算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)
③苇大 预测分析程序 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 To enable this the grammar must take a particular form, that is, a grammar LlO
预测分析程序 Predictive parser is a non-backtracking topdown 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. To enable this, the grammar must take a particular form,that is, a grammar LL(1)
③苇大 递归下降分析技术 The first technique for implementing a predictive parser is called recursive-descent A recursive descent parser consists of several small functions(procedures), one for each nonterminal in the grammar. as we parse a sentence we call the functions(procedures) that correspond to the left Side nonterminal of the productions we are applying If these productions are recursive, we end up calling the functions recursively
递归下降分析技术 The first technique for implementing a predictive parser is called recursive-descent. A recursive descent parser consists of several small functions(procedures), one for each nonterminal in the grammar. As we parse a sentence, we call the functions (procedures) that correspond to the left side nonterminal of the productions we are applying. If these productions are recursive, we end up calling the functions recursively