Mercurial > cpython-lru_cache-weakref
annotate Parser/grammar1.c @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 1c9a84e0981d |
| children | 916fb024ce94 |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
2060
146890653a57
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1873
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
146890653a57
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1873
diff
changeset
|
3 The Netherlands. |
| 145 | 4 |
| 5 All Rights Reserved | |
| 6 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
| 145 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
| 145 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
15 permission. |
| 145 | 16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 145 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
| 6 | 32 /* Grammar subroutines needed by parser */ |
| 33 | |
| 86 | 34 #include "pgenheaders.h" |
| 6 | 35 #include "assert.h" |
| 36 #include "grammar.h" | |
| 37 #include "token.h" | |
| 38 | |
| 39 /* Return the DFA for the given type */ | |
| 40 | |
| 41 dfa * | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
42 PyGrammar_FindDFA(g, type) |
| 6 | 43 grammar *g; |
| 44 register int type; | |
| 45 { | |
|
1873
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
46 register dfa *d; |
|
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
47 #if 1 |
|
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
48 /* Massive speed-up */ |
|
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
49 d = &g->g_dfa[type - NT_OFFSET]; |
|
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
50 assert(d->d_type == type); |
|
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
51 return d; |
|
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
52 #else |
|
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
53 /* Old, slow version */ |
| 6 | 54 register int i; |
| 55 | |
| 56 for (i = g->g_ndfas, d = g->g_dfa; --i >= 0; d++) { | |
| 57 if (d->d_type == type) | |
| 58 return d; | |
| 59 } | |
| 60 assert(0); | |
| 61 /* NOTREACHED */ | |
|
1873
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
62 #endif |
| 6 | 63 } |
| 64 | |
| 65 char * | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
66 PyGrammar_LabelRepr(lb) |
| 6 | 67 label *lb; |
| 68 { | |
| 69 static char buf[100]; | |
| 70 | |
| 71 if (lb->lb_type == ENDMARKER) | |
| 72 return "EMPTY"; | |
| 73 else if (ISNONTERMINAL(lb->lb_type)) { | |
| 74 if (lb->lb_str == NULL) { | |
| 75 sprintf(buf, "NT%d", lb->lb_type); | |
| 76 return buf; | |
| 77 } | |
| 78 else | |
| 79 return lb->lb_str; | |
| 80 } | |
| 81 else { | |
| 82 if (lb->lb_str == NULL) | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
83 return _PyParser_TokenNames[lb->lb_type]; |
| 6 | 84 else { |
| 85 sprintf(buf, "%.32s(%.32s)", | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
86 _PyParser_TokenNames[lb->lb_type], lb->lb_str); |
| 6 | 87 return buf; |
| 88 } | |
| 89 } | |
| 90 } |
