mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-21 02:03:03 +00:00
Propagate more token_number_t.
* src/gram.h (token_number_as_item_number) (item_number_as_token_number): New. * src/output.c (GENERATE_OUTPUT_TABLE): New. Use it to create output_item_number_table and output_token_number_table. * src/LR0.c, src/derives.c, src/gram.c, src/gram.h, src/lalr.c, * src/lex.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.c, src/symtab.h: Use token_number_t instead of shorts.
This commit is contained in:
15
ChangeLog
15
ChangeLog
@@ -1,3 +1,18 @@
|
|||||||
|
2002-04-22 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
Propagate more token_number_t.
|
||||||
|
|
||||||
|
* src/gram.h (token_number_as_item_number)
|
||||||
|
(item_number_as_token_number): New.
|
||||||
|
* src/output.c (GENERATE_OUTPUT_TABLE): New.
|
||||||
|
Use it to create output_item_number_table and
|
||||||
|
output_token_number_table.
|
||||||
|
* src/LR0.c, src/derives.c, src/gram.c, src/gram.h, src/lalr.c,
|
||||||
|
* src/lex.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.c, src/symtab.h: Use token_number_t instead of shorts.
|
||||||
|
|
||||||
|
|
||||||
2002-04-22 Akim Demaille <akim@epita.fr>
|
2002-04-22 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/output.h, src/output.c (get_lines_number): Remove.
|
* src/output.h, src/output.c (get_lines_number): Remove.
|
||||||
|
|||||||
36
src/LR0.c
36
src/LR0.c
@@ -26,6 +26,7 @@
|
|||||||
#include "bitset.h"
|
#include "bitset.h"
|
||||||
#include "quotearg.h"
|
#include "quotearg.h"
|
||||||
#include "symtab.h"
|
#include "symtab.h"
|
||||||
|
#include "gram.h"
|
||||||
#include "getargs.h"
|
#include "getargs.h"
|
||||||
#include "reader.h"
|
#include "reader.h"
|
||||||
#include "gram.h"
|
#include "gram.h"
|
||||||
@@ -51,7 +52,7 @@ static state_t *this_state = NULL;
|
|||||||
static state_t *last_state = NULL;
|
static state_t *last_state = NULL;
|
||||||
|
|
||||||
static int nshifts;
|
static int nshifts;
|
||||||
static short *shift_symbol = NULL;
|
static token_number_t *shift_symbol = NULL;
|
||||||
|
|
||||||
static short *redset = NULL;
|
static short *redset = NULL;
|
||||||
static short *shiftset = NULL;
|
static short *shiftset = NULL;
|
||||||
@@ -116,7 +117,7 @@ allocate_storage (void)
|
|||||||
shiftset = XCALLOC (short, nsyms);
|
shiftset = XCALLOC (short, nsyms);
|
||||||
redset = XCALLOC (short, nrules + 1);
|
redset = XCALLOC (short, nrules + 1);
|
||||||
state_hash = XCALLOC (state_t *, STATE_HASH_SIZE);
|
state_hash = XCALLOC (state_t *, STATE_HASH_SIZE);
|
||||||
shift_symbol = XCALLOC (short, nsyms);
|
shift_symbol = XCALLOC (token_number_t, nsyms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -161,20 +162,19 @@ new_itemsets (void)
|
|||||||
nshifts = 0;
|
nshifts = 0;
|
||||||
|
|
||||||
for (i = 0; i < nritemset; ++i)
|
for (i = 0; i < nritemset; ++i)
|
||||||
{
|
if (ritem[itemset[i]] >= 0)
|
||||||
int symbol = ritem[itemset[i]];
|
{
|
||||||
if (symbol >= 0)
|
token_number_t symbol
|
||||||
{
|
= item_number_as_token_number (ritem[itemset[i]]);
|
||||||
if (!kernel_size[symbol])
|
if (!kernel_size[symbol])
|
||||||
{
|
{
|
||||||
shift_symbol[nshifts] = symbol;
|
shift_symbol[nshifts] = symbol;
|
||||||
nshifts++;
|
nshifts++;
|
||||||
}
|
}
|
||||||
|
|
||||||
kernel_base[symbol][kernel_size[symbol]] = itemset[i] + 1;
|
kernel_base[symbol][kernel_size[symbol]] = itemset[i] + 1;
|
||||||
kernel_size[symbol]++;
|
kernel_size[symbol]++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ new_itemsets (void)
|
|||||||
`-----------------------------------------------------------------*/
|
`-----------------------------------------------------------------*/
|
||||||
|
|
||||||
static state_t *
|
static state_t *
|
||||||
new_state (int symbol)
|
new_state (token_number_t symbol)
|
||||||
{
|
{
|
||||||
state_t *p;
|
state_t *p;
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@ new_state (int symbol)
|
|||||||
`--------------------------------------------------------------*/
|
`--------------------------------------------------------------*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_state (int symbol)
|
get_state (token_number_t symbol)
|
||||||
{
|
{
|
||||||
int key;
|
int key;
|
||||||
int i;
|
int i;
|
||||||
@@ -298,7 +298,7 @@ append_states (void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int symbol;
|
token_number_t symbol;
|
||||||
|
|
||||||
if (trace_flag)
|
if (trace_flag)
|
||||||
fprintf (stderr, "Entering append_states, state = %d\n",
|
fprintf (stderr, "Entering append_states, state = %d\n",
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ set_derives (void)
|
|||||||
p = delts;
|
p = delts;
|
||||||
for (i = nrules; i > 0; i--)
|
for (i = nrules; i > 0; i--)
|
||||||
{
|
{
|
||||||
int lhs = rules[i].lhs->number;
|
token_number_t lhs = rules[i].lhs->number;
|
||||||
p->next = dset[lhs];
|
p->next = dset[lhs];
|
||||||
p->value = i;
|
p->value = i;
|
||||||
dset[lhs] = p;
|
dset[lhs] = p;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ int nvars = 0;
|
|||||||
|
|
||||||
token_number_t *token_translations = NULL;
|
token_number_t *token_translations = NULL;
|
||||||
|
|
||||||
int start_symbol = 0;
|
token_number_t start_symbol = 0;
|
||||||
|
|
||||||
int max_user_token_number = 256;
|
int max_user_token_number = 256;
|
||||||
|
|
||||||
|
|||||||
11
src/gram.h
11
src/gram.h
@@ -114,7 +114,16 @@ typedef int item_number_t;
|
|||||||
extern item_number_t *ritem;
|
extern item_number_t *ritem;
|
||||||
extern int nritems;
|
extern int nritems;
|
||||||
|
|
||||||
extern int start_symbol;
|
/* There is weird relationship between item_number_t and
|
||||||
|
token_number_t: we store token_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
|
||||||
|
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))
|
||||||
|
|
||||||
|
extern token_number_t start_symbol;
|
||||||
|
|
||||||
|
|
||||||
typedef struct rule_s
|
typedef struct rule_s
|
||||||
|
|||||||
13
src/lalr.c
13
src/lalr.c
@@ -217,7 +217,7 @@ set_goto_map (void)
|
|||||||
`----------------------------------------------------------*/
|
`----------------------------------------------------------*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
map_goto (int state, int symbol)
|
map_goto (int state, token_number_t symbol)
|
||||||
{
|
{
|
||||||
int high;
|
int high;
|
||||||
int low;
|
int low;
|
||||||
@@ -267,7 +267,7 @@ initialize_F (void)
|
|||||||
|
|
||||||
for (; j < sp->nshifts; j++)
|
for (; j < sp->nshifts; j++)
|
||||||
{
|
{
|
||||||
int symbol = SHIFT_SYMBOL (sp, j);
|
token_number_t symbol = SHIFT_SYMBOL (sp, j);
|
||||||
if (nullable[symbol])
|
if (nullable[symbol])
|
||||||
edge[nedges++] = map_goto (stateno, symbol);
|
edge[nedges++] = map_goto (stateno, symbol);
|
||||||
}
|
}
|
||||||
@@ -408,7 +408,7 @@ build_relations (void)
|
|||||||
for (i = 0; i < ngotos; i++)
|
for (i = 0; i < ngotos; i++)
|
||||||
{
|
{
|
||||||
int nedges = 0;
|
int nedges = 0;
|
||||||
int symbol1 = states[to_state[i]]->accessing_symbol;
|
token_number_t symbol1 = states[to_state[i]]->accessing_symbol;
|
||||||
short *rulep;
|
short *rulep;
|
||||||
|
|
||||||
for (rulep = derives[symbol1]; *rulep > 0; rulep++)
|
for (rulep = derives[symbol1]; *rulep > 0; rulep++)
|
||||||
@@ -426,7 +426,8 @@ build_relations (void)
|
|||||||
for (j = 0; j < sp->nshifts; j++)
|
for (j = 0; j < sp->nshifts; j++)
|
||||||
{
|
{
|
||||||
state = states[sp->shifts[j]];
|
state = states[sp->shifts[j]];
|
||||||
if (state->accessing_symbol == *rp)
|
if (state->accessing_symbol
|
||||||
|
== item_number_as_token_number (*rp))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,7 +446,9 @@ build_relations (void)
|
|||||||
/* JF added rp>=ritem && I hope to god its right! */
|
/* JF added rp>=ritem && I hope to god its right! */
|
||||||
if (rp >= ritem && ISVAR (*rp))
|
if (rp >= ritem && ISVAR (*rp))
|
||||||
{
|
{
|
||||||
edge[nedges++] = map_goto (states1[--length], *rp);
|
/* Downcasting from item_number_t to token_number_t. */
|
||||||
|
edge[nedges++] = map_goto (states1[--length],
|
||||||
|
item_number_as_token_number (*rp));
|
||||||
if (nullable[*rp])
|
if (nullable[*rp])
|
||||||
done = 0;
|
done = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -364,7 +364,7 @@ lex (void)
|
|||||||
obstack_1grow (&token_obstack, '\0');
|
obstack_1grow (&token_obstack, '\0');
|
||||||
token_buffer = obstack_finish (&token_obstack);
|
token_buffer = obstack_finish (&token_obstack);
|
||||||
symval = getsym (token_buffer);
|
symval = getsym (token_buffer);
|
||||||
if (symval->number == -1)
|
if (symval->number == NUMBER_UNDEFINED)
|
||||||
{
|
{
|
||||||
symval->number = ntokens++;
|
symval->number = ntokens++;
|
||||||
symval->class = token_sym;
|
symval->class = token_sym;
|
||||||
@@ -392,7 +392,7 @@ lex (void)
|
|||||||
token_buffer = obstack_finish (&token_obstack);
|
token_buffer = obstack_finish (&token_obstack);
|
||||||
|
|
||||||
symval = getsym (token_buffer);
|
symval = getsym (token_buffer);
|
||||||
if (symval->number == -1)
|
if (symval->number == NUMBER_UNDEFINED)
|
||||||
{
|
{
|
||||||
symval->number = ntokens++;
|
symval->number = ntokens++;
|
||||||
symval->class = token_sym;
|
symval->class = token_sym;
|
||||||
|
|||||||
@@ -47,11 +47,11 @@ void
|
|||||||
set_nullable (void)
|
set_nullable (void)
|
||||||
{
|
{
|
||||||
int ruleno;
|
int ruleno;
|
||||||
short *s1;
|
token_number_t *s1;
|
||||||
short *s2;
|
token_number_t *s2;
|
||||||
shorts *p;
|
shorts *p;
|
||||||
|
|
||||||
short *squeue = XCALLOC (short, nvars);
|
token_number_t *squeue = XCALLOC (token_number_t, nvars);
|
||||||
short *rcount = XCALLOC (short, nrules + 1);
|
short *rcount = XCALLOC (short, nrules + 1);
|
||||||
/* RITEM contains all the rules, including useless productions.
|
/* RITEM contains all the rules, including useless productions.
|
||||||
Hence we must allocate room for useless nonterminals too. */
|
Hence we must allocate room for useless nonterminals too. */
|
||||||
|
|||||||
125
src/output.c
125
src/output.c
@@ -133,77 +133,50 @@ static struct obstack format_obstack;
|
|||||||
int error_verbose = 0;
|
int error_verbose = 0;
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------.
|
/*------------------------------------------------------------------.
|
||||||
| Format the FIRST and then TABLE_DATA[BEGIN..END[ into OOUT, and |
|
| Create a function NAME which Format the FIRST and then |
|
||||||
| return the number of bits needed for its longuest value. |
|
| TABLE_DATA[BEGIN..END[ (of TYPE) into OOUT, and return the number |
|
||||||
`----------------------------------------------------------------*/
|
| of bits needed for its longuest value. |
|
||||||
|
`------------------------------------------------------------------*/
|
||||||
|
|
||||||
static inline long int
|
|
||||||
output_short_table (struct obstack *oout,
|
|
||||||
short *table_data,
|
|
||||||
short first,
|
|
||||||
int begin,
|
|
||||||
int end)
|
|
||||||
{
|
|
||||||
long int max = first;
|
|
||||||
int i;
|
|
||||||
int j = 1;
|
|
||||||
|
|
||||||
obstack_fgrow1 (oout, "%6d", first);
|
#define GENERATE_OUTPUT_TABLE(Name, Type) \
|
||||||
for (i = begin; i < end; ++i)
|
\
|
||||||
{
|
static inline long int \
|
||||||
obstack_1grow (oout, ',');
|
Name (struct obstack *oout, \
|
||||||
if (j >= 10)
|
Type *table_data, \
|
||||||
{
|
Type first, \
|
||||||
obstack_sgrow (oout, "\n ");
|
int begin, \
|
||||||
j = 1;
|
int end) \
|
||||||
}
|
{ \
|
||||||
else
|
long int max = first; \
|
||||||
++j;
|
int i; \
|
||||||
obstack_fgrow1 (oout, "%6d", table_data[i]);
|
int j = 1; \
|
||||||
if (table_data[i] > max)
|
\
|
||||||
max = table_data[i];
|
obstack_fgrow1 (oout, "%6d", first); \
|
||||||
}
|
for (i = begin; i < end; ++i) \
|
||||||
obstack_1grow (oout, 0);
|
{ \
|
||||||
|
obstack_1grow (oout, ','); \
|
||||||
return max;
|
if (j >= 10) \
|
||||||
|
{ \
|
||||||
|
obstack_sgrow (oout, "\n "); \
|
||||||
|
j = 1; \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
++j; \
|
||||||
|
obstack_fgrow1 (oout, "%6d", table_data[i]); \
|
||||||
|
if (table_data[i] > max) \
|
||||||
|
max = table_data[i]; \
|
||||||
|
} \
|
||||||
|
obstack_1grow (oout, 0); \
|
||||||
|
\
|
||||||
|
return max; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GENERATE_OUTPUT_TABLE(output_int_table, int)
|
||||||
/*--------------------.
|
GENERATE_OUTPUT_TABLE(output_short_table, short)
|
||||||
| Similar, for ints. |
|
GENERATE_OUTPUT_TABLE(output_token_number_table, token_number_t)
|
||||||
`--------------------*/
|
GENERATE_OUTPUT_TABLE(output_item_number_table, item_number_t)
|
||||||
|
|
||||||
static inline long int
|
|
||||||
output_int_table (struct obstack *oout,
|
|
||||||
int *table_data,
|
|
||||||
int first,
|
|
||||||
int begin,
|
|
||||||
int end)
|
|
||||||
{
|
|
||||||
long int max = first;
|
|
||||||
int i;
|
|
||||||
int j = 1;
|
|
||||||
|
|
||||||
obstack_fgrow1 (oout, "%6d", first);
|
|
||||||
for (i = begin; i < end; ++i)
|
|
||||||
{
|
|
||||||
obstack_1grow (oout, ',');
|
|
||||||
if (j >= 10)
|
|
||||||
{
|
|
||||||
obstack_sgrow (oout, "\n ");
|
|
||||||
j = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
++j;
|
|
||||||
obstack_fgrow1 (oout, "%6d", table_data[i]);
|
|
||||||
if (table_data[i] > max)
|
|
||||||
max = table_data[i];
|
|
||||||
}
|
|
||||||
obstack_1grow (oout, 0);
|
|
||||||
|
|
||||||
return max;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------.
|
/*-----------------------------------------------------------------.
|
||||||
@@ -214,8 +187,9 @@ output_int_table (struct obstack *oout,
|
|||||||
static void
|
static void
|
||||||
prepare_tokens (void)
|
prepare_tokens (void)
|
||||||
{
|
{
|
||||||
long int max = output_short_table (&format_obstack, token_translations,
|
long int max = output_token_number_table (&format_obstack,
|
||||||
0, 1, max_user_token_number + 1);
|
token_translations,
|
||||||
|
0, 1, max_user_token_number + 1);
|
||||||
muscle_insert ("translate", obstack_finish (&format_obstack));
|
muscle_insert ("translate", obstack_finish (&format_obstack));
|
||||||
MUSCLE_INSERT_LONG_INT ("token_number_max", max);
|
MUSCLE_INSERT_LONG_INT ("token_number_max", max);
|
||||||
XFREE (token_translations);
|
XFREE (token_translations);
|
||||||
@@ -281,7 +255,7 @@ prepare_rules (void)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
item_number_t *rhs = XMALLOC (item_number_t, nritems);
|
item_number_t *rhs = XMALLOC (item_number_t, nritems);
|
||||||
short *prhs = XMALLOC (short, nrules + 1);
|
short *prhs = XMALLOC (short, nrules + 1);
|
||||||
short *r1 = XMALLOC (short, nrules + 1);
|
token_number_t *r1 = XMALLOC (token_number_t, nrules + 1);
|
||||||
short *r2 = XMALLOC (short, nrules + 1);
|
short *r2 = XMALLOC (short, nrules + 1);
|
||||||
short *rline = XMALLOC (short, nrules + 1);
|
short *rline = XMALLOC (short, nrules + 1);
|
||||||
|
|
||||||
@@ -313,7 +287,7 @@ prepare_rules (void)
|
|||||||
output_short_table (&format_obstack, rline, 0, 1, nrules + 1);
|
output_short_table (&format_obstack, rline, 0, 1, nrules + 1);
|
||||||
muscle_insert ("rline", obstack_finish (&format_obstack));
|
muscle_insert ("rline", obstack_finish (&format_obstack));
|
||||||
|
|
||||||
output_short_table (&format_obstack, r1, 0, 1, nrules + 1);
|
output_token_number_table (&format_obstack, r1, 0, 1, nrules + 1);
|
||||||
muscle_insert ("r1", obstack_finish (&format_obstack));
|
muscle_insert ("r1", obstack_finish (&format_obstack));
|
||||||
|
|
||||||
output_short_table (&format_obstack, r2, 0, 1, nrules + 1);
|
output_short_table (&format_obstack, r2, 0, 1, nrules + 1);
|
||||||
@@ -332,11 +306,12 @@ static void
|
|||||||
prepare_states (void)
|
prepare_states (void)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
short *values = (short *) alloca (sizeof (short) * nstates);
|
token_number_t *values =
|
||||||
|
(token_number_t *) alloca (sizeof (token_number_t) * nstates);
|
||||||
for (i = 0; i < nstates; ++i)
|
for (i = 0; i < nstates; ++i)
|
||||||
values[i] = states[i]->accessing_symbol;
|
values[i] = states[i]->accessing_symbol;
|
||||||
output_short_table (&format_obstack, values,
|
output_token_number_table (&format_obstack, values,
|
||||||
0, 1, nstates);
|
0, 1, nstates);
|
||||||
muscle_insert ("stos", obstack_finish (&format_obstack));
|
muscle_insert ("stos", obstack_finish (&format_obstack));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,7 +364,7 @@ action_row (state_t *state)
|
|||||||
to reduce. */
|
to reduce. */
|
||||||
for (i = 0; i < shiftp->nshifts; i++)
|
for (i = 0; i < shiftp->nshifts; i++)
|
||||||
{
|
{
|
||||||
int symbol;
|
token_number_t symbol;
|
||||||
int shift_state = shiftp->shifts[i];
|
int shift_state = shiftp->shifts[i];
|
||||||
if (!shift_state)
|
if (!shift_state)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
21
src/print.c
21
src/print.c
@@ -124,7 +124,7 @@ print_shifts (FILE *out, state_t *state)
|
|||||||
if (!SHIFT_IS_DISABLED (shiftp, i))
|
if (!SHIFT_IS_DISABLED (shiftp, i))
|
||||||
{
|
{
|
||||||
int state1 = shiftp->shifts[i];
|
int state1 = shiftp->shifts[i];
|
||||||
int symbol = states[state1]->accessing_symbol;
|
token_number_t symbol = states[state1]->accessing_symbol;
|
||||||
fprintf (out,
|
fprintf (out,
|
||||||
_(" %-4s\tshift, and go to state %d\n"),
|
_(" %-4s\tshift, and go to state %d\n"),
|
||||||
escape (symbols[symbol]->tag), state1);
|
escape (symbols[symbol]->tag), state1);
|
||||||
@@ -166,7 +166,7 @@ print_gotos (FILE *out, state_t *state)
|
|||||||
if (!SHIFT_IS_DISABLED (shiftp, i))
|
if (!SHIFT_IS_DISABLED (shiftp, i))
|
||||||
{
|
{
|
||||||
int state1 = shiftp->shifts[i];
|
int state1 = shiftp->shifts[i];
|
||||||
int symbol = states[state1]->accessing_symbol;
|
token_number_t symbol = states[state1]->accessing_symbol;
|
||||||
fprintf (out, _(" %-4s\tgo to state %d\n"),
|
fprintf (out, _(" %-4s\tgo to state %d\n"),
|
||||||
escape (symbols[symbol]->tag), state1);
|
escape (symbols[symbol]->tag), state1);
|
||||||
}
|
}
|
||||||
@@ -190,7 +190,7 @@ print_reductions (FILE *out, state_t *state)
|
|||||||
if (state->consistent)
|
if (state->consistent)
|
||||||
{
|
{
|
||||||
int rule = redp->rules[0];
|
int rule = redp->rules[0];
|
||||||
int symbol = rules[rule].lhs->number;
|
token_number_t symbol = rules[rule].lhs->number;
|
||||||
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
|
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
|
||||||
rule - 1, escape (symbols[symbol]->tag));
|
rule - 1, escape (symbols[symbol]->tag));
|
||||||
return;
|
return;
|
||||||
@@ -360,7 +360,8 @@ do { \
|
|||||||
static void
|
static void
|
||||||
print_grammar (FILE *out)
|
print_grammar (FILE *out)
|
||||||
{
|
{
|
||||||
int i, j;
|
token_number_t i;
|
||||||
|
int j;
|
||||||
item_number_t *rule;
|
item_number_t *rule;
|
||||||
char buffer[90];
|
char buffer[90];
|
||||||
int column = 0;
|
int column = 0;
|
||||||
@@ -368,11 +369,11 @@ print_grammar (FILE *out)
|
|||||||
/* rule # : LHS -> RHS */
|
/* rule # : LHS -> RHS */
|
||||||
fprintf (out, "%s\n\n", _("Grammar"));
|
fprintf (out, "%s\n\n", _("Grammar"));
|
||||||
fprintf (out, " %s\n", _("Number, Line, Rule"));
|
fprintf (out, " %s\n", _("Number, Line, Rule"));
|
||||||
for (i = 1; i < nrules + 1; i++)
|
for (j = 1; j < nrules + 1; j++)
|
||||||
{
|
{
|
||||||
fprintf (out, _(" %3d %3d %s ->"),
|
fprintf (out, _(" %3d %3d %s ->"),
|
||||||
i - 1, rules[i].line, escape (rules[i].lhs->tag));
|
j - 1, rules[j].line, escape (rules[j].lhs->tag));
|
||||||
rule = rules[i].rhs;
|
rule = rules[j].rhs;
|
||||||
if (*rule >= 0)
|
if (*rule >= 0)
|
||||||
while (*rule >= 0)
|
while (*rule >= 0)
|
||||||
fprintf (out, " %s", escape (symbols[*rule++]->tag));
|
fprintf (out, " %s", escape (symbols[*rule++]->tag));
|
||||||
@@ -396,7 +397,7 @@ print_grammar (FILE *out)
|
|||||||
|
|
||||||
for (j = 1; j < nrules + 1; j++)
|
for (j = 1; j < nrules + 1; j++)
|
||||||
for (rule = rules[j].rhs; *rule >= 0; rule++)
|
for (rule = rules[j].rhs; *rule >= 0; rule++)
|
||||||
if (*rule == token_translations[i])
|
if (item_number_as_token_number (*rule) == token_translations[i])
|
||||||
{
|
{
|
||||||
END_TEST (65);
|
END_TEST (65);
|
||||||
sprintf (buffer + strlen (buffer), " %d", j - 1);
|
sprintf (buffer + strlen (buffer), " %d", j - 1);
|
||||||
@@ -417,7 +418,7 @@ print_grammar (FILE *out)
|
|||||||
if (rules[j].lhs->number == i)
|
if (rules[j].lhs->number == i)
|
||||||
left_count++;
|
left_count++;
|
||||||
for (rule = rules[j].rhs; *rule >= 0; rule++)
|
for (rule = rules[j].rhs; *rule >= 0; rule++)
|
||||||
if (*rule == i)
|
if (item_number_as_token_number (*rule) == i)
|
||||||
{
|
{
|
||||||
right_count++;
|
right_count++;
|
||||||
break;
|
break;
|
||||||
@@ -452,7 +453,7 @@ print_grammar (FILE *out)
|
|||||||
for (j = 1; j < nrules + 1; j++)
|
for (j = 1; j < nrules + 1; j++)
|
||||||
{
|
{
|
||||||
for (rule = rules[j].rhs; *rule >= 0; rule++)
|
for (rule = rules[j].rhs; *rule >= 0; rule++)
|
||||||
if (*rule == i)
|
if (item_number_as_token_number (*rule) == i)
|
||||||
{
|
{
|
||||||
END_TEST (65);
|
END_TEST (65);
|
||||||
sprintf (buffer + strlen (buffer), " %d", j - 1);
|
sprintf (buffer + strlen (buffer), " %d", j - 1);
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ print_actions (state_t *state, const char *node_name)
|
|||||||
if (!SHIFT_IS_DISABLED (shiftp, i))
|
if (!SHIFT_IS_DISABLED (shiftp, i))
|
||||||
{
|
{
|
||||||
int state1 = shiftp->shifts[i];
|
int state1 = shiftp->shifts[i];
|
||||||
int symbol = states[state1]->accessing_symbol;
|
token_number_t symbol = states[state1]->accessing_symbol;
|
||||||
|
|
||||||
new_edge (&edge);
|
new_edge (&edge);
|
||||||
|
|
||||||
|
|||||||
14
src/reader.c
14
src/reader.c
@@ -199,13 +199,13 @@ symbol_pack (symbol_t *this)
|
|||||||
/* This symbol and its alias are a single token defn.
|
/* This symbol and its alias are a single token defn.
|
||||||
Allocate a tokno, and assign to both check agreement of
|
Allocate a tokno, and assign to both check agreement of
|
||||||
prec and assoc fields and make both the same */
|
prec and assoc fields and make both the same */
|
||||||
if (this->number == -1)
|
if (this->number == NUMBER_UNDEFINED)
|
||||||
{
|
{
|
||||||
if (this == eoftoken || this->alias == eoftoken)
|
if (this == eoftoken || this->alias == eoftoken)
|
||||||
this->number = this->alias->number = 0;
|
this->number = this->alias->number = 0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert (this->alias->number != -1);
|
assert (this->alias->number != NUMBER_UNDEFINED);
|
||||||
this->number = this->alias->number;
|
this->number = this->alias->number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@ symbol_pack (symbol_t *this)
|
|||||||
}
|
}
|
||||||
else /* this->class == token_sym */
|
else /* this->class == token_sym */
|
||||||
{
|
{
|
||||||
assert (this->number != -1);
|
assert (this->number != NUMBER_UNDEFINED);
|
||||||
}
|
}
|
||||||
|
|
||||||
symbols[this->number] = this;
|
symbols[this->number] = this;
|
||||||
@@ -705,7 +705,7 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not)
|
|||||||
symbol->class = what_is;
|
symbol->class = what_is;
|
||||||
if (what_is == nterm_sym && oldclass != nterm_sym)
|
if (what_is == nterm_sym && oldclass != nterm_sym)
|
||||||
symbol->number = nvars++;
|
symbol->number = nvars++;
|
||||||
if (what_is == token_sym && symbol->number == -1)
|
if (what_is == token_sym && symbol->number == NUMBER_UNDEFINED)
|
||||||
symbol->number = ntokens++;
|
symbol->number = ntokens++;
|
||||||
|
|
||||||
if (typename)
|
if (typename)
|
||||||
@@ -857,7 +857,7 @@ parse_assoc_decl (associativity assoc)
|
|||||||
symval->assoc = assoc;
|
symval->assoc = assoc;
|
||||||
if (symval->class == nterm_sym)
|
if (symval->class == nterm_sym)
|
||||||
complain (_("symbol %s redefined"), symval->tag);
|
complain (_("symbol %s redefined"), symval->tag);
|
||||||
if (symval->number == -1)
|
if (symval->number == NUMBER_UNDEFINED)
|
||||||
{
|
{
|
||||||
symval->number = ntokens++;
|
symval->number = ntokens++;
|
||||||
symval->class = token_sym;
|
symval->class = token_sym;
|
||||||
@@ -1763,7 +1763,9 @@ packgram (void)
|
|||||||
p = p->next;
|
p = p->next;
|
||||||
while (p && p->sym)
|
while (p && p->sym)
|
||||||
{
|
{
|
||||||
ritem[itemno++] = p->sym->number;
|
/* item_number_t = token_number_t.
|
||||||
|
But the former needs to contain more: negative rule numbers. */
|
||||||
|
ritem[itemno++] = token_number_as_item_number (p->sym->number);
|
||||||
/* A rule gets by default the precedence and associativity
|
/* A rule gets by default the precedence and associativity
|
||||||
of the last token in it. */
|
of the last token in it. */
|
||||||
if (p->sym->class == token_sym)
|
if (p->sym->class == token_sym)
|
||||||
|
|||||||
@@ -278,12 +278,12 @@ reduce_grammar_tables (void)
|
|||||||
static void
|
static void
|
||||||
nonterminals_reduce (void)
|
nonterminals_reduce (void)
|
||||||
{
|
{
|
||||||
int i, n;
|
token_number_t i, n;
|
||||||
|
|
||||||
/* Map the nonterminals to their new index: useful first, useless
|
/* Map the nonterminals to their new index: useful first, useless
|
||||||
afterwards. Kept for later report. */
|
afterwards. Kept for later report. */
|
||||||
|
|
||||||
short *nontermmap = XCALLOC (short, nvars) - ntokens;
|
token_number_t *nontermmap = XCALLOC (token_number_t, nvars) - ntokens;
|
||||||
n = ntokens;
|
n = ntokens;
|
||||||
for (i = ntokens; i < nsyms; i++)
|
for (i = ntokens; i < nsyms; i++)
|
||||||
if (bitset_test (V, i))
|
if (bitset_test (V, i))
|
||||||
@@ -308,7 +308,7 @@ nonterminals_reduce (void)
|
|||||||
|
|
||||||
for (i = 0; i < nritems; ++i)
|
for (i = 0; i < nritems; ++i)
|
||||||
if (ISVAR (ritem[i]))
|
if (ISVAR (ritem[i]))
|
||||||
ritem[i] = nontermmap[ritem[i]];
|
ritem[i] = token_number_as_item_number (nontermmap[ritem[i]]);
|
||||||
|
|
||||||
start_symbol = nontermmap[start_symbol];
|
start_symbol = nontermmap[start_symbol];
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ typedef struct state_s
|
|||||||
struct state_s *link;
|
struct state_s *link;
|
||||||
|
|
||||||
short number;
|
short number;
|
||||||
short accessing_symbol;
|
token_number_t accessing_symbol;
|
||||||
shifts *shifts;
|
shifts *shifts;
|
||||||
reductions *reductions;
|
reductions *reductions;
|
||||||
errs *errs;
|
errs *errs;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ symbol_new (const char *tag)
|
|||||||
|
|
||||||
res->tag = xstrdup (tag);
|
res->tag = xstrdup (tag);
|
||||||
res->type_name = NULL;
|
res->type_name = NULL;
|
||||||
res->number = -1;
|
res->number = NUMBER_UNDEFINED;
|
||||||
res->prec = 0;
|
res->prec = 0;
|
||||||
res->assoc = right_assoc;
|
res->assoc = right_assoc;
|
||||||
res->user_token_number = SUNDEF;
|
res->user_token_number = SUNDEF;
|
||||||
|
|||||||
@@ -43,15 +43,19 @@ typedef enum
|
|||||||
|
|
||||||
/* Internal token numbers. */
|
/* Internal token numbers. */
|
||||||
typedef short token_number_t;
|
typedef short token_number_t;
|
||||||
|
|
||||||
#define SUNDEF -1 /* For undefined user number. */
|
#define SUNDEF -1 /* For undefined user number. */
|
||||||
#define SALIAS -9991 /* for symbol generated with an alias */
|
#define SALIAS -9991 /* for symbol generated with an alias */
|
||||||
|
|
||||||
|
#define NUMBER_UNDEFINED ((token_number_t) -1)
|
||||||
|
|
||||||
struct symbol_s
|
struct symbol_s
|
||||||
{
|
{
|
||||||
/* The key, name of the symbol. */
|
/* The key, name of the symbol. */
|
||||||
char *tag;
|
char *tag;
|
||||||
/* Its type. */
|
/* Its type. */
|
||||||
char *type_name;
|
char *type_name;
|
||||||
|
|
||||||
token_number_t number;
|
token_number_t number;
|
||||||
short prec;
|
short prec;
|
||||||
associativity assoc;
|
associativity assoc;
|
||||||
|
|||||||
Reference in New Issue
Block a user