Refined section on logging to one file from multiple processes.
[python.git] / Parser / grammar1.c
blobb76719a1d5ba2992f5843f919466ce597bcd2fda
2 /* Grammar subroutines needed by parser */
4 #include "Python.h"
5 #include "pgenheaders.h"
6 #include "grammar.h"
7 #include "token.h"
9 /* Return the DFA for the given type */
11 dfa *
12 PyGrammar_FindDFA(grammar *g, register int type)
14 register dfa *d;
15 #if 1
16 /* Massive speed-up */
17 d = &g->g_dfa[type - NT_OFFSET];
18 assert(d->d_type == type);
19 return d;
20 #else
21 /* Old, slow version */
22 register int i;
24 for (i = g->g_ndfas, d = g->g_dfa; --i >= 0; d++) {
25 if (d->d_type == type)
26 return d;
28 assert(0);
29 /* NOTREACHED */
30 #endif
33 char *
34 PyGrammar_LabelRepr(label *lb)
36 static char buf[100];
38 if (lb->lb_type == ENDMARKER)
39 return "EMPTY";
40 else if (ISNONTERMINAL(lb->lb_type)) {
41 if (lb->lb_str == NULL) {
42 PyOS_snprintf(buf, sizeof(buf), "NT%d", lb->lb_type);
43 return buf;
45 else
46 return lb->lb_str;
48 else {
49 if (lb->lb_str == NULL)
50 return _PyParser_TokenNames[lb->lb_type];
51 else {
52 PyOS_snprintf(buf, sizeof(buf), "%.32s(%.32s)",
53 _PyParser_TokenNames[lb->lb_type], lb->lb_str);
54 return buf;