+2002-05-26 Akim Demaille <akim@epita.fr>
+
+ * src/LR0.c, src/derives.c, src/gram.c, src/gram.h, src/lalr.c,
+ * src/nullable.c, src/output.c, src/print.c, src/print_graph.c,
+ * src/reader.c, src/reduce.c, src/state.h, src/symtab.h
+ (token_number_t, item_number_as_token_number)
+ (token_number_as_item_number, muscle_insert_token_number_table):
+ Rename as...
+ (symbol_number_t, item_number_as_symbol_number)
+ (symbol_number_as_item_number, muscle_insert_symbol_number_table):
+ these, since it is more appropriate.
+
2002-05-26 Akim Demaille <akim@epita.fr>
* tests/calc.at (AT_CHECK_CALC): Adjust: there are now additional
static state_t *last_state = NULL;
static int nshifts;
-static token_number_t *shift_symbol = NULL;
+static symbol_number_t *shift_symbol = NULL;
static short *redset = NULL;
static short *shiftset = NULL;
shiftset = XCALLOC (short, nsyms);
redset = XCALLOC (short, nrules + 1);
state_hash = XCALLOC (state_t *, STATE_HASH_SIZE);
- shift_symbol = XCALLOC (token_number_t, nsyms);
+ shift_symbol = XCALLOC (symbol_number_t, nsyms);
}
for (i = 0; i < nritemset; ++i)
if (ritem[itemset[i]] >= 0)
{
- token_number_t symbol
- = item_number_as_token_number (ritem[itemset[i]]);
+ symbol_number_t symbol
+ = item_number_as_symbol_number (ritem[itemset[i]]);
if (!kernel_size[symbol])
{
shift_symbol[nshifts] = symbol;
`-----------------------------------------------------------------*/
static state_t *
-new_state (token_number_t symbol, size_t core_size, item_number_t *core)
+new_state (symbol_number_t symbol, size_t core_size, item_number_t *core)
{
state_t *p;
`--------------------------------------------------------------*/
static int
-get_state (token_number_t symbol, size_t core_size, item_number_t *core)
+get_state (symbol_number_t symbol, size_t core_size, item_number_t *core)
{
int key;
size_t i;
{
int i;
int j;
- token_number_t symbol;
+ symbol_number_t symbol;
if (trace_flag)
fprintf (stderr, "Entering append_states, state = %d\n",
p = delts;
for (i = nrules; i > 0; i--)
{
- token_number_t lhs = rules[i].lhs->number;
+ symbol_number_t lhs = rules[i].lhs->number;
p->next = dset[lhs];
p->value = i;
dset[lhs] = p;
int ntokens = 1;
int nvars = 0;
-token_number_t *token_translations = NULL;
+symbol_number_t *token_translations = NULL;
-token_number_t start_symbol = 0;
+symbol_number_t start_symbol = 0;
int max_user_token_number = 256;
extern unsigned int nritems;
/* There is weird relationship between item_number_t and
- token_number_t: we store token_number_t in item_number_t, but in
+ symbol_number_t: we store symbol_number_t in item_number_t, but in
the latter we also store, as negative numbers, the rule numbers.
- Therefore, an token_number_t must be a valid item_number_t, and we
+ Therefore, an symbol_number_t must be a valid item_number_t, and we
sometimes have to perform the converse transformation. */
-#define token_number_as_item_number(Tok) ((item_number_t) (Tok))
-#define item_number_as_token_number(Ite) ((token_number_t) (Ite))
+#define symbol_number_as_item_number(Tok) ((item_number_t) (Tok))
+#define item_number_as_symbol_number(Ite) ((symbol_number_t) (Ite))
-extern token_number_t start_symbol;
+extern symbol_number_t start_symbol;
typedef struct rule_s
/* TOKEN_TRANSLATION -- a table indexed by a token number as returned
by the user's yylex routine, it yields the internal token number
used by the parser and throughout bison. */
-extern token_number_t *token_translations;
+extern symbol_number_t *token_translations;
extern int max_user_token_number;
`----------------------------------------------------------*/
static int
-map_goto (int state, token_number_t symbol)
+map_goto (int state, symbol_number_t symbol)
{
int high;
int low;
for (; j < sp->nshifts; j++)
{
- token_number_t symbol = SHIFT_SYMBOL (sp, j);
+ symbol_number_t symbol = SHIFT_SYMBOL (sp, j);
if (nullable[symbol])
edge[nedges++] = map_goto (stateno, symbol);
}
for (i = 0; i < ngotos; i++)
{
int nedges = 0;
- token_number_t symbol1 = states[to_state[i]]->accessing_symbol;
+ symbol_number_t symbol1 = states[to_state[i]]->accessing_symbol;
short *rulep;
for (rulep = derives[symbol1]; *rulep > 0; rulep++)
{
state = states[sp->shifts[j]];
if (state->accessing_symbol
- == item_number_as_token_number (*rp))
+ == item_number_as_symbol_number (*rp))
break;
}
/* JF added rp>=ritem && I hope to god its right! */
if (rp >= ritem && ISVAR (*rp))
{
- /* Downcasting from item_number_t to token_number_t. */
+ /* Downcasting from item_number_t to symbol_number_t. */
edge[nedges++] = map_goto (states1[--length],
- item_number_as_token_number (*rp));
+ item_number_as_symbol_number (*rp));
if (nullable[*rp])
done = 0;
}
set_nullable (void)
{
int ruleno;
- token_number_t *s1;
- token_number_t *s2;
+ symbol_number_t *s1;
+ symbol_number_t *s2;
shorts *p;
- token_number_t *squeue = XCALLOC (token_number_t, nvars);
+ symbol_number_t *squeue = XCALLOC (symbol_number_t, nvars);
short *rcount = XCALLOC (short, nrules + 1);
/* RITEM contains all the rules, including useless productions.
Hence we must allocate room for useless nonterminals too. */
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_unsigned_int_table, unsigned int)
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_short_table, short)
-GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_token_number_table, token_number_t)
+GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_symbol_number_table, symbol_number_t)
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_item_number_table, item_number_t)
static void
prepare_tokens (void)
{
- muscle_insert_token_number_table ("translate",
+ muscle_insert_symbol_number_table ("translate",
token_translations,
0, 1, max_user_token_number + 1);
item_number_t *rhs = XMALLOC (item_number_t, nritems);
unsigned int *prhs = XMALLOC (unsigned int, nrules + 1);
unsigned int *rline = XMALLOC (unsigned int, nrules + 1);
- token_number_t *r1 = XMALLOC (token_number_t, nrules + 1);
+ symbol_number_t *r1 = XMALLOC (symbol_number_t, nrules + 1);
unsigned int *r2 = XMALLOC (unsigned int, nrules + 1);
for (r = 1; r < nrules + 1; ++r)
muscle_insert_item_number_table ("rhs", rhs, ritem[0], 1, nritems);
muscle_insert_unsigned_int_table ("prhs", prhs, 0, 1, nrules + 1);
muscle_insert_unsigned_int_table ("rline", rline, 0, 1, nrules + 1);
- muscle_insert_token_number_table ("r1", r1, 0, 1, nrules + 1);
+ muscle_insert_symbol_number_table ("r1", r1, 0, 1, nrules + 1);
muscle_insert_unsigned_int_table ("r2", r2, 0, 1, nrules + 1);
free (rhs);
prepare_states (void)
{
size_t i;
- token_number_t *values =
- (token_number_t *) alloca (sizeof (token_number_t) * nstates);
+ symbol_number_t *values =
+ (symbol_number_t *) alloca (sizeof (symbol_number_t) * nstates);
for (i = 0; i < nstates; ++i)
values[i] = states[i]->accessing_symbol;
- muscle_insert_token_number_table ("stos", values,
+ muscle_insert_symbol_number_table ("stos", values,
0, 1, nstates);
}
to reduce. */
for (i = 0; i < shiftp->nshifts; i++)
{
- token_number_t symbol;
+ symbol_number_t symbol;
int shift_state = shiftp->shifts[i];
if (!shift_state)
continue;
if (!SHIFT_IS_DISABLED (shiftp, i))
{
int state1 = shiftp->shifts[i];
- token_number_t symbol = states[state1]->accessing_symbol;
+ symbol_number_t symbol = states[state1]->accessing_symbol;
fprintf (out,
_(" %-4s\tshift, and go to state %d\n"),
escape (symbols[symbol]->tag), state1);
if (!SHIFT_IS_DISABLED (shiftp, i))
{
int state1 = shiftp->shifts[i];
- token_number_t symbol = states[state1]->accessing_symbol;
+ symbol_number_t symbol = states[state1]->accessing_symbol;
fprintf (out, _(" %-4s\tgo to state %d\n"),
escape (symbols[symbol]->tag), state1);
}
if (state->consistent)
{
int rule = redp->rules[0];
- token_number_t symbol = rules[rule].lhs->number;
+ symbol_number_t symbol = rules[rule].lhs->number;
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
rule - 1, escape (symbols[symbol]->tag));
return;
static void
print_grammar (FILE *out)
{
- token_number_t i;
+ symbol_number_t i;
int j;
item_number_t *rule;
char buffer[90];
for (j = 1; j < nrules + 1; j++)
for (rule = rules[j].rhs; *rule >= 0; rule++)
- if (item_number_as_token_number (*rule) == token_translations[i])
+ if (item_number_as_symbol_number (*rule) == token_translations[i])
{
END_TEST (65);
sprintf (buffer + strlen (buffer), " %d", j - 1);
if (rules[j].lhs->number == i)
left_count++;
for (rule = rules[j].rhs; *rule >= 0; rule++)
- if (item_number_as_token_number (*rule) == i)
+ if (item_number_as_symbol_number (*rule) == i)
{
right_count++;
break;
for (j = 1; j < nrules + 1; j++)
{
for (rule = rules[j].rhs; *rule >= 0; rule++)
- if (item_number_as_token_number (*rule) == i)
+ if (item_number_as_symbol_number (*rule) == i)
{
END_TEST (65);
sprintf (buffer + strlen (buffer), " %d", j - 1);
if (!SHIFT_IS_DISABLED (shiftp, i))
{
int state1 = shiftp->shifts[i];
- token_number_t symbol = states[state1]->accessing_symbol;
+ symbol_number_t symbol = states[state1]->accessing_symbol;
new_edge (&edge);
max_user_token_number = this->user_token_number;
}
- token_translations = XCALLOC (token_number_t, max_user_token_number + 1);
+ token_translations = XCALLOC (symbol_number_t, max_user_token_number + 1);
/* Initialize all entries for literal tokens to 2, the internal
token number for $undefined., which represents all invalid
p = p->next;
while (p && p->sym)
{
- /* item_number_t = token_number_t.
+ /* item_number_t = symbol_number_t.
But the former needs to contain more: negative rule numbers. */
- ritem[itemno++] = token_number_as_item_number (p->sym->number);
+ ritem[itemno++] = symbol_number_as_item_number (p->sym->number);
/* A rule gets by default the precedence and associativity
of the last token in it. */
if (p->sym->class == token_sym)
static void
nonterminals_reduce (void)
{
- token_number_t i, n;
+ symbol_number_t i, n;
/* Map the nonterminals to their new index: useful first, useless
afterwards. Kept for later report. */
- token_number_t *nontermmap = XCALLOC (token_number_t, nvars) - ntokens;
+ symbol_number_t *nontermmap = XCALLOC (symbol_number_t, nvars) - ntokens;
n = ntokens;
for (i = ntokens; i < nsyms; i++)
if (bitset_test (V, i))
item_number_t *rhsp;
for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
if (ISVAR (*rhsp))
- *rhsp = token_number_as_item_number (nontermmap[*rhsp]);
+ *rhsp = symbol_number_as_item_number (nontermmap[*rhsp]);
}
start_symbol = nontermmap[start_symbol];
}
struct state_s *link;
short number;
- token_number_t accessing_symbol;
+ symbol_number_t accessing_symbol;
shifts *shifts;
reductions *reductions;
errs *errs;
/* Internal token numbers. */
-typedef short token_number_t;
+typedef short symbol_number_t;
typedef struct symbol_s symbol_t;
/* Its type. */
char *type_name;
- token_number_t number;
+ symbol_number_t number;
short prec;
associativity assoc;
int user_token_number;
#define USER_NUMBER_ALIAS -9991
/* Undefined internal token number. */
-#define NUMBER_UNDEFINED ((token_number_t) -1)
+#define NUMBER_UNDEFINED ((symbol_number_t) -1)
/* A function to apply to each symbol. */