* src/lex.h: Rename all the tokens:

s/bENDFILEb/tok_eof/g;
s/bIDENTIFIERb/tok_identifier/g;
etc.
Let them be enums, not #define, to ease debugging.
Adjust all the code.
This commit is contained in:
Akim Demaille
2001-01-19 18:10:32 +00:00
parent 0d6508efab
commit 511e79b3d4
17 changed files with 406 additions and 395 deletions

116
src/lex.c
View File

@@ -355,7 +355,7 @@ read_type_name (FILE *fin)
}
int
token_t
lex (void)
{
int c;
@@ -378,7 +378,7 @@ lex (void)
{
case EOF:
strcpy (token_buffer, "EOF");
return ENDFILE;
return tok_eof;
case 'A': case 'B': case 'C': case 'D': case 'E':
case 'F': case 'G': case 'H': case 'I': case 'J':
@@ -407,7 +407,7 @@ lex (void)
*p = 0;
ungetc (c, finput);
symval = getsym (token_buffer);
return IDENTIFIER;
return tok_identifier;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
@@ -426,7 +426,7 @@ lex (void)
}
*p = 0;
ungetc (c, finput);
return NUMBER;
return tok_number;
}
case '\'':
@@ -458,7 +458,7 @@ lex (void)
symval->class = token_sym;
if (!symval->user_token_number)
symval->user_token_number = code;
return IDENTIFIER;
return tok_identifier;
}
case '\"':
@@ -480,23 +480,23 @@ lex (void)
symval = getsym (token_buffer);
symval->class = token_sym;
return IDENTIFIER;
return tok_identifier;
}
case ',':
return COMMA;
return tok_comma;
case ':':
return COLON;
return tok_colon;
case ';':
return SEMICOLON;
return tok_semicolon;
case '|':
return BAR;
return tok_bar;
case '{':
return LEFT_CURLY;
return tok_left_curly;
case '=':
do
@@ -510,23 +510,23 @@ lex (void)
if (c == '{')
{
strcpy (token_buffer, "={");
return LEFT_CURLY;
return tok_left_curly;
}
else
{
ungetc (c, finput);
return ILLEGAL;
return tok_illegal;
}
case '<':
read_type_name (finput);
return TYPENAME;
return tok_typename;
case '%':
return parse_percent_token ();
default:
return ILLEGAL;
return tok_illegal;
}
}
@@ -542,44 +542,44 @@ struct percent_table_struct
struct percent_table_struct percent_table[] =
{
{ "token", NULL, TOKEN },
{ "term", NULL, TOKEN },
{ "nterm", NULL, NTERM },
{ "type", NULL, TYPE },
{ "guard", NULL, GUARD },
{ "union", NULL, UNION },
{ "expect", NULL, EXPECT },
{ "thong", NULL, THONG },
{ "start", NULL, START },
{ "left", NULL, LEFT },
{ "right", NULL, RIGHT },
{ "nonassoc", NULL, NONASSOC },
{ "binary", NULL, NONASSOC },
{ "prec", NULL, PREC },
{ "locations", &locations_flag, NOOP }, /* -l */
{ "no_lines", &no_lines_flag, NOOP }, /* -l */
{ "raw", &raw_flag, NOOP }, /* -r */
{ "token_table", &token_table_flag, NOOP }, /* -k */
{ "yacc", &yacc_flag, NOOP }, /* -y */
{ "fixed_output_files",&yacc_flag, NOOP }, /* -y */
{ "defines", &defines_flag, NOOP }, /* -d */
{ "no_parser", &no_parser_flag, NOOP }, /* -n */
{ "token", NULL, tok_token },
{ "term", NULL, tok_token },
{ "nterm", NULL, tok_nterm },
{ "type", NULL, tok_type },
{ "guard", NULL, tok_guard },
{ "union", NULL, tok_union },
{ "expect", NULL, tok_expect },
{ "thong", NULL, tok_thong },
{ "start", NULL, tok_start },
{ "left", NULL, tok_left },
{ "right", NULL, tok_right },
{ "nonassoc", NULL, tok_nonassoc },
{ "binary", NULL, tok_nonassoc },
{ "prec", NULL, tok_prec },
{ "locations", &locations_flag, tok_noop }, /* -l */
{ "no_lines", &no_lines_flag, tok_noop }, /* -l */
{ "raw", &raw_flag, tok_noop }, /* -r */
{ "token_table", &token_table_flag, tok_noop }, /* -k */
{ "yacc", &yacc_flag, tok_noop }, /* -y */
{ "fixed_output_files",&yacc_flag, tok_noop }, /* -y */
{ "defines", &defines_flag, tok_noop }, /* -d */
{ "no_parser", &no_parser_flag, tok_noop }, /* -n */
#if 0
/* For the time being, this is not enabled yet, while it's possible
though, since we use obstacks. The only risk is with semantic
parsers which will output an `include' of an output file: be sure
that the naem included is indeed the name of the output file. */
{ "output_file", &spec_outfile, SETOPT }, /* -o */
{ "file_prefix", &spec_file_prefix, SETOPT }, /* -b */
{ "name_prefix", &spec_name_prefix, SETOPT }, /* -p */
{ "output_file", &spec_outfile, tok_setopt }, /* -o */
{ "file_prefix", &spec_file_prefix, tok_setopt }, /* -b */
{ "name_prefix", &spec_name_prefix, tok_setopt }, /* -p */
#endif
{ "verbose", &verbose_flag, NOOP }, /* -v */
{ "debug", &debug_flag, NOOP }, /* -t */
{ "semantic_parser", &semantic_parser, NOOP },
{ "pure_parser", &pure_parser, NOOP },
/* {"help", <print usage stmt>, NOOP}, *//* -h */
/* {"version", <print version number> , NOOP}, *//* -V */
{ NULL, NULL, ILLEGAL}
{ "verbose", &verbose_flag, tok_noop }, /* -v */
{ "debug", &debug_flag, tok_noop }, /* -t */
{ "semantic_parser", &semantic_parser, tok_noop },
{ "pure_parser", &pure_parser, tok_noop },
/* {"help", <print usage stmt>, tok_noop}, *//* -h */
/* {"version", <print version number> , tok_noop}, *//* -V */
{ NULL, NULL, tok_illegal}
};
/* Parse a token which starts with %.
@@ -601,28 +601,28 @@ parse_percent_token (void)
switch (c)
{
case '%':
return TWO_PERCENTS;
return tok_two_percents;
case '{':
return PERCENT_LEFT_CURLY;
return tok_percent_left_curly;
case '<':
return LEFT;
return tok_left;
case '>':
return RIGHT;
return tok_right;
case '2':
return NONASSOC;
return tok_nonassoc;
case '0':
return TOKEN;
return tok_token;
case '=':
return PREC;
return tok_prec;
}
if (!isalpha (c))
return ILLEGAL;
return tok_illegal;
p = token_buffer;
*p++ = '%';
@@ -646,15 +646,15 @@ parse_percent_token (void)
if (strcmp (token_buffer + 1, tx->name) == 0)
break;
if (tx->retval == SETOPT)
if (tx->retval == tok_setopt)
{
*((char **) (tx->set_flag)) = optarg;
return NOOP;
return tok_noop;
}
if (tx->set_flag)
{
*((int *) (tx->set_flag)) = 1;
return NOOP;
return tok_noop;
}
return tx->retval;
}

View File

@@ -22,33 +22,35 @@
# define LEX_H_
/* Token-type codes. */
# define ENDFILE 0
# define IDENTIFIER 1
# define COMMA 2
# define COLON 3
# define SEMICOLON 4
# define BAR 5
# define LEFT_CURLY 6
# define TWO_PERCENTS 7
# define PERCENT_LEFT_CURLY 8
# define TOKEN 9
# define NTERM 10
# define GUARD 11
# define TYPE 12
# define UNION 13
# define START 14
# define LEFT 15
# define RIGHT 16
# define NONASSOC 17
# define PREC 18
# define TYPENAME 21
# define NUMBER 22
# define EXPECT 23
# define THONG 24
# define NOOP 25
# define SETOPT 26
# define ILLEGAL 27
typedef enum token_e
{
tok_eof,
tok_identifier,
tok_comma,
tok_colon,
tok_semicolon,
tok_bar,
tok_left_curly,
tok_two_percents,
tok_percent_left_curly,
tok_token,
tok_nterm,
tok_guard,
tok_type,
tok_union,
tok_start,
tok_left,
tok_right,
tok_nonassoc,
tok_prec,
tok_typename,
tok_number,
tok_expect,
tok_thong,
tok_noop,
tok_setopt,
tok_illegal
} token_t;
extern char *token_buffer;
extern bucket *symval;
@@ -64,7 +66,7 @@ void read_type_name PARAMS ((FILE *fin));
symbol table using symtab.c; symval is set to a pointer to the
entry found. */
int lex PARAMS ((void));
token_t lex PARAMS ((void));
int parse_percent_token PARAMS ((void));

View File

@@ -486,18 +486,18 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not)
fatal (_("Premature EOF after %s"), token_buffer);
token = lex ();
if (token == COMMA)
if (token == tok_comma)
{
symbol = NULL;
continue;
}
if (token == TYPENAME)
if (token == tok_typename)
{
typename = xstrdup (token_buffer);
value_components_used = 1;
symbol = NULL;
}
else if (token == IDENTIFIER && *symval->tag == '\"' && symbol)
else if (token == tok_identifier && *symval->tag == '\"' && symbol)
{
if (symval->alias)
warn (_("symbol `%s' used more than once as a literal string"),
@@ -519,7 +519,7 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not)
translations = 1;
symbol = NULL;
}
else if (token == IDENTIFIER)
else if (token == tok_identifier)
{
int oldclass = symval->class;
symbol = symval;
@@ -538,7 +538,7 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not)
complain (_("type redeclaration for %s"), symbol->tag);
}
}
else if (symbol && token == NUMBER)
else if (symbol && token == tok_number)
{
symbol->user_token_number = numval;
translations = 1;
@@ -563,7 +563,7 @@ parse_start_decl (void)
{
if (start_flag)
complain (_("multiple %s declarations"), "%start");
if (lex () != IDENTIFIER)
if (lex () != tok_identifier)
complain (_("invalid %s declaration"), "%start");
else
{
@@ -582,7 +582,7 @@ parse_type_decl (void)
{
char *name;
if (lex () != TYPENAME)
if (lex () != tok_typename)
{
complain ("%s", _("%type declaration has no <typename>"));
skip_to_char ('%');
@@ -606,11 +606,11 @@ parse_type_decl (void)
switch (t)
{
case COMMA:
case SEMICOLON:
case tok_comma:
case tok_semicolon:
break;
case IDENTIFIER:
case tok_identifier:
if (symval->type_name == NULL)
symval->type_name = name;
else if (strcmp (name, symval->type_name) != 0)
@@ -655,14 +655,14 @@ parse_assoc_decl (associativity assoc)
switch (t)
{
case TYPENAME:
case tok_typename:
name = xstrdup (token_buffer);
break;
case COMMA:
case tok_comma:
break;
case IDENTIFIER:
case tok_identifier:
if (symval->prec != 0)
complain (_("redefining precedence of %s"), symval->tag);
symval->prec = lastprec;
@@ -679,8 +679,8 @@ parse_assoc_decl (associativity assoc)
}
break;
case NUMBER:
if (prev == IDENTIFIER)
case tok_number:
if (prev == tok_identifier)
{
symval->user_token_number = numval;
translations = 1;
@@ -694,7 +694,7 @@ token_buffer);
}
break;
case SEMICOLON:
case tok_semicolon:
return;
default:
@@ -828,7 +828,7 @@ parse_thong_decl (void)
translations = 1;
token = lex (); /* fetch typename or first token */
if (token == TYPENAME)
if (token == tok_typename)
{
typename = xstrdup (token_buffer);
value_components_used = 1;
@@ -837,7 +837,7 @@ parse_thong_decl (void)
/* process first token */
if (token != IDENTIFIER)
if (token != tok_identifier)
{
complain (_("unrecognized item %s, expected an identifier"),
token_buffer);
@@ -851,7 +851,7 @@ parse_thong_decl (void)
token = lex (); /* get number or literal string */
if (token == NUMBER)
if (token == tok_number)
{
usrtoknum = numval;
token = lex (); /* okay, did number, now get literal */
@@ -861,7 +861,7 @@ parse_thong_decl (void)
/* process literal string token */
if (token != IDENTIFIER || *symval->tag != '\"')
if (token != tok_identifier || *symval->tag != '\"')
{
complain (_("expected string constant instead of %s"), token_buffer);
skip_to_char ('%');
@@ -901,54 +901,54 @@ read_declarations (void)
switch (tok)
{
case TWO_PERCENTS:
case tok_two_percents:
return;
case PERCENT_LEFT_CURLY:
case tok_percent_left_curly:
copy_definition ();
break;
case TOKEN:
case tok_token:
parse_token_decl (token_sym, nterm_sym);
break;
case NTERM:
case tok_nterm:
parse_token_decl (nterm_sym, token_sym);
break;
case TYPE:
case tok_type:
parse_type_decl ();
break;
case START:
case tok_start:
parse_start_decl ();
break;
case UNION:
case tok_union:
parse_union_decl ();
break;
case EXPECT:
case tok_expect:
parse_expect_decl ();
break;
case THONG:
case tok_thong:
parse_thong_decl ();
break;
case LEFT:
case tok_left:
parse_assoc_decl (left_assoc);
break;
case RIGHT:
case tok_right:
parse_assoc_decl (right_assoc);
break;
case NONASSOC:
case tok_nonassoc:
parse_assoc_decl (non_assoc);
break;
case NOOP:
case tok_noop:
break;
default:
@@ -1203,7 +1203,7 @@ get_type (void)
t = lex ();
if (t != TYPENAME)
if (t != tok_typename)
{
complain (_("invalid %s declaration"), "%type");
return t;
@@ -1217,13 +1217,13 @@ get_type (void)
switch (t)
{
case SEMICOLON:
case tok_semicolon:
return lex ();
case COMMA:
case tok_comma:
break;
case IDENTIFIER:
case tok_identifier:
if (symval->type_name == NULL)
symval->type_name = name;
else if (strcmp (name, symval->type_name) != 0)
@@ -1269,9 +1269,9 @@ readgram (void)
t = lex ();
while (t != TWO_PERCENTS && t != ENDFILE)
while (t != tok_two_percents && t != tok_eof)
{
if (t == IDENTIFIER || t == BAR)
if (t == tok_identifier || t == tok_bar)
{
int action_flag = 0;
/* Number of symbols in rhs of this rule so far */
@@ -1279,7 +1279,7 @@ readgram (void)
int xactions = 0; /* JF for error checking */
bucket *first_rhs = 0;
if (t == IDENTIFIER)
if (t == tok_identifier)
{
lhs = symval;
@@ -1290,14 +1290,14 @@ readgram (void)
}
t = lex ();
if (t != COLON)
if (t != tok_colon)
{
complain (_("ill-formed rule: initial symbol not followed by colon"));
unlex (t);
}
}
if (nrules == 0 && t == BAR)
if (nrules == 0 && t == tok_bar)
{
complain (_("grammar starts with vertical bar"));
lhs = symval; /* BOGUS: use a random symval */
@@ -1337,19 +1337,19 @@ readgram (void)
for (;;)
{
t = lex ();
if (t == PREC)
if (t == tok_prec)
{
t = lex ();
crule->ruleprec = symval;
t = lex ();
}
if (!(t == IDENTIFIER || t == LEFT_CURLY))
if (!(t == tok_identifier || t == tok_left_curly))
break;
/* If next token is an identifier, see if a colon follows it.
If one does, exit this rule now. */
if (t == IDENTIFIER)
if (t == tok_identifier)
{
bucket *ssave;
int t1;
@@ -1358,7 +1358,7 @@ readgram (void)
t1 = lex ();
unlex (t1);
symval = ssave;
if (t1 == COLON)
if (t1 == tok_colon)
break;
if (!first_rhs) /* JF */
@@ -1408,7 +1408,7 @@ readgram (void)
action_flag = 0;
}
if (t == IDENTIFIER)
if (t == tok_identifier)
{
nitems++;
p = XCALLOC (symbol_list, 1);
@@ -1430,14 +1430,14 @@ readgram (void)
p1->next = p;
p1 = p;
if (t == PREC)
if (t == tok_prec)
{
complain (_("two @prec's in a row"));
t = lex ();
crule->ruleprec = symval;
t = lex ();
}
if (t == GUARD)
if (t == tok_guard)
{
if (!semantic_parser)
complain (_("%%guard present but %%semantic_parser not specified"));
@@ -1445,7 +1445,7 @@ readgram (void)
copy_guard (crule, rulelength);
t = lex ();
}
else if (t == LEFT_CURLY)
else if (t == tok_left_curly)
{
/* This case never occurs -wjh */
if (action_flag)
@@ -1470,7 +1470,7 @@ readgram (void)
/* Warn if there is no default for $$ but we need one. */
else if (!xactions && !first_rhs && lhs->type_name != 0)
complain (_("empty rule for typed nonterminal, and no action"));
if (t == SEMICOLON)
if (t == tok_semicolon)
t = lex ();
}
#if 0
@@ -1480,31 +1480,31 @@ readgram (void)
b) most of them scan forward until finding a next %
thus they may swallow lots of intervening rules
*/
else if (t == TOKEN)
else if (t == tok_token)
{
parse_token_decl (token_sym, nterm_sym);
t = lex ();
}
else if (t == NTERM)
else if (t == tok_nterm)
{
parse_token_decl (nterm_sym, token_sym);
t = lex ();
}
else if (t == TYPE)
else if (t == tok_type)
{
t = get_type ();
}
else if (t == UNION)
else if (t == tok_union)
{
parse_union_decl ();
t = lex ();
}
else if (t == EXPECT)
else if (t == tok_expect)
{
parse_expect_decl ();
t = lex ();
}
else if (t == START)
else if (t == tok_start)
{
parse_start_decl ();
t = lex ();