aboutsummaryrefslogtreecommitdiffstats
path: root/utils/Burg/nonterminal.c
blob: 71fd7d49442c4aff97fecde2bdff35500ec08810 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
char rcsid_nonterminal[] = "$Id$";

#include "b.h"
#include <stdio.h>
#include <string.h>

NonTerminal	start;
NonTerminalNum	max_nonterminal = 1;
NonTerminalNum	last_user_nonterminal;
List		nonterminals;

NonTerminal
newNonTerminal(name) char *name;
{
	NonTerminal nt;

	nt = (NonTerminal) zalloc(sizeof(struct nonterminal));
	assert(nt);
	if (max_nonterminal == 1) {
		start = nt;
	}
	nt->name = name;
	nt->num = max_nonterminal++;
	nonterminals = newList(nt, nonterminals);

	return nt;
}

int
nonTerminalName(buf, i) char *buf; int i;
{
	List l;

	for (l = nonterminals; l; l = l->next) {
		NonTerminal nt = (NonTerminal) l->x;
		if (nt->num == i) {
			strcpy(buf, nt->name);
			return 1;
		}
	}
	strcpy(buf, "(Unknown NonTerminal)");
	return 0;
}

void
dumpNonTerminal(n) NonTerminal n;
{
	printf("%s(%d)", n->name, n->num);
}