home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 10 Scripting / 01 Berger / PTNode.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-09  |  809 b   |  50 lines

  1. #include <stdio.h>
  2.  
  3. #include "PTNode.H"
  4.  
  5.  
  6. void
  7. PTNode::Dump() const
  8. {
  9.   Dump_Internal( 0 );
  10.   printf( "\n" );
  11.  
  12. }
  13.  
  14.  
  15. void
  16. PTNode::Dump_Internal( int indent ) const
  17. {
  18.   int c = 0;
  19.   for ( ; c < indent; c += 2 )
  20.     printf( " |" );
  21.  
  22.   printf( " +-- %s\n", GetName().c_str() );
  23.  
  24.   NodeList::const_iterator i = GetChildrenBegin();
  25.   NodeList::const_iterator end = GetChildrenEnd();
  26.  
  27.   indent += 2;
  28.  
  29.   for ( ; i != end; ++i ) {
  30.     PTNodePtr node = *i;
  31.  
  32.     node->Dump_Internal( indent );
  33.   }
  34.  
  35.   indent -= 2;
  36. }
  37.  
  38.  
  39.  
  40. // When dumping the parse tree, it is useful to see what the actual constant
  41. // number.  Make sure to add its value to the name string.
  42. string
  43. ConstantNode::GetName() const
  44. {
  45.   char name[64];
  46.   sprintf( name, "Constant %d", m_value );
  47.  
  48.   return name;
  49. }
  50.