100 likes | 124 Views
chapter 6:bottom-up analysis. 6.1 introduction 1.basic idea:start from the input-string,reduce upward step by step by using grammar,try to get to the start symbol. if the final root node is start symbol,the string is therefore a legal sentence,or else not. 2.the problem encountered
E N D
chapter 6:bottom-up analysis 6.1 introduction 1.basic idea:start from the input-string,reduce upward step by step by using grammar,try to get to the start symbol. if the final root node is start symbol,the string is therefore a legal sentence,or else not.
2.the problem encountered at each step of reduction,two basic problems were faced: first: how to determine an simple phrase to reduce? second: what non-terminator will be reduced?
3.solution because the analysis process is to scan string from left to right,so the problem is to seek handle, then the problem of finding to-be-reduced part in a string is to find handle. but how to determine a handle?
4.algorithm to answer the above mentioned question, we introduce precedence relations definition to a grammar.that is =,< and > for a given grammar G,each to symbols R,S they may appear adjacently in a sentence-pattern,they have one of the following precedence relations:
+ 1)R=S iff(if and only if) there exist the rule form like : U→... RS ... 2)R<S iff U→... RV ... and V →S... 3)R>S iff U→... VW .. and V →...R and W →S... + *
According to this ,we design the algorithm,its kernel is shift-reduce strategy. let me illustrate it with an example. ex6.2 If G[S] S→bMb M→(L | a L→Ma) easy to obtain the simple precedence array:
analyze a so-called sentence to see if it is legal let w=b(aa)b
5.now let us summarize the contents mentioned above,and give a brief description of the algorithm: first introduce a stack to hold symbols; according to the scan-order to push symbols into (shift in) the stack; see if there is a handle in the stack; the process involves four kinds of activities: they are:shift,reduce,accept ,error report you should take attention to handle recognizing method and the use of array.