sys/conf/files: Move vmx a bit up.
[dragonfly.git] / contrib / byacc / graph.c
blob6070fa2beb0f09d8d6fdc79eaf12bae1d91cb2d1
1 /* $Id: graph.c,v 1.8 2014/02/19 00:46:57 Tom.Shields Exp $ */
3 #include "defs.h"
5 static void graph_state(int stateno);
6 static void graph_LA(int ruleno);
8 static unsigned int larno;
10 void
11 graph(void)
13 int i;
14 int j;
15 shifts *sp;
16 int sn;
17 int as;
19 if (!gflag)
20 return;
22 for (i = 0; i < nstates; ++i)
24 closure(state_table[i]->items, state_table[i]->nitems);
25 graph_state(i);
28 fprintf(graph_file, "\n\n");
29 for (i = 0; i < nstates; ++i)
32 sp = shift_table[i];
33 if (sp)
34 for (j = 0; j < sp->nshifts; ++j)
36 sn = sp->shift[j];
37 as = accessing_symbol[sn];
38 fprintf(graph_file,
39 "\tq%d -> q%d [label=\"%s\"];\n",
40 i, sn, symbol_pname[as]);
44 fprintf(graph_file, "}\n");
46 for (i = 0; i < nsyms; ++i)
47 FREE(symbol_pname[i]);
48 FREE(symbol_pname);
51 static void
52 graph_state(int stateno)
54 Value_t *isp;
55 int rule;
56 Value_t *sp;
57 Value_t *sp1;
59 larno = (unsigned)lookaheads[stateno];
60 fprintf(graph_file, "\n\tq%d [label=\"%d:\\l", stateno, stateno);
62 for (isp = itemset; isp < itemsetend; isp++)
64 sp1 = sp = ritem + *isp;
66 while (*sp >= 0)
67 ++sp;
68 rule = -(*sp);
69 fprintf(graph_file, " %s -> ", symbol_pname[rlhs[rule]]);
71 for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
72 fprintf(graph_file, "%s ", symbol_pname[*sp]);
74 putc('.', graph_file);
76 while (*sp >= 0)
78 fprintf(graph_file, " %s", symbol_pname[*sp]);
79 sp++;
82 if (*sp1 < 0)
83 graph_LA(-*sp1);
85 fprintf(graph_file, "\\l");
87 fprintf(graph_file, "\"];");
90 static void
91 graph_LA(int ruleno)
93 int i;
94 unsigned tokensetsize;
95 unsigned *rowp;
97 tokensetsize = (unsigned)WORDSIZE(ntokens);
99 if (ruleno == LAruleno[larno])
101 rowp = LA + larno * tokensetsize;
103 fprintf(graph_file, " { ");
104 for (i = ntokens - 1; i >= 0; i--)
106 if (BIT(rowp, i))
107 fprintf(graph_file, "%s ", symbol_pname[i]);
109 fprintf(graph_file, "}");
110 ++larno;