home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / NODE.H < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-01  |  1.0 KB  |  47 lines

  1.  
  2. /* Parse tree node interface */
  3.  
  4. #ifndef Py_NODE_H
  5. #define Py_NODE_H
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9.  
  10. typedef struct _node {
  11.     short        n_type;
  12.     char        *n_str;
  13.     int            n_lineno;
  14.     int            n_nchildren;
  15.     struct _node    *n_child;
  16. } node;
  17.  
  18. extern DL_IMPORT(node *) PyNode_New(int type);
  19. extern DL_IMPORT(int) PyNode_AddChild(node *n, int type,
  20.                                       char *str, int lineno);
  21. extern DL_IMPORT(void) PyNode_Free(node *n);
  22.  
  23. /* Node access functions */
  24. #define NCH(n)        ((n)->n_nchildren)
  25. #define CHILD(n, i)    (&(n)->n_child[i])
  26. #define TYPE(n)        ((n)->n_type)
  27. #define STR(n)        ((n)->n_str)
  28.  
  29. /* Assert that the type of a node is what we expect */
  30. #ifndef Py_DEBUG
  31. #define REQ(n, type) { /*pass*/ ; }
  32. #else
  33. #define REQ(n, type) \
  34.     { if (TYPE(n) != (type)) { \
  35.         fprintf(stderr, "FATAL: node type %d, required %d\n", \
  36.             TYPE(n), type); \
  37.         abort(); \
  38.     } }
  39. #endif
  40.  
  41. extern DL_IMPORT(void) PyNode_ListTree(node *);
  42.  
  43. #ifdef __cplusplus
  44. }
  45. #endif
  46. #endif /* !Py_NODE_H */
  47.