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