You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.3 KiB

36 years ago
36 years ago
36 years ago
36 years ago
36 years ago
36 years ago
  1. /* List a node on a file */
  2. #include "pgenheaders.h"
  3. #include "token.h"
  4. #include "node.h"
  5. /* Forward */
  6. static void list1node(FILE *, node *);
  7. static void listnode(FILE *, node *);
  8. void
  9. PyNode_ListTree(node *n)
  10. {
  11. listnode(stdout, n);
  12. }
  13. static int level, atbol;
  14. static void
  15. listnode(FILE *fp, node *n)
  16. {
  17. level = 0;
  18. atbol = 1;
  19. list1node(fp, n);
  20. }
  21. static void
  22. list1node(FILE *fp, node *n)
  23. {
  24. if (n == 0)
  25. return;
  26. if (ISNONTERMINAL(TYPE(n))) {
  27. int i;
  28. for (i = 0; i < NCH(n); i++)
  29. list1node(fp, CHILD(n, i));
  30. }
  31. else if (ISTERMINAL(TYPE(n))) {
  32. switch (TYPE(n)) {
  33. case INDENT:
  34. ++level;
  35. break;
  36. case DEDENT:
  37. --level;
  38. break;
  39. default:
  40. if (atbol) {
  41. int i;
  42. for (i = 0; i < level; ++i)
  43. fprintf(fp, "\t");
  44. atbol = 0;
  45. }
  46. if (TYPE(n) == NEWLINE) {
  47. if (STR(n) != NULL)
  48. fprintf(fp, "%s", STR(n));
  49. fprintf(fp, "\n");
  50. atbol = 1;
  51. }
  52. else
  53. fprintf(fp, "%s ", STR(n));
  54. break;
  55. }
  56. }
  57. else
  58. fprintf(fp, "? ");
  59. }