#ifndef _PRINT_TREE_HPP_
#define _PRINT_TREE_HPP_

/*
   print_tree

   Print an ANTLR abstract syntax tree in operator prefix form.

 */

typedef enum { FALSE = 0, TRUE = 1 } Boolean;


#define For_each_kid(t,top)     for(t=( (top && is_nonleaf(top)) ? top->getFirstChild() : (RefAST)NULL ); t; t = t->getNextSibling() )


class print_tree {
private:
  typedef enum { INDENT = 2 } bogus;
  int indent_level;

private:
  void pr_name( RefAST node );
  void pr_indent();
  void pr_top( RefAST top );
  void pr_open_angle(void);
  void pr_close_angle(Boolean first);
  void pr_leaves( RefAST top );

  Boolean is_nonleaf( RefAST node )
  {
    Boolean rslt;

    rslt = (Boolean)(node->getFirstChild() != NULL);
    return rslt;
  }
public:
  void pr_tree( const RefAST top );
}; // print_tree

#endif

back to ANTLR examples page