8.1 Building a Parse Tree

Suppose we want to obtain the parse tree for a program in the language generated by the above grammar. In anticipation of further processing phases, we would like to have an internal form most suitable for reduction to an Intermediate representation. However, here for illustration purpose, first we represent the parse tree in a form suitable for actually drawing the tree, which is done with the help of a TEXpackage known as pst-tree.

In the pst-tree package, a tree is written as \pstree{root}{node1 node2 … noden}, where each node can be written in one of several different ways, but we use \TR{node-label} to write a node. For example, \pstree{\TR{A}}{ \TR{B} \TR{C}} gives the tree.

 

 

How do we generate the parse ...

Get Compilers: Principles and Practice now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.