(state_table): Be a state_t * instead of a core **.
(accessing_symbol): Remove, part of state_t.
* src/lalr.c: Adjust.
(set_accessing_symbol): Merge into...
(set_state_table): this.
* src/print_graph.c, src/conflicts.c: Adjust.
+2001-11-19 Akim Demaille <akim@epita.fr>
+
+ * src/lalr.h (state_t): New.
+ (state_table): Be a state_t * instead of a core **.
+ (accessing_symbol): Remove, part of state_t.
+ * src/lalr.c: Adjust.
+ (set_accessing_symbol): Merge into...
+ (set_state_table): this.
+ * src/print_graph.c, src/conflicts.c: Adjust.
+
2001-11-14 Akim Demaille <akim@epita.fr>
* tests/calc.at, tests/output.at, tests/regression.at,
for (i = 0; i < k; i++)
{
if (shiftp->shifts[i]
- && token == accessing_symbol[shiftp->shifts[i]])
+ && token == state_table[shiftp->shifts[i]].accessing_symbol)
(shiftp->shifts[i]) = 0;
}
}
k = shiftp->nshifts;
for (i = 0; i < k; i++)
{
- symbol = accessing_symbol[shiftp->shifts[i]];
+ symbol = state_table[shiftp->shifts[i]].accessing_symbol;
if (ISVAR (symbol))
break;
SETBIT (lookaheadset, symbol);
{
if (!shiftp->shifts[i])
continue;
- symbol = accessing_symbol[shiftp->shifts[i]];
+ symbol = state_table[shiftp->shifts[i]].accessing_symbol;
if (ISVAR (symbol))
break;
SETBIT (shiftset, symbol);
{
if (!shiftp->shifts[i])
continue;
- symbol = accessing_symbol[shiftp->shifts[i]];
+ symbol = state_table[shiftp->shifts[i]].accessing_symbol;
if (ISVAR (symbol))
break;
/* if this state has a shift for the error token,
{
if (!shiftp->shifts[i])
continue;
- symbol = accessing_symbol[shiftp->shifts[i]];
+ symbol = state_table[shiftp->shifts[i]].accessing_symbol;
if (ISVAR (symbol))
break;
SETBIT (shiftset, symbol);
#include "nullable.h"
#include "derives.h"
+/* All the decorated states, indexed by the state number. Warning:
+ there is a state_TABLE in LR0.c, but it is different and static.
+ */
+state_t *state_table = NULL;
+
int tokensetsize;
short *lookaheads;
short *LAruleno;
unsigned *LA;
-short *accessing_symbol;
+
char *consistent;
-core **state_table;
shifts **shift_table;
reductions **reduction_table;
short *goto_map;
{
core *sp;
- state_table = XCALLOC (core *, nstates);
-
- for (sp = first_state; sp; sp = sp->next)
- state_table[sp->number] = sp;
-}
-
-
-static void
-set_accessing_symbol (void)
-{
- core *sp;
-
- accessing_symbol = XCALLOC (short, nstates);
+ state_table = XCALLOC (state_t, nstates);
for (sp = first_state; sp; sp = sp->next)
- accessing_symbol[sp->number] = sp->accessing_symbol;
+ {
+ state_table[sp->number].state = sp;
+ state_table[sp->number].accessing_symbol = sp->accessing_symbol;
+ }
}
rp = reduction_table[i];
sp = shift_table[i];
- if (rp && (rp->nreds > 1
- || (sp && !ISVAR (accessing_symbol[sp->shifts[0]]))))
+ if (rp
+ && (rp->nreds > 1
+ || (sp && !ISVAR (state_table[sp->shifts[0]].accessing_symbol))))
count += rp->nreds;
else
consistent[i] = 1;
if (sp)
for (k = 0; k < sp->nshifts; k++)
- {
- if (accessing_symbol[sp->shifts[k]] == error_token_number)
- {
- consistent[i] = 0;
- break;
- }
- }
+ if (state_table[sp->shifts[k]].accessing_symbol
+ == error_token_number)
+ {
+ consistent[i] = 0;
+ break;
+ }
}
lookaheads[nstates] = count;
{
for (i = sp->nshifts - 1; i >= 0; i--)
{
- symbol = accessing_symbol[sp->shifts[i]];
+ symbol = state_table[sp->shifts[i]].accessing_symbol;
if (ISTOKEN (symbol))
break;
for (i = sp->nshifts - 1; i >= 0; i--)
{
state2 = sp->shifts[i];
- symbol = accessing_symbol[state2];
+ symbol = state_table[state2].accessing_symbol;
if (ISTOKEN (symbol))
break;
for (j = 0; j < k; j++)
{
- symbol = accessing_symbol[sp->shifts[j]];
+ symbol = state_table[sp->shifts[j]].accessing_symbol;
if (ISVAR (symbol))
break;
SETBIT (rowp, symbol);
for (; j < k; j++)
{
- symbol = accessing_symbol[sp->shifts[j]];
+ symbol = state_table[sp->shifts[j]].accessing_symbol;
if (nullable[symbol])
edge[nedges++] = map_goto (stateno, symbol);
}
{
nedges = 0;
state1 = from_state[i];
- symbol1 = accessing_symbol[to_state[i]];
+ symbol1 = state_table[to_state[i]].accessing_symbol;
for (rulep = derives[symbol1]; *rulep > 0; rulep++)
{
for (j = 0; j < k; j++)
{
stateno = sp->shifts[j];
- if (accessing_symbol[stateno] == symbol2)
+ if (state_table[stateno].accessing_symbol == symbol2)
break;
}
tokensetsize = WORDSIZE (ntokens);
set_state_table ();
- set_accessing_symbol ();
set_shift_table ();
set_reduction_table ();
set_maxrhs ();
extern unsigned *LA;
+/* A structure decorating a state, with additional information. */
+typedef struct state_s
+{
+ /* A state. */
+ core *state;
+
+ /* Its accessing symbol. */
+ short accessing_symbol;
+} state_t;
+
+/* All the decorated states, indexed by the state number. Warning:
+ there is a state_TABLE in LR0.c, but it is different and static.
+ */
+extern state_t *state_table;
+
extern int tokensetsize;
extern short *lookaheads;
-extern short *accessing_symbol;
-extern core **state_table;
extern shifts **shift_table;
extern reductions **reduction_table;
static void
output_stos (void)
{
- output_table_data (&output_obstack, accessing_symbol,
+ int i;
+ short *values = (short *) alloca (sizeof (short) * nstates);
+ for (i = 0; i < nstates; ++i)
+ values[i] = state_table[i].accessing_symbol;
+ output_table_data (&output_obstack, values,
0, 1, nstates);
muscle_insert ("stos", obstack_finish (&output_obstack));
}
if (!shift_state)
continue;
- symbol = accessing_symbol[shift_state];
+ symbol = state_table[shift_state].accessing_symbol;
if (ISVAR (symbol))
break;
XFREE (lookaheads);
XFREE (LA);
XFREE (LAruleno);
- XFREE (accessing_symbol);
goto_actions ();
XFREE (goto_map + ntokens);
output_table ();
output_check ();
+ XFREE (state_table);
}
\f
free_itemsets (void)
{
core *cp, *cptmp;
-
- XFREE (state_table);
-
for (cp = first_state; cp; cp = cptmp)
{
cptmp = cp->next;
short *sp;
short *sp1;
- statep = state_table[state];
+ statep = state_table[state].state;
k = statep->nitems;
if (k == 0)
if (!shiftp->shifts[i])
continue;
state1 = shiftp->shifts[i];
- symbol = accessing_symbol[state1];
+ symbol = state_table[state1].accessing_symbol;
/* The following line used to be turned off. */
if (ISVAR (symbol))
break;
if (!shiftp->shifts[i])
continue;
state1 = shiftp->shifts[i];
- symbol = accessing_symbol[state1];
+ symbol = state_table[state1].accessing_symbol;
fprintf (out, _(" %-4s\tgo to state %d\n"),
tags[symbol], state1);
}
short *sp;
short *sp1;
- statep = state_table[state];
+ statep = state_table[state].state;
k = statep->nitems;
if (k == 0)
}
}
-/* Output in graph_obstack edges specifications in incidence with current
+/* Output in graph_obstack edges specifications in incidence with current
node. */
static void
print_actions (int state, const char *node_name, struct obstack *node_obstack)
if (!shiftp->shifts[i])
continue;
state1 = shiftp->shifts[i];
- symbol = accessing_symbol[state1];
+ symbol = state_table[state1].accessing_symbol;
if (ISVAR (symbol))
break;
if (!shiftp->shifts[i])
continue;
state1 = shiftp->shifts[i];
- symbol = accessing_symbol[state1];
+ symbol = state_table[state1].accessing_symbol;
new_edge (&edge);
open_edge (&edge, fgraph);
}
}
-/* Output in GRAPH_OBSTACK the current node specifications and edges
+/* Output in GRAPH_OBSTACK the current node specifications and edges
which go out from that node. */
static void
print_state (int state)
new_node (&node); /* Set node attributs default value. */
sprintf (name, "%d", state);
node.title = name; /* Give a name to the node. */
-
- {
- /* Here we begin to compute the node label. */
+
+ {
+ /* Here we begin to compute the node label. */
obstack_sgrow (&node_obstack, "\t\tlabel:\t\""); /* Open Label */
-
- /* Keep the size of NODE_OBSTACK before computing the label. It is
+
+ /* Keep the size of NODE_OBSTACK before computing the label. It is
useful to format the label. */
node_output_size = obstack_object_size (&node_obstack);
-
+
/* Compute the labels of nodes on the fly. */
print_core (state, &node_obstack);
/* Compute edges and additionnal parts of node label. */
print_actions (state, node.title, &node_obstack);
-
+
obstack_sgrow (&node_obstack, "\"\n"); /* Close Label. */
- }
+ }
open_node (fgraph);
/* Output a VCG formatted attributs list. */
output_node (&node, fgraph);
/* Save the node label. */
- fwrite (obstack_base (&node_obstack),
+ fwrite (obstack_base (&node_obstack),
obstack_object_size (&node_obstack), 1, fgraph);
close_node (fgraph);
print_graph (void)
{
int i;
-
+
if (!graph_flag)
return;
#if 0
graph.smanhattan_edges = yes;
- graph.manhattan_edges = yes;
+ graph.manhattan_edges = yes;
#endif
graph.display_edge_labels = yes;