📜  自顶向下解析和自底向上解析的区别

📅  最后修改于: 2021-09-27 15:12:07             🧑  作者: Mango

解析中有两种类型的解析技术,第一种是自顶向下解析,第二种是自底向上解析。

自顶向下解析是一种解析技术,首先查看解析树的最高级别,然后使用语法规则向下处理解析树,而自底向上解析是一种首先查看解析最低级别的解析技术树并使用语法规则构建解析树。

存在一些差异来区分这两种解析技术,如下所示:

S.No Top Down Parsing Bottom Up Parsing
1. It is a parsing strategy that first looks at the highest level of the parse tree and works down the parse tree by using the rules of grammar. It is a parsing strategy that first looks at the lowest level of the parse tree and works up the parse tree by using the rules of grammar.
2. Top-down parsing attempts to find the left most derivations for an input string. Bottom-up parsing can be defined as an attempts to reduce the input string to start symbol of a grammar.
3. In this parsing technique we start parsing from top (start symbol of parse tree) to down (the leaf node of parse tree) in top-down manner. In this parsing technique we start parsing from bottom (leaf node of parse tree) to up (the start symbol of parse tree) in bottom-up manner.
4. This parsing technique uses Left Most Derivation. This parsing technique uses Right Most Derivation.
5. It’s main decision is to select what production rule to use in order to construct the string. It’s main decision is to select when to use a production rule to reduce the string to get the starting symbol.