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