Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1 | /* Grammar subroutines needed by parser */ |
| 2 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame^] | 3 | #include "pgenheaders.h" |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 4 | #include "assert.h" |
| 5 | #include "grammar.h" |
| 6 | #include "token.h" |
| 7 | |
| 8 | /* Return the DFA for the given type */ |
| 9 | |
| 10 | dfa * |
| 11 | finddfa(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 | |
| 26 | char * |
| 27 | labelrepr(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 | } |