mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
* src/reader.c (gensym): Rename as...
* src/symtab.h, src/symtab.c (dummy_symbol_get): this. (getsym): Rename as... (symbol_get): this.
This commit is contained in:
@@ -236,7 +236,7 @@ typedef union {
|
||||
char *string;
|
||||
associativity assoc;
|
||||
} yystype;
|
||||
/* Line 272 of /home/lrde/prof/akim/src/bison/data/yacc.c. */
|
||||
/* Line 272 of /usr/local/share/bison/yacc.c. */
|
||||
#line 241 "parse-gram.c"
|
||||
# define YYSTYPE yystype
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
@@ -257,7 +257,7 @@ typedef struct yyltype
|
||||
/* Copy the second part of user declarations. */
|
||||
|
||||
|
||||
/* Line 292 of /home/lrde/prof/akim/src/bison/data/yacc.c. */
|
||||
/* Line 292 of /usr/local/share/bison/yacc.c. */
|
||||
#line 262 "parse-gram.c"
|
||||
|
||||
#if ! defined (yyoverflow) || YYERROR_VERBOSE
|
||||
@@ -1479,7 +1479,7 @@ yyreduce:
|
||||
|
||||
case 67:
|
||||
#line 371 "parse-gram.y"
|
||||
{ yyval.symbol = getsym (yyvsp[0].string, yylsp[0]); }
|
||||
{ yyval.symbol = symbol_get (yyvsp[0].string, yylsp[0]); }
|
||||
break;
|
||||
|
||||
case 68:
|
||||
@@ -1490,7 +1490,7 @@ yyreduce:
|
||||
case 69:
|
||||
#line 382 "parse-gram.y"
|
||||
{
|
||||
yyval.symbol = getsym (yyvsp[0].string, yylsp[0]);
|
||||
yyval.symbol = symbol_get (yyvsp[0].string, yylsp[0]);
|
||||
symbol_class_set (yyval.symbol, token_sym, yylsp[0]);
|
||||
}
|
||||
break;
|
||||
@@ -1520,7 +1520,7 @@ yyreduce:
|
||||
|
||||
}
|
||||
|
||||
/* Line 1040 of /home/lrde/prof/akim/src/bison/data/yacc.c. */
|
||||
/* Line 1040 of /usr/local/share/bison/yacc.c. */
|
||||
#line 1525 "parse-gram.c"
|
||||
|
||||
yyvsp -= yylen;
|
||||
|
||||
@@ -111,7 +111,7 @@ typedef union {
|
||||
char *string;
|
||||
associativity assoc;
|
||||
} yystype;
|
||||
/* Line 1353 of /home/lrde/prof/akim/src/bison/data/yacc.c. */
|
||||
/* Line 1353 of /usr/local/share/bison/yacc.c. */
|
||||
#line 116 "y.tab.h"
|
||||
# define YYSTYPE yystype
|
||||
#endif
|
||||
|
||||
@@ -368,7 +368,7 @@ rhs:
|
||||
symbol:
|
||||
ID { $$ = $1; }
|
||||
| string_as_id { $$ = $1; }
|
||||
| CHARACTER { $$ = getsym ($1, @1); }
|
||||
| CHARACTER { $$ = symbol_get ($1, @1); }
|
||||
;
|
||||
|
||||
action:
|
||||
@@ -380,7 +380,7 @@ action:
|
||||
string_as_id:
|
||||
STRING
|
||||
{
|
||||
$$ = getsym ($1, @1);
|
||||
$$ = symbol_get ($1, @1);
|
||||
symbol_class_set ($$, token_sym, @1);
|
||||
}
|
||||
;
|
||||
|
||||
40
src/reader.c
40
src/reader.c
@@ -126,7 +126,7 @@ get_merge_function (const char* name, const char* type)
|
||||
type = "";
|
||||
|
||||
head.next = merge_functions;
|
||||
for (syms = &head, n = 1; syms->next != NULL; syms = syms->next, n += 1)
|
||||
for (syms = &head, n = 1; syms->next != NULL; syms = syms->next, n += 1)
|
||||
if (strcmp (name, syms->next->name) == 0)
|
||||
break;
|
||||
if (syms->next == NULL) {
|
||||
@@ -136,7 +136,7 @@ get_merge_function (const char* name, const char* type)
|
||||
syms->next->next = NULL;
|
||||
merge_functions = head.next;
|
||||
} else if (strcmp (type, syms->next->type) != 0)
|
||||
warn (_("result type clash on merge function %s: `%s' vs. `%s'"),
|
||||
warn (_("result type clash on merge function %s: `%s' vs. `%s'"),
|
||||
name, type, syms->next->type);
|
||||
return n;
|
||||
}
|
||||
@@ -160,26 +160,6 @@ free_merger_functions (void)
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------.
|
||||
| Generate a dummy symbol, a nonterminal, whose name cannot conflict |
|
||||
| with the user's names. |
|
||||
`-------------------------------------------------------------------*/
|
||||
|
||||
static symbol_t *
|
||||
gensym (location_t location)
|
||||
{
|
||||
/* Incremented for each generated symbol */
|
||||
static int gensym_count = 0;
|
||||
static char buf[256];
|
||||
|
||||
symbol_t *sym;
|
||||
|
||||
sprintf (buf, "@%d", ++gensym_count);
|
||||
sym = getsym (buf, location);
|
||||
sym->class = nterm_sym;
|
||||
sym->number = nvars++;
|
||||
return sym;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------.
|
||||
| Parse the input grammar into a one symbol_list_t structure. Each |
|
||||
@@ -323,7 +303,7 @@ grammar_midrule_action (void)
|
||||
/* Make a DUMMY nonterminal, whose location is that of the midrule
|
||||
action. Create the MIDRULE. */
|
||||
location_t dummy_location = current_rule->action_location;
|
||||
symbol_t *dummy = gensym (dummy_location);
|
||||
symbol_t *dummy = dummy_symbol_get (dummy_location);
|
||||
symbol_list_t *midrule = symbol_list_new (dummy, dummy_location);
|
||||
|
||||
/* Make a new rule, whose body is empty, before the current one, so
|
||||
@@ -371,7 +351,7 @@ grammar_current_rule_dprec_set (int dprec, location_t location)
|
||||
warn_at (location, _("%%dprec affects only GLR parsers"));
|
||||
if (dprec <= 0)
|
||||
complain_at (location, _("%%dprec must be followed by positive number"));
|
||||
else if (current_rule->dprec != 0)
|
||||
else if (current_rule->dprec != 0)
|
||||
complain_at (location, _("only one %%dprec allowed per rule"));
|
||||
current_rule->dprec = dprec;
|
||||
}
|
||||
@@ -384,9 +364,9 @@ grammar_current_rule_merge_set (const char* name, location_t location)
|
||||
{
|
||||
if (! glr_parser)
|
||||
warn_at (location, _("%%merge affects only GLR parsers"));
|
||||
if (current_rule->merger != 0)
|
||||
if (current_rule->merger != 0)
|
||||
complain_at (location, _("only one %%merge allowed per rule"));
|
||||
current_rule->merger =
|
||||
current_rule->merger =
|
||||
get_merge_function (name, current_rule->sym->type_name);
|
||||
}
|
||||
|
||||
@@ -499,18 +479,18 @@ reader (void)
|
||||
symbols_new ();
|
||||
|
||||
/* Construct the axiom symbol. */
|
||||
axiom = getsym ("$axiom", empty_location);
|
||||
axiom = symbol_get ("$axiom", empty_location);
|
||||
axiom->class = nterm_sym;
|
||||
axiom->number = nvars++;
|
||||
|
||||
/* Construct the error token */
|
||||
errtoken = getsym ("error", empty_location);
|
||||
errtoken = symbol_get ("error", empty_location);
|
||||
errtoken->class = token_sym;
|
||||
errtoken->number = ntokens++;
|
||||
|
||||
/* Construct a token that represents all undefined literal tokens.
|
||||
It is always token number 2. */
|
||||
undeftoken = getsym ("$undefined.", empty_location);
|
||||
undeftoken = symbol_get ("$undefined.", empty_location);
|
||||
undeftoken->class = token_sym;
|
||||
undeftoken->number = ntokens++;
|
||||
|
||||
@@ -536,7 +516,7 @@ reader (void)
|
||||
/* If the user did not define her EOFTOKEN, do it now. */
|
||||
if (!eoftoken)
|
||||
{
|
||||
eoftoken = getsym ("$", empty_location);
|
||||
eoftoken = symbol_get ("$", empty_location);
|
||||
eoftoken->class = token_sym;
|
||||
eoftoken->number = 0;
|
||||
/* Value specified by POSIX. */
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#define yyrestart gram_restart
|
||||
#define yytext gram_text
|
||||
|
||||
#line 19 "scan-gram.c"
|
||||
#line 19 "lex.yy.c"
|
||||
/* A lexical scanner generated by flex */
|
||||
|
||||
/* Scanner skeleton version:
|
||||
@@ -27,7 +27,7 @@
|
||||
#define YY_FLEX_MINOR_VERSION 5
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
|
||||
#ifdef c_plusplus
|
||||
@@ -40,7 +40,9 @@
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <stdlib.h>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
/* Use prototypes in function declarations. */
|
||||
#define YY_USE_PROTOS
|
||||
@@ -823,7 +825,7 @@ static void handle_at PARAMS ((braced_code_t code_kind,
|
||||
#define SC_PROLOGUE 7
|
||||
#define SC_EPILOGUE 8
|
||||
|
||||
#line 827 "scan-gram.c"
|
||||
#line 829 "lex.yy.c"
|
||||
|
||||
/* Macros after this point can all be overridden by user definitions in
|
||||
* section 1.
|
||||
@@ -923,9 +925,20 @@ YY_MALLOC_DECL
|
||||
YY_FATAL_ERROR( "input in flex scanner failed" ); \
|
||||
result = n; \
|
||||
} \
|
||||
else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \
|
||||
&& ferror( yyin ) ) \
|
||||
YY_FATAL_ERROR( "input in flex scanner failed" );
|
||||
else \
|
||||
{ \
|
||||
errno=0; \
|
||||
while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
|
||||
{ \
|
||||
if( errno != EINTR) \
|
||||
{ \
|
||||
YY_FATAL_ERROR( "input in flex scanner failed" ); \
|
||||
break; \
|
||||
} \
|
||||
errno=0; \
|
||||
clearerr(yyin); \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
/* No semi-colon after return; correct usage is to write "yyterminate();" -
|
||||
@@ -997,7 +1010,7 @@ YY_DECL
|
||||
/*----------------------------.
|
||||
| Scanning Bison directives. |
|
||||
`----------------------------*/
|
||||
#line 1001 "scan-gram.c"
|
||||
#line 1014 "lex.yy.c"
|
||||
|
||||
if ( yy_init )
|
||||
{
|
||||
@@ -1291,7 +1304,7 @@ case 39:
|
||||
YY_RULE_SETUP
|
||||
#line 162 "scan-gram.l"
|
||||
{
|
||||
yylval->symbol = getsym (yytext, *yylloc);
|
||||
yylval->symbol = symbol_get (yytext, *yylloc);
|
||||
return ID;
|
||||
}
|
||||
YY_BREAK
|
||||
@@ -1482,7 +1495,7 @@ YY_RULE_SETUP
|
||||
assert (yy_top_state () == INITIAL);
|
||||
{
|
||||
YY_OBS_FINISH;
|
||||
yylval->symbol = getsym (last_string, *yylloc);
|
||||
yylval->symbol = symbol_get (last_string, *yylloc);
|
||||
symbol_class_set (yylval->symbol, token_sym, *yylloc);
|
||||
symbol_user_token_number_set (yylval->symbol, last_string[1], *yylloc);
|
||||
YY_OBS_FREE;
|
||||
@@ -1857,7 +1870,7 @@ YY_RULE_SETUP
|
||||
#line 528 "scan-gram.l"
|
||||
YY_FATAL_ERROR( "flex scanner jammed" );
|
||||
YY_BREAK
|
||||
#line 1861 "scan-gram.c"
|
||||
#line 1874 "lex.yy.c"
|
||||
case YY_STATE_EOF(INITIAL):
|
||||
yyterminate();
|
||||
|
||||
@@ -2421,11 +2434,15 @@ YY_BUFFER_STATE b;
|
||||
}
|
||||
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#ifndef YY_ALWAYS_INTERACTIVE
|
||||
#ifndef YY_NEVER_INTERACTIVE
|
||||
extern int isatty YY_PROTO(( int ));
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef YY_USE_PROTOS
|
||||
void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
|
||||
|
||||
@@ -160,7 +160,7 @@ blanks [ \t\f]+
|
||||
{eols} YY_LINES; YY_STEP;
|
||||
{blanks} YY_STEP;
|
||||
{id} {
|
||||
yylval->symbol = getsym (yytext, *yylloc);
|
||||
yylval->symbol = symbol_get (yytext, *yylloc);
|
||||
return ID;
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ blanks [ \t\f]+
|
||||
assert (yy_top_state () == INITIAL);
|
||||
{
|
||||
YY_OBS_FINISH;
|
||||
yylval->symbol = getsym (last_string, *yylloc);
|
||||
yylval->symbol = symbol_get (last_string, *yylloc);
|
||||
symbol_class_set (yylval->symbol, token_sym, *yylloc);
|
||||
symbol_user_token_number_set (yylval->symbol, last_string[1], *yylloc);
|
||||
YY_OBS_FREE;
|
||||
|
||||
24
src/symtab.c
24
src/symtab.c
@@ -447,7 +447,7 @@ symbols_new (void)
|
||||
`----------------------------------------------------------------*/
|
||||
|
||||
symbol_t *
|
||||
getsym (const char *key, location_t location)
|
||||
symbol_get (const char *key, location_t location)
|
||||
{
|
||||
symbol_t probe;
|
||||
symbol_t *entry;
|
||||
@@ -465,6 +465,28 @@ getsym (const char *key, location_t location)
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------.
|
||||
| Generate a dummy nonterminal, whose name cannot conflict with the |
|
||||
| user's names. |
|
||||
`------------------------------------------------------------------*/
|
||||
|
||||
symbol_t *
|
||||
dummy_symbol_get (location_t location)
|
||||
{
|
||||
/* Incremented for each generated symbol. */
|
||||
static int dummy_count = 0;
|
||||
static char buf[256];
|
||||
|
||||
symbol_t *sym;
|
||||
|
||||
sprintf (buf, "@%d", ++dummy_count);
|
||||
sym = symbol_get (buf, location);
|
||||
sym->class = nterm_sym;
|
||||
sym->number = nvars++;
|
||||
return sym;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------.
|
||||
| Free the symbols. |
|
||||
`-------------------*/
|
||||
|
||||
@@ -103,7 +103,11 @@ const char *symbol_tag_get_n PARAMS ((symbol_t *symbol, int n));
|
||||
void symbol_tag_print PARAMS ((symbol_t *symbol, FILE *out));
|
||||
|
||||
/* Fetch (or create) the symbol associated to KEY. */
|
||||
symbol_t *getsym PARAMS ((const char *key, location_t location));
|
||||
symbol_t *symbol_get PARAMS ((const char *key, location_t location));
|
||||
|
||||
/* Generate a dummy nonterminal, whose name cannot conflict with the
|
||||
user's names. */
|
||||
symbol_t *dummy_symbol_get PARAMS ((location_t location));
|
||||
|
||||
/* Declare the new SYMBOL. Make it an alias of SYMVAL. */
|
||||
void symbol_make_alias PARAMS ((symbol_t *symbol, symbol_t *symval));
|
||||
|
||||
Reference in New Issue
Block a user