next next up down toc toc mail

10.6.  Parse Trees

A parse tree for a grammar G is a tree where

Every terminal string generated by a grammar has a corresponding parse tree; every valid parse tree represents a string generated by the grammar.

Example: Given the following grammar, find a parse tree for the string 1 + 2 + 3:

1.   <E>:   <N>
2.   <E>:   ( <E> )
3.   <E>:   <E> + <E>
4.   <E>:   <E> - <E>
5.   <E>:   <E> * <E>
6.   <E>:   <E> / <E>
7.   <N>:   0 | 1 | 2 | ... 9
A possible parse tree is:

Parse the tree in In-order and substitute the values in the nodes ASAP. The result is 6.

A possible parse tree is also:

Parse the tree in In-order and substitute the values in the nodes ASAP. The result is 6.


back next up down toc toc mail


Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1998).

Last modified: 27/July/98 (12:14)