Mercurial > cpython-lru_cache-weakref
annotate Parser/listnode.c @ 892:11ea669c231e legacy-trunk
Documented new contents of lib5.tex
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 03 Jun 1992 17:56:44 +0000 |
| parents | 0cd197947d81 |
| children | 1cabc2b6c970 |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
795
0cd197947d81
Copyright for 1992 added
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
2 Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The |
| 145 | 3 Netherlands. |
| 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 | |
| 6 | 25 /* List a node on a file */ |
| 26 | |
| 86 | 27 #include "pgenheaders.h" |
| 6 | 28 #include "token.h" |
| 29 #include "node.h" | |
| 30 | |
| 86 | 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 | |
| 6 | 41 static int level, atbol; |
| 42 | |
| 86 | 43 void |
| 44 listnode(fp, n) | |
| 45 FILE *fp; | |
| 46 node *n; | |
| 47 { | |
| 48 level = 0; | |
| 49 atbol = 1; | |
| 50 list1node(fp, n); | |
| 51 } | |
| 52 | |
| 6 | 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 } |
