blob: a914bab23620005c5b1a1453bab79586341890d8 [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
Guido van Rossum9bfef441993-03-29 10:43:31 +00002Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
3Amsterdam, The 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 *));
33
34void
35listtree(n)
36 node *n;
37{
38 listnode(stdout, n);
39}
40
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000041static int level, atbol;
42
Guido van Rossum9e90a671993-06-24 11:10:19 +000043static void
Guido van Rossum3f5da241990-12-20 15:06:42 +000044listnode(fp, n)
45 FILE *fp;
46 node *n;
47{
48 level = 0;
49 atbol = 1;
50 list1node(fp, n);
51}
52
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000053static void
54list1node(fp, n)
55 FILE *fp;
56 node *n;
57{
58 if (n == 0)
59 return;
60 if (ISNONTERMINAL(TYPE(n))) {
61 int i;
62 for (i = 0; i < NCH(n); i++)
63 list1node(fp, CHILD(n, i));
64 }
65 else if (ISTERMINAL(TYPE(n))) {
66 switch (TYPE(n)) {
67 case INDENT:
68 ++level;
69 break;
70 case DEDENT:
71 --level;
72 break;
73 default:
74 if (atbol) {
75 int i;
76 for (i = 0; i < level; ++i)
77 fprintf(fp, "\t");
78 atbol = 0;
79 }
80 if (TYPE(n) == NEWLINE) {
81 if (STR(n) != NULL)
82 fprintf(fp, "%s", STR(n));
83 fprintf(fp, "\n");
84 atbol = 1;
85 }
86 else
87 fprintf(fp, "%s ", STR(n));
88 break;
89 }
90 }
91 else
92 fprintf(fp, "? ");
93}