Remove building with NOCRYPTO option
[minix.git] / external / bsd / byacc / dist / graph.c
blobe2cd90f44c1d8a693398ae57fb7d941b8f97bf04
1 /* $NetBSD: graph.c,v 1.5 2015/01/03 23:22:52 christos Exp $ */
3 #include "defs.h"
4 /* Id: graph.c,v 1.8 2014/02/19 00:46:57 Tom.Shields Exp */
6 #include <sys/cdefs.h>
7 __RCSID("$NetBSD: graph.c,v 1.5 2015/01/03 23:22:52 christos Exp $");
9 static void graph_state(int stateno);
10 static void graph_LA(int ruleno);
12 static unsigned int larno;
14 void
15 graph(void)
17 int i;
18 int j;
19 shifts *sp;
20 int sn;
21 int as;
23 if (!gflag)
24 return;
26 for (i = 0; i < nstates; ++i)
28 closure(state_table[i]->items, state_table[i]->nitems);
29 graph_state(i);
32 fprintf(graph_file, "\n\n");
33 for (i = 0; i < nstates; ++i)
36 sp = shift_table[i];
37 if (sp)
38 for (j = 0; j < sp->nshifts; ++j)
40 sn = sp->shift[j];
41 as = accessing_symbol[sn];
42 fprintf(graph_file,
43 "\tq%d -> q%d [label=\"%s\"];\n",
44 i, sn, symbol_pname[as]);
48 fprintf(graph_file, "}\n");
50 for (i = 0; i < nsyms; ++i)
51 FREE(symbol_pname[i]);
52 FREE(symbol_pname);
55 static void
56 graph_state(int stateno)
58 Value_t *isp;
59 int rule;
60 Value_t *sp;
61 Value_t *sp1;
63 larno = (unsigned)lookaheads[stateno];
64 fprintf(graph_file, "\n\tq%d [label=\"%d:\\l", stateno, stateno);
66 for (isp = itemset; isp < itemsetend; isp++)
68 sp1 = sp = ritem + *isp;
70 while (*sp >= 0)
71 ++sp;
72 rule = -(*sp);
73 fprintf(graph_file, " %s -> ", symbol_pname[rlhs[rule]]);
75 for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
76 fprintf(graph_file, "%s ", symbol_pname[*sp]);
78 putc('.', graph_file);
80 while (*sp >= 0)
82 fprintf(graph_file, " %s", symbol_pname[*sp]);
83 sp++;
86 if (*sp1 < 0)
87 graph_LA(-*sp1);
89 fprintf(graph_file, "\\l");
91 fprintf(graph_file, "\"];");
94 static void
95 graph_LA(int ruleno)
97 int i;
98 unsigned tokensetsize;
99 unsigned *rowp;
101 tokensetsize = (unsigned)WORDSIZE(ntokens);
103 if (ruleno == LAruleno[larno])
105 rowp = LA + larno * tokensetsize;
107 fprintf(graph_file, " { ");
108 for (i = ntokens - 1; i >= 0; i--)
110 if (BIT(rowp, i))
111 fprintf(graph_file, "%s ", symbol_pname[i]);
113 fprintf(graph_file, "}");
114 ++larno;