Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 2 | Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, |
| 3 | Amsterdam, The Netherlands. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 25 | /* List a node on a file */ |
| 26 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 27 | #include "pgenheaders.h" |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 28 | #include "token.h" |
| 29 | #include "node.h" |
| 30 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 31 | /* Forward */ |
| 32 | static void list1node PROTO((FILE *, node *)); |
| 33 | |
| 34 | void |
| 35 | listtree(n) |
| 36 | node *n; |
| 37 | { |
| 38 | listnode(stdout, n); |
| 39 | } |
| 40 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 41 | static int level, atbol; |
| 42 | |
Guido van Rossum | 9e90a67 | 1993-06-24 11:10:19 +0000 | [diff] [blame^] | 43 | static void |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 44 | listnode(fp, n) |
| 45 | FILE *fp; |
| 46 | node *n; |
| 47 | { |
| 48 | level = 0; |
| 49 | atbol = 1; |
| 50 | list1node(fp, n); |
| 51 | } |
| 52 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 53 | static void |
| 54 | list1node(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 | } |