Syntax Tree | Abstract Syntax Tree | Parse Tree | Annotated Parse Tree

Syntax Tree 

  • A syntax tree describes the abstract syntactic structure of source code written in a programming language. 
  • In the syntax tree, we can eliminate the extra information.
  • In the syntax tree, interior nodes are operators and leaves are operands.
  • Syntax tree is usually used when represent a program in a tree structure.
  • Syntax tree helps to determine the accuracy of the compiler. If the syntax tree contains an error, the compiler displays an error message. 
  • Program analysis and program transformation are some other uses of the syntax tree.

Abstract syntax tree is another name for the syntax tree.

A sentence id + id * id would have the following syntax tree:

Parse tree and Syntax tree 1


Parse Tree 

A parse tree is an ordered, rooted tree that represents the syntactic structure of a string according to some context-free grammar. 

Parsing tree, derivation tree, and concrete syntax tree are some other names for parse tree 

Example:

Production

S= S+ S | S * S  

S = a|b|c  

Input:

a * b + c

 

Parse tree5

 

Annotated Parse Tree – The parse tree containing the values of attributes at each node for given input string is called annotated or decorated parse tree.

Features –

  • High level specification
  • Hides implementation details
  • Explicit order of evaluation is not specified

 SyntaxDirected Translation 1 SyntaxDirected Translation 1 Grammar symbols


Difference

The main difference between parse tree and syntax tree is that parse tree is a hierarchical structure that represents the derivation of the grammar to obtain input strings while syntax tree is a way of representing the syntax of a programming language as a hierarchical tree similar structure.

 Moreover, parse tree contains records of the rules (tokens) to match input texts while syntax tree contains records of the syntax of programming language. Hence, this is another major difference between parse tree and syntax tree.

 


 

No comments:

Post a Comment

Monk and Inversions

using System; public class Solution { public static void Main () { int T = Convert . ToInt32 ( Console . ReadLine...