Mercurial > cpython-lru_cache-weakref
annotate Parser/grammar.c @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | fd25030223b0 |
| children |
| rev | line source |
|---|---|
| 145 | 1 |
| 6 | 2 /* Grammar implementation */ |
| 3 | |
|
21181
944d6e02f359
The parser doesn't need its own implementation of assert, and having its
Tim Peters <tim.peters@gmail.com>
parents:
14375
diff
changeset
|
4 #include "Python.h" |
| 86 | 5 #include "pgenheaders.h" |
| 6 | |
| 6 | 7 #include <ctype.h> |
| 8 | |
| 9 #include "token.h" | |
| 10 #include "grammar.h" | |
| 11 | |
|
29066
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
28646
diff
changeset
|
12 #ifdef RISCOS |
|
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
28646
diff
changeset
|
13 #include <unixlib.h> |
|
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
28646
diff
changeset
|
14 #endif |
|
90342f395721
Patch #734231: Update RiscOS support. In particular, correct
Martin v. Löwis <martin@v.loewis.de>
parents:
28646
diff
changeset
|
15 |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5231
diff
changeset
|
16 extern int Py_DebugFlag; |
| 6 | 17 |
| 18 grammar * | |
| 13659 | 19 newgrammar(int start) |
| 6 | 20 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
21 grammar *g; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
22 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
23 g = (grammar *)PyObject_MALLOC(sizeof(grammar)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
24 if (g == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
25 Py_FatalError("no mem for new grammar"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
26 g->g_ndfas = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
27 g->g_dfa = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
28 g->g_start = start; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
29 g->g_ll.ll_nlabels = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
30 g->g_ll.ll_label = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
31 g->g_accel = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
32 return g; |
| 6 | 33 } |
| 34 | |
| 35 dfa * | |
| 13659 | 36 adddfa(grammar *g, int type, char *name) |
| 6 | 37 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
38 dfa *d; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
39 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
40 g->g_dfa = (dfa *)PyObject_REALLOC(g->g_dfa, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
41 sizeof(dfa) * (g->g_ndfas + 1)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
42 if (g->g_dfa == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
43 Py_FatalError("no mem to resize dfa in adddfa"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
44 d = &g->g_dfa[g->g_ndfas++]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
45 d->d_type = type; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
46 d->d_name = strdup(name); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
47 d->d_nstates = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
48 d->d_state = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
49 d->d_initial = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
50 d->d_first = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
51 return d; /* Only use while fresh! */ |
| 6 | 52 } |
| 53 | |
| 54 int | |
| 13659 | 55 addstate(dfa *d) |
| 6 | 56 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
57 state *s; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
58 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
59 d->d_state = (state *)PyObject_REALLOC(d->d_state, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
60 sizeof(state) * (d->d_nstates + 1)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
61 if (d->d_state == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
62 Py_FatalError("no mem to resize state in addstate"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
63 s = &d->d_state[d->d_nstates++]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
64 s->s_narcs = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
65 s->s_arc = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
66 s->s_lower = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
67 s->s_upper = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
68 s->s_accel = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
69 s->s_accept = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
70 return s - d->d_state; |
| 6 | 71 } |
| 72 | |
| 73 void | |
| 13659 | 74 addarc(dfa *d, int from, int to, int lbl) |
| 6 | 75 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
76 state *s; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
77 arc *a; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
78 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
79 assert(0 <= from && from < d->d_nstates); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
80 assert(0 <= to && to < d->d_nstates); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
81 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
82 s = &d->d_state[from]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
83 s->s_arc = (arc *)PyObject_REALLOC(s->s_arc, sizeof(arc) * (s->s_narcs + 1)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
84 if (s->s_arc == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
85 Py_FatalError("no mem to resize arc list in addarc"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
86 a = &s->s_arc[s->s_narcs++]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
87 a->a_lbl = lbl; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
88 a->a_arrow = to; |
| 6 | 89 } |
| 90 | |
| 91 int | |
| 13659 | 92 addlabel(labellist *ll, int type, char *str) |
| 6 | 93 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
94 int i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
95 label *lb; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
96 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
97 for (i = 0; i < ll->ll_nlabels; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
98 if (ll->ll_label[i].lb_type == type && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
99 strcmp(ll->ll_label[i].lb_str, str) == 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
100 return i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
101 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
102 ll->ll_label = (label *)PyObject_REALLOC(ll->ll_label, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
103 sizeof(label) * (ll->ll_nlabels + 1)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
104 if (ll->ll_label == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
105 Py_FatalError("no mem to resize labellist in addlabel"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
106 lb = &ll->ll_label[ll->ll_nlabels++]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
107 lb->lb_type = type; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
108 lb->lb_str = strdup(str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
109 if (Py_DebugFlag) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
110 printf("Label @ %8p, %d: %s\n", ll, ll->ll_nlabels, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
111 PyGrammar_LabelRepr(lb)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
112 return lb - ll->ll_label; |
| 6 | 113 } |
| 114 | |
| 115 /* Same, but rather dies than adds */ | |
| 116 | |
| 117 int | |
| 13659 | 118 findlabel(labellist *ll, int type, char *str) |
| 6 | 119 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
120 int i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
121 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
122 for (i = 0; i < ll->ll_nlabels; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
123 if (ll->ll_label[i].lb_type == type /*&& |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
124 strcmp(ll->ll_label[i].lb_str, str) == 0*/) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
125 return i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
126 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
127 fprintf(stderr, "Label %d/'%s' not found\n", type, str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
128 Py_FatalError("grammar.c:findlabel()"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
129 return 0; /* Make gcc -Wall happy */ |
| 6 | 130 } |
| 131 | |
| 86 | 132 /* Forward */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
133 static void translabel(grammar *, label *); |
| 86 | 134 |
| 135 void | |
| 13659 | 136 translatelabels(grammar *g) |
| 86 | 137 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
138 int i; |
|
2044
281e40652e23
Parser/tokenizer.c (tok_nextc): zap tok->buf after freeing;
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
139 |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4577
diff
changeset
|
140 #ifdef Py_DEBUG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
141 printf("Translating labels ...\n"); |
|
2044
281e40652e23
Parser/tokenizer.c (tok_nextc): zap tok->buf after freeing;
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
142 #endif |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
143 /* Don't translate EMPTY */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
144 for (i = EMPTY+1; i < g->g_ll.ll_nlabels; i++) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
145 translabel(g, &g->g_ll.ll_label[i]); |
| 86 | 146 } |
| 147 | |
| 6 | 148 static void |
| 13659 | 149 translabel(grammar *g, label *lb) |
| 6 | 150 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
151 int i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
152 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
153 if (Py_DebugFlag) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
154 printf("Translating label %s ...\n", PyGrammar_LabelRepr(lb)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
155 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
156 if (lb->lb_type == NAME) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
157 for (i = 0; i < g->g_ndfas; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
158 if (strcmp(lb->lb_str, g->g_dfa[i].d_name) == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
159 if (Py_DebugFlag) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
160 printf( |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
161 "Label %s is non-terminal %d.\n", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
162 lb->lb_str, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
163 g->g_dfa[i].d_type); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
164 lb->lb_type = g->g_dfa[i].d_type; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
165 free(lb->lb_str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
166 lb->lb_str = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
167 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
168 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
169 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
170 for (i = 0; i < (int)N_TOKENS; i++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
171 if (strcmp(lb->lb_str, _PyParser_TokenNames[i]) == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
172 if (Py_DebugFlag) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
173 printf("Label %s is terminal %d.\n", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
174 lb->lb_str, i); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
175 lb->lb_type = i; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
176 free(lb->lb_str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
177 lb->lb_str = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
178 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
179 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
180 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
181 printf("Can't translate NAME label '%s'\n", lb->lb_str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
182 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
183 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
184 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
185 if (lb->lb_type == STRING) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
186 if (isalpha(Py_CHARMASK(lb->lb_str[1])) || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
187 lb->lb_str[1] == '_') { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
188 char *p; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
189 char *src; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
190 char *dest; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
191 size_t name_len; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
192 if (Py_DebugFlag) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
193 printf("Label %s is a keyword\n", lb->lb_str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
194 lb->lb_type = NAME; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
195 src = lb->lb_str + 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
196 p = strchr(src, '\''); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
197 if (p) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
198 name_len = p - src; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
199 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
200 name_len = strlen(src); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
201 dest = (char *)malloc(name_len + 1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
202 if (!dest) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
203 printf("Can't alloc dest '%s'\n", src); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
204 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
205 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
206 strncpy(dest, src, name_len); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
207 dest[name_len] = '\0'; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
208 free(lb->lb_str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
209 lb->lb_str = dest; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
210 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
211 else if (lb->lb_str[2] == lb->lb_str[0]) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
212 int type = (int) PyToken_OneChar(lb->lb_str[1]); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
213 if (type != OP) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
214 lb->lb_type = type; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
215 free(lb->lb_str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
216 lb->lb_str = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
217 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
218 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
219 printf("Unknown OP label %s\n", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
220 lb->lb_str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
221 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
222 else if (lb->lb_str[2] && lb->lb_str[3] == lb->lb_str[0]) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
223 int type = (int) PyToken_TwoChars(lb->lb_str[1], |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
224 lb->lb_str[2]); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
225 if (type != OP) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
226 lb->lb_type = type; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
227 free(lb->lb_str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
228 lb->lb_str = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
229 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
230 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
231 printf("Unknown OP label %s\n", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
232 lb->lb_str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
233 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
234 else if (lb->lb_str[2] && lb->lb_str[3] && lb->lb_str[4] == lb->lb_str[0]) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
235 int type = (int) PyToken_ThreeChars(lb->lb_str[1], |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
236 lb->lb_str[2], |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
237 lb->lb_str[3]); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
238 if (type != OP) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
239 lb->lb_type = type; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
240 free(lb->lb_str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
241 lb->lb_str = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
242 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
243 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
244 printf("Unknown OP label %s\n", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
245 lb->lb_str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
246 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
247 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
248 printf("Can't translate STRING label %s\n", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
249 lb->lb_str); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
250 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
251 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
252 printf("Can't translate label '%s'\n", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
39476
diff
changeset
|
253 PyGrammar_LabelRepr(lb)); |
| 6 | 254 } |
