简体   繁体   English

解析树和推导?

[英]Parsing Tree and Derivation?

I don't understand the relantioship between parsing tree and derivation.我不明白解析树和推导之间的关系。 The parsing tree is invariant with respect to the derivation, but does this mean that regardless of the derivation (rightmost or leftmost) the parsing tree remains the same?解析树相对于推导是不变的,但这是否意味着无论推导(最右边或最左边)解析树保持不变? Or according to the method (rightmost or leftmost) does the parsing tree change?或者根据方法(最右边或最左边)解析树是否改变? Pls help me Sorry for my bad english.请帮助我对不起我的英语不好。

The parse tree is a record of the derivation.解析树是推导的记录。 Each non-leaf node of the tree is the result of a single derivation step.树的每个非叶节点都是单个推导步骤的结果。

At the root of the parse tree and at the beginning of the derivation, you find the grammar's start symbol.在解析树的根部和推导的开头,您可以找到语法的开始符号。 A derivation step replaces a non-terminal with the right-hand side of some production which has that non-terminal on the left-hand side.推导步骤将非终结符替换为左侧具有该非终结符的某些产生式的右侧。 In the tree, the node corresponding to the non-terminal is given a sequence of children, each one a symbol in the right-hand side of the production.在树中,对应于非终结符的节点被赋予一系列子节点,每个子节点在产生式的右侧都有一个符号。 Terminal symbols become leaf nodes and non-terminals will eventually become the top of a subtree.终端符号成为叶节点,非终端最终将成为子树的顶部。

If the grammar is unambiguous, there is only one parse tree for each derivable sentence.如果语法是明确的,则每个可派生的句子只有一个解析树。 But that parse tree represents a large number of possible derivations, unless the grammar is linear (that is, the right-hand side of every production contains at most one non-terminal).但是该解析树表示大量可能的推导,除非语法是线性的(即每个产生式的右侧最多包含一个非终结符)。 In a derivation which is being built, you can select any non-terminal for the next derivation step;在正在构建的推导中,您可以选择任何非终端进行下一个推导步骤; in the parse tree, you can select any node representing a non-terminal which does not yet have children.在解析树中,您可以选择表示尚未有子节点的非终端的任何节点。

The leftmost and rightmost derivations are just two of these many possibilities.最左边和最右边的推导只是众多可能性中的两种。 (Again, unless the grammar is linear, in which case the leftmost and rightmost derivations are the same derivation.) But a derivation doesn't have to be leftmost or rightmost. (同样,除非语法是线性的,在这种情况下,最左边和最右边的推导是相同的推导。)但是推导不必是最左边或最右边的。 At each step, it can choose any non-terminal, not only the leftmost or rightmost one.在每一步,它可以选择任何非终端,而不仅仅是最左边或最右边的一个。 In the tree representation, a possible derivation can be generated by any valid topological sort of the nodes.在树表示中,可能的推导可以由节点的任何有效拓扑排序生成。

But that doesn't matter in practical terms.但这实际上并不重要。 The only useful practical question is whether there is more than one different parse tree for each sentence in the grammar, which is exactly the same as asking whether there is more than one leftmost derivation or more than one rightmost derivation.唯一有用的实际问题是语法中的每个句子是否存在不止一个不同的解析树,这与询问是否存在多个最左推导或多个最右推导完全相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM