blob: 719b1bb9c98c439eacdef5ba3f8b02b49ceb8cd7 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
Guido van Rossumb9f8d6e1995-01-04 19:08:09 +00002Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
Guido van Rossumf70e43a1991-02-19 12:39:46 +00004
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000025/* List a node on a file */
26
Guido van Rossum3f5da241990-12-20 15:06:42 +000027#include "pgenheaders.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000028#include "token.h"
29#include "node.h"
30
Guido van Rossum3f5da241990-12-20 15:06:42 +000031/* Forward */
32static void list1node PROTO((FILE *, node *));
Guido van Rossumb73cc041993-11-01 16:28:59 +000033static void listnode PROTO((FILE *, node *));
Guido van Rossum3f5da241990-12-20 15:06:42 +000034
35void
36listtree(n)
37 node *n;
38{
39 listnode(stdout, n);
40}
41
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000042static int level, atbol;
43
Guido van Rossum9e90a671993-06-24 11:10:19 +000044static void
Guido van Rossum3f5da241990-12-20 15:06:42 +000045listnode(fp, n)
46 FILE *fp;
47 node *n;
48{
49 level = 0;
50 atbol = 1;
51 list1node(fp, n);
52}
53
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000054static void
55list1node(fp, n)
56 FILE *fp;
57 node *n;
58{
59 if (n == 0)
60 return;
61 if (ISNONTERMINAL(TYPE(n))) {
62 int i;
63 for (i = 0; i < NCH(n); i++)
64 list1node(fp, CHILD(n, i));
65 }
66 else if (ISTERMINAL(TYPE(n))) {
67 switch (TYPE(n)) {
68 case INDENT:
69 ++level;
70 break;
71 case DEDENT:
72 --level;
73 break;
74 default:
75 if (atbol) {
76 int i;
77 for (i = 0; i < level; ++i)
78 fprintf(fp, "\t");
79 atbol = 0;
80 }
81 if (TYPE(n) == NEWLINE) {
82 if (STR(n) != NULL)
83 fprintf(fp, "%s", STR(n));
84 fprintf(fp, "\n");
85 atbol = 1;
86 }
87 else
88 fprintf(fp, "%s ", STR(n));
89 break;
90 }
91 }
92 else
93 fprintf(fp, "? ");
94}