X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/29ae55f112c411438e778ccf2fd3fca8332ca0f2..53c71a12c8bed583886c857a53e6f13f95d9916b:/src/lex.c diff --git a/src/lex.c b/src/lex.c index 489fdf9c..516f7997 100644 --- a/src/lex.c +++ b/src/lex.c @@ -32,12 +32,12 @@ static struct obstack token_obstack; const char *token_buffer = NULL; -bucket *symval = NULL; +symbol_t *symval = NULL; int numval; /* A token to be reread, see unlex and lex. */ static token_t unlexed = tok_undef; -static bucket *unlexed_symval = NULL; +static symbol_t *unlexed_symval = NULL; static const char *unlexed_token_buffer = NULL; void @@ -364,9 +364,13 @@ lex (void) obstack_1grow (&token_obstack, '\0'); token_buffer = obstack_finish (&token_obstack); symval = getsym (token_buffer); - symval->class = token_sym; - if (symval->user_token_number == SUNDEF) - symval->user_token_number = code; + if (symval->number == NUMBER_UNDEFINED) + { + symval->number = ntokens++; + symval->class = token_sym; + if (symval->user_token_number == SUNDEF) + symval->user_token_number = code; + } return tok_identifier; } @@ -388,7 +392,11 @@ lex (void) token_buffer = obstack_finish (&token_obstack); symval = getsym (token_buffer); - symval->class = token_sym; + if (symval->number == NUMBER_UNDEFINED) + { + symval->number = ntokens++; + symval->class = token_sym; + } return tok_identifier; } @@ -485,44 +493,40 @@ parse_percent_token (void) obstack_1grow (&token_obstack, '%'); obstack_1grow (&token_obstack, c); - switch (c) + if (!isalpha (c)) { - case '%': + obstack_1grow (&token_obstack, '\0'); token_buffer = obstack_finish (&token_obstack); - return tok_two_percents; - case '{': - token_buffer = obstack_finish (&token_obstack); - return tok_percent_left_curly; + switch (c) + { + case '%': + return tok_two_percents; - /* The following guys are here for backward compatibility with - very ancient Yacc versions. The paper of Johnson mentions - them (as ancient :). */ - case '<': - token_buffer = obstack_finish (&token_obstack); - return tok_left; + case '{': + return tok_percent_left_curly; - case '>': - token_buffer = obstack_finish (&token_obstack); - return tok_right; + /* The following guys are here for backward compatibility with + very ancient Yacc versions. The paper of Johnson mentions + them (as ancient :). */ + case '<': + return tok_left; - case '2': - token_buffer = obstack_finish (&token_obstack); - return tok_nonassoc; + case '>': + return tok_right; - case '0': - token_buffer = obstack_finish (&token_obstack); - return tok_token; + case '2': + return tok_nonassoc; - case '=': - token_buffer = obstack_finish (&token_obstack); - return tok_prec; - } + case '0': + return tok_token; - if (!isalpha (c)) - { - token_buffer = obstack_finish (&token_obstack); - return tok_illegal; + case '=': + return tok_prec; + + default: + return tok_illegal; + } } while (c = getc (finput), isalpha (c) || c == '_' || c == '-')