@@ -39,17 +39,17 @@ PERFORMANCE OF THIS SOFTWARE.
3939#include "token.h"
4040#include "grammar.h"
4141
42- extern int debugging ;
42+ extern int Py_DebugFlag ;
4343
4444grammar *
4545newgrammar (start )
4646 int start ;
4747{
4848 grammar * g ;
4949
50- g = NEW (grammar , 1 );
50+ g = PyMem_NEW (grammar , 1 );
5151 if (g == NULL )
52- fatal ("no mem for new grammar" );
52+ Py_FatalError ("no mem for new grammar" );
5353 g -> g_ndfas = 0 ;
5454 g -> g_dfa = NULL ;
5555 g -> g_start = start ;
@@ -67,9 +67,9 @@ adddfa(g, type, name)
6767{
6868 dfa * d ;
6969
70- RESIZE (g -> g_dfa , dfa , g -> g_ndfas + 1 );
70+ PyMem_RESIZE (g -> g_dfa , dfa , g -> g_ndfas + 1 );
7171 if (g -> g_dfa == NULL )
72- fatal ("no mem to resize dfa in adddfa" );
72+ Py_FatalError ("no mem to resize dfa in adddfa" );
7373 d = & g -> g_dfa [g -> g_ndfas ++ ];
7474 d -> d_type = type ;
7575 d -> d_name = name ;
@@ -86,9 +86,9 @@ addstate(d)
8686{
8787 state * s ;
8888
89- RESIZE (d -> d_state , state , d -> d_nstates + 1 );
89+ PyMem_RESIZE (d -> d_state , state , d -> d_nstates + 1 );
9090 if (d -> d_state == NULL )
91- fatal ("no mem to resize state in addstate" );
91+ Py_FatalError ("no mem to resize state in addstate" );
9292 s = & d -> d_state [d -> d_nstates ++ ];
9393 s -> s_narcs = 0 ;
9494 s -> s_arc = NULL ;
@@ -111,9 +111,9 @@ addarc(d, from, to, lbl)
111111 assert (0 <= to && to < d -> d_nstates );
112112
113113 s = & d -> d_state [from ];
114- RESIZE (s -> s_arc , arc , s -> s_narcs + 1 );
114+ PyMem_RESIZE (s -> s_arc , arc , s -> s_narcs + 1 );
115115 if (s -> s_arc == NULL )
116- fatal ("no mem to resize arc list in addarc" );
116+ Py_FatalError ("no mem to resize arc list in addarc" );
117117 a = & s -> s_arc [s -> s_narcs ++ ];
118118 a -> a_lbl = lbl ;
119119 a -> a_arrow = to ;
@@ -133,9 +133,9 @@ addlabel(ll, type, str)
133133 strcmp (ll -> ll_label [i ].lb_str , str ) == 0 )
134134 return i ;
135135 }
136- RESIZE (ll -> ll_label , label , ll -> ll_nlabels + 1 );
136+ PyMem_RESIZE (ll -> ll_label , label , ll -> ll_nlabels + 1 );
137137 if (ll -> ll_label == NULL )
138- fatal ("no mem to resize labellist in addlabel" );
138+ Py_FatalError ("no mem to resize labellist in addlabel" );
139139 lb = & ll -> ll_label [ll -> ll_nlabels ++ ];
140140 lb -> lb_type = type ;
141141 lb -> lb_str = str ; /* XXX strdup(str) ??? */
@@ -158,12 +158,12 @@ findlabel(ll, type, str)
158158 return i ;
159159 }
160160 fprintf (stderr , "Label %d/'%s' not found\n" , type , str );
161- fatal ("grammar.c:findlabel()" );
161+ Py_FatalError ("grammar.c:findlabel()" );
162162 return 0 ; /* Make gcc -Wall happy */
163163}
164164
165165/* Forward */
166- static void translabel PROTO ((grammar * , label * ) );
166+ static void translabel Py_PROTO ((grammar * , label * ) );
167167
168168void
169169translatelabels (g )
@@ -186,24 +186,25 @@ translabel(g, lb)
186186{
187187 int i ;
188188
189- if (debugging )
190- printf ("Translating label %s ...\n" , labelrepr (lb ));
189+ if (Py_DebugFlag )
190+ printf ("Translating label %s ...\n" , PyGrammar_LabelRepr (lb ));
191191
192192 if (lb -> lb_type == NAME ) {
193193 for (i = 0 ; i < g -> g_ndfas ; i ++ ) {
194194 if (strcmp (lb -> lb_str , g -> g_dfa [i ].d_name ) == 0 ) {
195- if (debugging )
196- printf ("Label %s is non-terminal %d.\n" ,
197- lb -> lb_str ,
198- g -> g_dfa [i ].d_type );
195+ if (Py_DebugFlag )
196+ printf (
197+ "Label %s is non-terminal %d.\n" ,
198+ lb -> lb_str ,
199+ g -> g_dfa [i ].d_type );
199200 lb -> lb_type = g -> g_dfa [i ].d_type ;
200201 lb -> lb_str = NULL ;
201202 return ;
202203 }
203204 }
204205 for (i = 0 ; i < (int )N_TOKENS ; i ++ ) {
205- if (strcmp (lb -> lb_str , tok_name [i ]) == 0 ) {
206- if (debugging )
206+ if (strcmp (lb -> lb_str , _PyParser_TokenNames [i ]) == 0 ) {
207+ if (Py_DebugFlag )
207208 printf ("Label %s is terminal %d.\n" ,
208209 lb -> lb_str , i );
209210 lb -> lb_type = i ;
@@ -218,7 +219,7 @@ translabel(g, lb)
218219 if (lb -> lb_type == STRING ) {
219220 if (isalpha (lb -> lb_str [1 ]) || lb -> lb_str [1 ] == '_' ) {
220221 char * p ;
221- if (debugging )
222+ if (Py_DebugFlag )
222223 printf ("Label %s is a keyword\n" , lb -> lb_str );
223224 lb -> lb_type = NAME ;
224225 lb -> lb_str ++ ;
@@ -227,7 +228,7 @@ translabel(g, lb)
227228 * p = '\0' ;
228229 }
229230 else if (lb -> lb_str [2 ] == lb -> lb_str [0 ]) {
230- int type = (int ) tok_1char (lb -> lb_str [1 ]);
231+ int type = (int ) PyToken_OneChar (lb -> lb_str [1 ]);
231232 if (type != OP ) {
232233 lb -> lb_type = type ;
233234 lb -> lb_str = NULL ;
@@ -237,7 +238,7 @@ translabel(g, lb)
237238 lb -> lb_str );
238239 }
239240 else if (lb -> lb_str [2 ] && lb -> lb_str [3 ] == lb -> lb_str [0 ]) {
240- int type = (int ) tok_2char (lb -> lb_str [1 ],
241+ int type = (int ) PyToken_TwoChars (lb -> lb_str [1 ],
241242 lb -> lb_str [2 ]);
242243 if (type != OP ) {
243244 lb -> lb_type = type ;
@@ -252,5 +253,6 @@ translabel(g, lb)
252253 lb -> lb_str );
253254 }
254255 else
255- printf ("Can't translate label '%s'\n" , labelrepr (lb ));
256+ printf ("Can't translate label '%s'\n" ,
257+ PyGrammar_LabelRepr (lb ));
256258}
0 commit comments