1 / 7

From a parse tree to a syntax tree:

From a parse tree to a syntax tree: We have looked at a grammar for arithmetic expressions, and saw how to construct the parse trees for specific expressions. A syntax tree for an expression can be constructed from the parse tree, and is an alternative description of the expression.

Download Presentation

From a parse tree to a syntax tree:

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. From a parse tree to a syntax tree: We have looked at a grammar for arithmetic expressions, and saw how to construct the parse trees for specific expressions. A syntax tree for an expression can be constructed from the parse tree, and is an alternative description of the expression. The nodes in the parse tree containing non-terminal symbols, and the nodes containing parentheses are “squeezed out” of the tree. In a syntax tree the operands appear in the leaf nodes, and the operators appear in the non-leaf nodes.

  2. Example: (a + b) * c <E> <T> <T> * <F> ( <E> ) c <E> + <T> a b

  3. The syntax tree for (a + b) * c * + c a b A pre-order traversal yields: * + a b c A post-order traversal yields: a b + c *

  4. Example: a + b * c <E> <E> + <T> <T> <T> * <F> <F> <F> c a b

  5. The syntax tree for a + b * c + * a b c A pre-order traversal yields: + a * b c A post-order traversal yields: a b c * +

  6. Assume the data values on the nodes of a tree can be ordered. A binary search tree T is a binary tree that is either empty, or 1. Each data item in the left subtree of T is less than or equal to the data item on the root of T 2. Each data item in the right subtree of T is greater than or equal to the data item on the root of T. 3. The left subtree and right subtree of T are also binary search trees. An in-order traversal of a binary search tree displays the data values on the nodes in increasing order

  7. M R D T C J S V U W Z An in-order traversal: C D J M S T U V W Z

More Related