blob: 6c101582ba063f664f70737148b951fd318d0a8e [file] [log] [blame]
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00001/* Grammar subroutines needed by parser */
2
Guido van Rossum3f5da241990-12-20 15:06:42 +00003#include "pgenheaders.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +00004#include "assert.h"
5#include "grammar.h"
6#include "token.h"
7
8/* Return the DFA for the given type */
9
10dfa *
11finddfa(g, type)
12 grammar *g;
13 register int type;
14{
15 register int i;
16 register dfa *d;
17
18 for (i = g->g_ndfas, d = g->g_dfa; --i >= 0; d++) {
19 if (d->d_type == type)
20 return d;
21 }
22 assert(0);
23 /* NOTREACHED */
24}
25
26char *
27labelrepr(lb)
28 label *lb;
29{
30 static char buf[100];
31
32 if (lb->lb_type == ENDMARKER)
33 return "EMPTY";
34 else if (ISNONTERMINAL(lb->lb_type)) {
35 if (lb->lb_str == NULL) {
36 sprintf(buf, "NT%d", lb->lb_type);
37 return buf;
38 }
39 else
40 return lb->lb_str;
41 }
42 else {
43 if (lb->lb_str == NULL)
44 return tok_name[lb->lb_type];
45 else {
46 sprintf(buf, "%.32s(%.32s)",
47 tok_name[lb->lb_type], lb->lb_str);
48 return buf;
49 }
50 }
51}