ptnode.cpp

来自「C人工智能游戏开发的一些实例源代码 C Game development in 」· C++ 代码 · 共 64 行

CPP
64
字号
#include <stdio.h>

#include "PTNode.H"


void
PTNode::Dump() const
{
  Dump_Internal( 0 );
  printf( "\n" );

}


void
PTNode::Dump_Internal( int indent ) const
{
  int c = 0;
  for ( ; c < indent; c += 2 )
    printf( " |" );

  printf( " +-- %s\n", GetName().c_str() );


  NodeList::const_iterator i = GetChildrenBegin();
  NodeList::const_iterator end = GetChildrenEnd();

  indent += 2;

  for ( ; i != end; ++i ) {
    PTNodePtr node = *i;

    // It is okay for some nodes to have NULL pointers in their list of
    // children.  This just means that the optional child is not specified.
    if ( node == NULL )
      continue;

    node->Dump_Internal( indent );
  }

  indent -= 2;
}



// When dumping the parse tree, it is useful to see what the actual constant
// number.  Make sure to add its value to the name string.
string
ConstantNode::GetName() const
{
  char name[64];
  sprintf( name, "Constant %d", m_value );

  return name;
}



string
IdentifierNode::GetName() const
{
  return "Identifier " + m_name;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?