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

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

问题描述

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天全站免登陆