Mercurial > cpython-lru_cache-weakref
annotate Parser/grammar1.c @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | 473f29411f3b |
| children | fd25030223b0 |
| rev | line source |
|---|---|
|
21088
347ea693002d
Reverting last change so we don't have to think about the assert macro
Barry Warsaw <barry@python.org>
parents:
21085
diff
changeset
|
1 |
| 6 | 2 /* Grammar subroutines needed by parser */ |
| 3 | |
|
21181
944d6e02f359
The parser doesn't need its own implementation of assert, and having its
Tim Peters <tim.peters@gmail.com>
parents:
21088
diff
changeset
|
4 #include "Python.h" |
| 86 | 5 #include "pgenheaders.h" |
| 6 | 6 #include "grammar.h" |
| 7 #include "token.h" | |
| 8 | |
| 9 /* Return the DFA for the given type */ | |
| 10 | |
| 11 dfa * | |
| 13659 | 12 PyGrammar_FindDFA(grammar *g, register int type) |
| 6 | 13 { |
|
1873
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
14 register dfa *d; |
|
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
15 #if 1 |
|
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
16 /* Massive speed-up */ |
|
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
17 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
|
18 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
|
19 return d; |
|
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
20 #else |
|
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
21 /* Old, slow version */ |
| 6 | 22 register int i; |
| 23 | |
| 24 for (i = g->g_ndfas, d = g->g_dfa; --i >= 0; d++) { | |
| 25 if (d->d_type == type) | |
| 26 return d; | |
| 27 } | |
| 28 assert(0); | |
| 29 /* NOTREACHED */ | |
|
1873
9081bb7acd52
* Parser/grammar1.c (finddfa): massive speed up by using direct
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
30 #endif |
| 6 | 31 } |
| 32 | |
| 33 char * | |
| 13659 | 34 PyGrammar_LabelRepr(label *lb) |
| 6 | 35 { |
| 36 static char buf[100]; | |
| 37 | |
| 38 if (lb->lb_type == ENDMARKER) | |
| 39 return "EMPTY"; | |
| 40 else if (ISNONTERMINAL(lb->lb_type)) { | |
| 41 if (lb->lb_str == NULL) { | |
|
21182
473f29411f3b
PyGrammar_LabelRepr(): sprintf -> PyOS_snprintf.
Tim Peters <tim.peters@gmail.com>
parents:
21181
diff
changeset
|
42 PyOS_snprintf(buf, sizeof(buf), "NT%d", lb->lb_type); |
| 6 | 43 return buf; |
| 44 } | |
| 45 else | |
| 46 return lb->lb_str; | |
| 47 } | |
| 48 else { | |
| 49 if (lb->lb_str == NULL) | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
50 return _PyParser_TokenNames[lb->lb_type]; |
| 6 | 51 else { |
|
21182
473f29411f3b
PyGrammar_LabelRepr(): sprintf -> PyOS_snprintf.
Tim Peters <tim.peters@gmail.com>
parents:
21181
diff
changeset
|
52 PyOS_snprintf(buf, sizeof(buf), "%.32s(%.32s)", |
|
21088
347ea693002d
Reverting last change so we don't have to think about the assert macro
Barry Warsaw <barry@python.org>
parents:
21085
diff
changeset
|
53 _PyParser_TokenNames[lb->lb_type], lb->lb_str); |
| 6 | 54 return buf; |
| 55 } | |
| 56 } | |
| 57 } |
