Define the "identifier" of a symbol.

Symbols may have several string representations, for instance if they
have an alias.  What I call its "id" is a string that can be used as
an identifier.  May not exist.

Currently the symbols which have the "tag_is_id" flag set are those that
don't have an alias.  Look harder for the id.

	* src/output.c (is_identifier): Move to...
	* src/symtab.c (is_identifier): here.
	* src/symtab.h, src/symtab.c (symbol_id_get): New.
	* src/output.c (symbol_definitions_output): Use it to define "id"
	and "has_id".
	Remove the definition of "tag_is_id".
	* data/lalr1.cc: Use the "id" and "has_id" whereever "tag" and
	"tag_is_id" were used to produce code.
	We still use "tag" for documentation.
This commit is contained in:
Akim Demaille
2008-08-26 20:10:03 +02:00
parent 086fd1137d
commit aea10ef46f
5 changed files with 90 additions and 33 deletions

View File

@@ -396,26 +396,6 @@ merger_output (FILE *out)
}
/*----------------------------------.
| Whether S is a valid identifier. |
`----------------------------------*/
static bool
is_identifier (uniqstr s)
{
static char const alphanum[26 + 26 + 1 + 10] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"_"
"0123456789";
if (!s || ! memchr (alphanum, *s, sizeof alphanum - 10))
return false;
for (++s; *s; ++s)
if (! memchr (alphanum, *s, sizeof alphanum))
return false;
return true;
}
/*---------------------------------------.
| Output the symbol definitions to OUT. |
`---------------------------------------*/
@@ -428,17 +408,23 @@ symbol_definitions_output (FILE *out)
{
symbol *sym = symbols[i];
const char *key;
const char *value;
#define SET_KEY(Entry) \
obstack_fgrow2 (&format_obstack, "symbol(%d, %s)", i, Entry); \
obstack_1grow (&format_obstack, 0); \
key = obstack_finish (&format_obstack);
// Whether the tag is a valid identifier.
SET_KEY("tag_is_id");
MUSCLE_INSERT_INT (key, is_identifier(sym->tag));
// Whether the symbol has an identifier.
value = symbol_id_get (sym);
SET_KEY("has_id");
MUSCLE_INSERT_INT (key, !!value);
// The inner tag.
// Its identifier.
SET_KEY("id");
MUSCLE_INSERT_STRING (key, value ? value : "");
// Its tag. Typically for documentation purpose.
SET_KEY("tag");
MUSCLE_INSERT_STRING (key, sym->tag);