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