Add better error reporting for MemoryErrors caused by str->float conversions.
[python.git] / Parser / listnode.c
blobc0b3b666fe7e573a215adc07b7875c3e8bff9943
2 /* List a node on a file */
4 #include "pgenheaders.h"
5 #include "token.h"
6 #include "node.h"
8 /* Forward */
9 static void list1node(FILE *, node *);
10 static void listnode(FILE *, node *);
12 void
13 PyNode_ListTree(node *n)
15 listnode(stdout, n);
18 static int level, atbol;
20 static void
21 listnode(FILE *fp, node *n)
23 level = 0;
24 atbol = 1;
25 list1node(fp, n);
28 static void
29 list1node(FILE *fp, node *n)
31 if (n == 0)
32 return;
33 if (ISNONTERMINAL(TYPE(n))) {
34 int i;
35 for (i = 0; i < NCH(n); i++)
36 list1node(fp, CHILD(n, i));
38 else if (ISTERMINAL(TYPE(n))) {
39 switch (TYPE(n)) {
40 case INDENT:
41 ++level;
42 break;
43 case DEDENT:
44 --level;
45 break;
46 default:
47 if (atbol) {
48 int i;
49 for (i = 0; i < level; ++i)
50 fprintf(fp, "\t");
51 atbol = 0;
53 if (TYPE(n) == NEWLINE) {
54 if (STR(n) != NULL)
55 fprintf(fp, "%s", STR(n));
56 fprintf(fp, "\n");
57 atbol = 1;
59 else
60 fprintf(fp, "%s ", STR(n));
61 break;
64 else
65 fprintf(fp, "? ");