③苇大 表驱动分析技术 Another method for implementing a predictive parser is called table-driven parsing that uses a table, called parse table, to store that production along with an explicit stack to keep track of where we are in the parse. We push the start symbol on the stack and read the first input token. as the parser works through the input there are the following possibilities for the top stack symbol X and the input token nonterminal a: (1)IfX=a and a=end of input(#): parser halts and parse completed successfully. (2) IfX=a and a[=# successful match, pop X and advance to next input token. This is called a match action. (3) IfX=a and X is a nonterminal, pop x and consult table at [X, a] to see which production applies, push right side of production on stack. This is called a predict action. (4 If none of the preceding cases applies or the table entry from step 3 is blank, there has been a parse error
表驱动分析技术 Another method for implementing a predictive parser is called table-driven parsing that uses a table, called parse table, to store that production along with an explicit stack to keep track of where we are in the parse. We push the start symbol on the stack and read the first input token. As the parser works through the input, there are the following possibilities for the top stack symbol X and the input token nonterminal a:(1) If X = a and a = end of input (#): parser halts and parse completed successfully.(2) If X = a and a != #: successful match, pop X and advance to next input token. This is called a match action.(3)If X != a and X is a nonterminal, pop X and consult table at [X,a] to see which production applies, push right side of production on stack. This is called a predict action.(4) If none of the preceding cases applies or the table entry from step 3 is blank, there has been a parse error
③苇大 分析表的构造 1. For each production A-> u of the grammar, do steps 2 and 3 2. For each terminal a in First(u), add a->u to MIA. al 3. Ife in First(u),(i.e. A is nullable)add A to miA, b] for each terminal b in Follow (A) If s in First(u), and is in Follow (A), add A >u to MA, #f 4. All undefined entries are errors
分析表的构造 1. For each production A –> u of the grammar, do steps 2 and 3 2. For each terminal a in First(u), add A –> u to M[A,a] 3. If in First(u), (i.e. A is nullable) add A –> u to M[A,b] for each terminal b in Follow(A), If in First(u), and # is in Follow(A), add A – > u to M[A,#] 4. All undefined entries are errors
③苇大 自下而上分析 ◇自下而上分折一般过程 ◇移进归约技术 ◇LR分析技术 ◇补充:算符优先分析技术
自下而上分析 自下而上分析一般过程 移进归约技术 LR 分析技术 补充:算符优先分析技术