术语解析树和派生树之间有什么区别? [英] Any differences between terms parse trees and derivation trees?

查看:293
本文介绍了术语解析树和派生树之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当引用符合语法的文本的结果时,术语AST(抽象语法树),解析树和派生树被不同的人所束缚.假设我们正在谈论解析计算机语言,它们之间的差异是否足够细微,以至于我们可以互换使用这些术语?如果没有,我们如何正确使用这些术语?

The terms AST (Abstract Syntax Tree), parse tree and derivation tree are bandied about by different people when referring to the result of parsing texts conforming to a grammar. Assuming we are talking about parsing computer languages, are their differences minute enough that we can use these terms interchangeably ? If not, how do we use the terms correctly ?

推荐答案

AFAIK,派生树"和解析树"是相同的.

AFAIK, "derivation tree" and "parse tree" are the same.

抽象语法树

在计算机科学中,抽象语法树(AST)或仅是语法树,是用编程语言编写的源代码抽象句法结构的树表示.树的每个节点表示在源代码中出现的构造.从某种意义上说,该语法是抽象的",因为它并不代表真实语法中出现的每个细节.

In computer science, an abstract syntax tree (AST), or just syntax tree, is a tree representation of the abstract syntactic structure of source code written in a programming language. Each node of the tree denotes a construct occurring in the source code. The syntax is 'abstract' in the sense that it does not represent every detail that appears in the real syntax.

解析树

具体的语法树或语法分析树或语法分析树是一棵(有序的,有根的)树,表示根据某种形式语法的字符串的语法结构.在解析树中,内部节点用语法的非终结符标记,而叶子节点用语法的终结符标记.

A concrete syntax tree or parse tree or parsing tree is an (ordered, rooted) tree that represents the syntactic structure of a string according to some formal grammar. In a parse tree, the interior nodes are labeled by non-terminals of the grammar, while the leaf nodes are labeled by terminals of the grammar.

以源a = (1 + 2) * 3;为例. 分析树可能看起来像:

Take the source a = (1 + 2) * 3; for example. The parse tree could look like:

    ASSIGNMENT
   / / |      \
  / /  |       \ 
 a = expression ;
       /   \
 expression \ 
   / | \     \
  (  +  )     *
    / \        \
   1   2        3

抽象语法树可能看起来像:

ASSIGNMENT
  /    \
 a   expression 
      /     \
 expression  *
     |        \ 
     +         3 
    / \
   1   2

这篇关于术语解析树和派生树之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆