mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
dogfooding: use api.value.type union
* src/parse-gram.y (api.value.type): Set to union. Replace occurrences of %union with explicit %types. * src/scan-gram.l: Adjust yylval's field names. (RETURN_VALUE): No longer needs the Field argument. Use it more.
This commit is contained in:
@@ -97,6 +97,7 @@
|
|||||||
|
|
||||||
%define api.prefix {gram_}
|
%define api.prefix {gram_}
|
||||||
%define api.pure full
|
%define api.pure full
|
||||||
|
%define api.value.type union
|
||||||
%define locations
|
%define locations
|
||||||
%define parse.error verbose
|
%define parse.error verbose
|
||||||
%define parse.lac full
|
%define parse.lac full
|
||||||
@@ -180,16 +181,13 @@
|
|||||||
%token TAG_ANY "<*>"
|
%token TAG_ANY "<*>"
|
||||||
%token TAG_NONE "<>"
|
%token TAG_NONE "<>"
|
||||||
|
|
||||||
%union {unsigned char character;}
|
%type <unsigned char> CHAR
|
||||||
%type <character> CHAR
|
%printer { fputs (char_name ($$), yyo); } <unsigned char>
|
||||||
%printer { fputs (char_name ($$), yyo); } CHAR
|
|
||||||
|
|
||||||
%union {char *code;};
|
%type <char*> "{...}" "%?{...}" "%{...%}" EPILOGUE STRING
|
||||||
%type <code> "{...}" "%?{...}" "%{...%}" EPILOGUE STRING
|
|
||||||
%printer { fputs (quotearg_style (c_quoting_style, $$), yyo); } STRING
|
%printer { fputs (quotearg_style (c_quoting_style, $$), yyo); } STRING
|
||||||
%printer { fprintf (yyo, "{\n%s\n}", $$); } <code>
|
%printer { fprintf (yyo, "{\n%s\n}", $$); } <char*>
|
||||||
|
|
||||||
%union {uniqstr uniqstr;}
|
|
||||||
%type <uniqstr> BRACKETED_ID ID ID_COLON PERCENT_FLAG TAG tag variable
|
%type <uniqstr> BRACKETED_ID ID ID_COLON PERCENT_FLAG TAG tag variable
|
||||||
%printer { fputs ($$, yyo); } <uniqstr>
|
%printer { fputs ($$, yyo); } <uniqstr>
|
||||||
%printer { fprintf (yyo, "[%s]", $$); } BRACKETED_ID
|
%printer { fprintf (yyo, "[%s]", $$); } BRACKETED_ID
|
||||||
@@ -197,23 +195,18 @@
|
|||||||
%printer { fprintf (yyo, "%%%s", $$); } PERCENT_FLAG
|
%printer { fprintf (yyo, "%%%s", $$); } PERCENT_FLAG
|
||||||
%printer { fprintf (yyo, "<%s>", $$); } TAG tag
|
%printer { fprintf (yyo, "<%s>", $$); } TAG tag
|
||||||
|
|
||||||
%union {int integer;};
|
%token <int> INT "integer"
|
||||||
%token <integer> INT "integer"
|
%printer { fprintf (yyo, "%d", $$); } <int>
|
||||||
%printer { fprintf (yyo, "%d", $$); } <integer>
|
|
||||||
|
|
||||||
%union {symbol *symbol;}
|
%type <symbol*> id id_colon string_as_id symbol symbol.prec
|
||||||
%type <symbol> id id_colon string_as_id symbol symbol.prec
|
%printer { fprintf (yyo, "%s", $$->tag); } <symbol*>
|
||||||
%printer { fprintf (yyo, "%s", $$->tag); } <symbol>
|
|
||||||
%printer { fprintf (yyo, "%s:", $$->tag); } id_colon
|
%printer { fprintf (yyo, "%s:", $$->tag); } id_colon
|
||||||
|
|
||||||
%union {assoc assoc;};
|
|
||||||
%type <assoc> precedence_declarator
|
%type <assoc> precedence_declarator
|
||||||
|
|
||||||
%union {symbol_list *list;}
|
%type <symbol_list*> symbols.1 symbols.prec generic_symlist generic_symlist_item
|
||||||
%type <list> symbols.1 symbols.prec generic_symlist generic_symlist_item
|
|
||||||
|
|
||||||
%union {named_ref *named_ref;}
|
%type <named_ref*> named_ref.opt
|
||||||
%type <named_ref> named_ref.opt
|
|
||||||
|
|
||||||
/*---------.
|
/*---------.
|
||||||
| %param. |
|
| %param. |
|
||||||
@@ -239,8 +232,7 @@
|
|||||||
static void add_param (param_type type, char *decl, location loc);
|
static void add_param (param_type type, char *decl, location loc);
|
||||||
static param_type current_param = param_none;
|
static param_type current_param = param_none;
|
||||||
};
|
};
|
||||||
%union {param_type param;}
|
%token <param_type> PERCENT_PARAM "%param";
|
||||||
%token <param> PERCENT_PARAM "%param";
|
|
||||||
%printer
|
%printer
|
||||||
{
|
{
|
||||||
switch ($$)
|
switch ($$)
|
||||||
@@ -253,7 +245,7 @@
|
|||||||
#undef CASE
|
#undef CASE
|
||||||
case param_none: aver (false); break;
|
case param_none: aver (false); break;
|
||||||
}
|
}
|
||||||
} <param>;
|
} <param_type>;
|
||||||
|
|
||||||
|
|
||||||
/*==========\
|
/*==========\
|
||||||
@@ -405,9 +397,8 @@ grammar_declaration:
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
%type <code_type> code_props_type;
|
%type <code_props_type> code_props_type;
|
||||||
%union {code_props_type code_type;};
|
%printer { fprintf (yyo, "%s", code_props_type_string ($$)); } <code_props_type>;
|
||||||
%printer { fprintf (yyo, "%s", code_props_type_string ($$)); } <code_type>;
|
|
||||||
code_props_type:
|
code_props_type:
|
||||||
"%destructor" { $$ = destructor; }
|
"%destructor" { $$ = destructor; }
|
||||||
| "%printer" { $$ = printer; }
|
| "%printer" { $$ = printer; }
|
||||||
@@ -642,16 +633,15 @@ variable:
|
|||||||
;
|
;
|
||||||
|
|
||||||
/* Some content or empty by default. */
|
/* Some content or empty by default. */
|
||||||
%code requires {#include "muscle-tab.h"};
|
%code requires {
|
||||||
%union
|
#include "muscle-tab.h"
|
||||||
{
|
typedef struct
|
||||||
struct
|
|
||||||
{
|
{
|
||||||
char const *chars;
|
char const *chars;
|
||||||
muscle_kind kind;
|
muscle_kind kind;
|
||||||
} value;
|
} value_type;
|
||||||
};
|
};
|
||||||
%type <value> value;
|
%type <value_type> value;
|
||||||
%printer
|
%printer
|
||||||
{
|
{
|
||||||
switch ($$.kind)
|
switch ($$.kind)
|
||||||
@@ -660,7 +650,7 @@ variable:
|
|||||||
case muscle_keyword: fprintf (yyo, "%s", $$.chars); break;
|
case muscle_keyword: fprintf (yyo, "%s", $$.chars); break;
|
||||||
case muscle_string: fprintf (yyo, "\"%s\"", $$.chars); break;
|
case muscle_string: fprintf (yyo, "\"%s\"", $$.chars); break;
|
||||||
}
|
}
|
||||||
} <value>;
|
} <value_type>;
|
||||||
|
|
||||||
value:
|
value:
|
||||||
%empty { $$.kind = muscle_keyword; $$.chars = ""; }
|
%empty { $$.kind = muscle_keyword; $$.chars = ""; }
|
||||||
|
|||||||
@@ -53,15 +53,15 @@ static boundary scanner_cursor;
|
|||||||
static size_t no_cr_read (FILE *, char *, size_t);
|
static size_t no_cr_read (FILE *, char *, size_t);
|
||||||
#define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size))
|
#define YY_INPUT(buf, result, size) ((result) = no_cr_read (yyin, buf, size))
|
||||||
|
|
||||||
#define RETURN_PERCENT_PARAM(Value) \
|
#define RETURN_PERCENT_PARAM(Value) \
|
||||||
RETURN_VALUE(PERCENT_PARAM, param, param_ ## Value)
|
RETURN_VALUE(PERCENT_PARAM, param_ ## Value)
|
||||||
|
|
||||||
#define RETURN_PERCENT_FLAG(Value) \
|
#define RETURN_PERCENT_FLAG(Value) \
|
||||||
RETURN_VALUE(PERCENT_FLAG, uniqstr, uniqstr_new (Value))
|
RETURN_VALUE(PERCENT_FLAG, uniqstr_new (Value))
|
||||||
|
|
||||||
#define RETURN_VALUE(Token, Field, Value) \
|
#define RETURN_VALUE(Token, Value) \
|
||||||
do { \
|
do { \
|
||||||
val->Field = Value; \
|
val->Token = Value; \
|
||||||
return Token; \
|
return Token; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@@ -134,6 +134,7 @@ letter [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
|
|||||||
notletter [^.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]{-}[%\{]
|
notletter [^.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]{-}[%\{]
|
||||||
id {letter}({letter}|[-0-9])*
|
id {letter}({letter}|[-0-9])*
|
||||||
int [0-9]+
|
int [0-9]+
|
||||||
|
xint 0[xX][0-9abcdefABCDEF]+
|
||||||
|
|
||||||
/* Zero or more instances of backslash-newline. Following GCC, allow
|
/* Zero or more instances of backslash-newline. Following GCC, allow
|
||||||
white space between the backslash and the newline. */
|
white space between the backslash and the newline. */
|
||||||
@@ -281,20 +282,14 @@ eqopt ([[:space:]]*=)?
|
|||||||
";" return SEMICOLON;
|
";" return SEMICOLON;
|
||||||
|
|
||||||
{id} {
|
{id} {
|
||||||
val->uniqstr = uniqstr_new (yytext);
|
val->ID = uniqstr_new (yytext);
|
||||||
id_loc = *loc;
|
id_loc = *loc;
|
||||||
bracketed_id_str = NULL;
|
bracketed_id_str = NULL;
|
||||||
BEGIN SC_AFTER_IDENTIFIER;
|
BEGIN SC_AFTER_IDENTIFIER;
|
||||||
}
|
}
|
||||||
|
|
||||||
{int} {
|
{int} RETURN_VALUE (INT, scan_integer (yytext, 10, *loc));
|
||||||
val->integer = scan_integer (yytext, 10, *loc);
|
{xint} RETURN_VALUE (INT, scan_integer (yytext, 16, *loc));
|
||||||
return INT;
|
|
||||||
}
|
|
||||||
0[xX][0-9abcdefABCDEF]+ {
|
|
||||||
val->integer = scan_integer (yytext, 16, *loc);
|
|
||||||
return INT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Identifiers may not start with a digit. Yet, don't silently
|
/* Identifiers may not start with a digit. Yet, don't silently
|
||||||
accept "1FOO" as "1 FOO". */
|
accept "1FOO" as "1 FOO". */
|
||||||
@@ -437,7 +432,7 @@ eqopt ([[:space:]]*=)?
|
|||||||
{
|
{
|
||||||
if (INITIAL == bracketed_id_context_state)
|
if (INITIAL == bracketed_id_context_state)
|
||||||
{
|
{
|
||||||
val->uniqstr = bracketed_id_str;
|
val->BRACKETED_ID = bracketed_id_str;
|
||||||
bracketed_id_str = 0;
|
bracketed_id_str = 0;
|
||||||
*loc = bracketed_id_loc;
|
*loc = bracketed_id_loc;
|
||||||
return BRACKETED_ID;
|
return BRACKETED_ID;
|
||||||
@@ -464,7 +459,7 @@ eqopt ([[:space:]]*=)?
|
|||||||
{
|
{
|
||||||
. {
|
. {
|
||||||
ROLLBACK_CURRENT_TOKEN;
|
ROLLBACK_CURRENT_TOKEN;
|
||||||
val->uniqstr = bracketed_id_str;
|
val->BRACKETED_ID = bracketed_id_str;
|
||||||
bracketed_id_str = 0;
|
bracketed_id_str = 0;
|
||||||
*loc = bracketed_id_loc;
|
*loc = bracketed_id_loc;
|
||||||
BEGIN INITIAL;
|
BEGIN INITIAL;
|
||||||
@@ -517,10 +512,9 @@ eqopt ([[:space:]]*=)?
|
|||||||
{
|
{
|
||||||
"\"" {
|
"\"" {
|
||||||
STRING_FINISH;
|
STRING_FINISH;
|
||||||
loc->start = token_start;
|
|
||||||
val->code = last_string;
|
|
||||||
BEGIN INITIAL;
|
BEGIN INITIAL;
|
||||||
return STRING;
|
loc->start = token_start;
|
||||||
|
RETURN_VALUE (STRING, last_string);
|
||||||
}
|
}
|
||||||
<<EOF>> unexpected_eof (token_start, "\"");
|
<<EOF>> unexpected_eof (token_start, "\"");
|
||||||
"\n" unexpected_newline (token_start, "\"");
|
"\n" unexpected_newline (token_start, "\"");
|
||||||
@@ -536,14 +530,14 @@ eqopt ([[:space:]]*=)?
|
|||||||
"'" {
|
"'" {
|
||||||
STRING_FINISH;
|
STRING_FINISH;
|
||||||
loc->start = token_start;
|
loc->start = token_start;
|
||||||
val->character = last_string[0];
|
val->CHAR = last_string[0];
|
||||||
|
|
||||||
/* FIXME: Eventually, make these errors. */
|
/* FIXME: Eventually, make these errors. */
|
||||||
if (last_string[0] == '\0')
|
if (last_string[0] == '\0')
|
||||||
{
|
{
|
||||||
complain (loc, Wother, _("empty character literal"));
|
complain (loc, Wother, _("empty character literal"));
|
||||||
/* '\0' seems dangerous even if we are about to complain. */
|
/* '\0' seems dangerous even if we are about to complain. */
|
||||||
val->character = '\'';
|
val->CHAR = '\'';
|
||||||
}
|
}
|
||||||
else if (last_string[1] != '\0')
|
else if (last_string[1] != '\0')
|
||||||
complain (loc, Wother,
|
complain (loc, Wother,
|
||||||
@@ -570,7 +564,7 @@ eqopt ([[:space:]]*=)?
|
|||||||
{
|
{
|
||||||
STRING_FINISH;
|
STRING_FINISH;
|
||||||
loc->start = token_start;
|
loc->start = token_start;
|
||||||
val->uniqstr = uniqstr_new (last_string);
|
val->TAG = uniqstr_new (last_string);
|
||||||
STRING_FREE;
|
STRING_FREE;
|
||||||
BEGIN INITIAL;
|
BEGIN INITIAL;
|
||||||
return TAG;
|
return TAG;
|
||||||
@@ -725,9 +719,8 @@ eqopt ([[:space:]]*=)?
|
|||||||
{
|
{
|
||||||
STRING_FINISH;
|
STRING_FINISH;
|
||||||
loc->start = code_start;
|
loc->start = code_start;
|
||||||
val->code = last_string;
|
|
||||||
BEGIN INITIAL;
|
BEGIN INITIAL;
|
||||||
return BRACED_CODE;
|
RETURN_VALUE (BRACED_CODE, last_string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -740,9 +733,8 @@ eqopt ([[:space:]]*=)?
|
|||||||
{
|
{
|
||||||
STRING_FINISH;
|
STRING_FINISH;
|
||||||
loc->start = code_start;
|
loc->start = code_start;
|
||||||
val->code = last_string;
|
|
||||||
BEGIN INITIAL;
|
BEGIN INITIAL;
|
||||||
return BRACED_PREDICATE;
|
RETURN_VALUE (BRACED_PREDICATE, last_string);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
obstack_1grow (&obstack_for_string, '}');
|
obstack_1grow (&obstack_for_string, '}');
|
||||||
@@ -758,9 +750,8 @@ eqopt ([[:space:]]*=)?
|
|||||||
"%}" {
|
"%}" {
|
||||||
STRING_FINISH;
|
STRING_FINISH;
|
||||||
loc->start = code_start;
|
loc->start = code_start;
|
||||||
val->code = last_string;
|
|
||||||
BEGIN INITIAL;
|
BEGIN INITIAL;
|
||||||
return PROLOGUE;
|
RETURN_VALUE (PROLOGUE, last_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
<<EOF>> unexpected_eof (code_start, "%}");
|
<<EOF>> unexpected_eof (code_start, "%}");
|
||||||
@@ -777,9 +768,8 @@ eqopt ([[:space:]]*=)?
|
|||||||
<<EOF>> {
|
<<EOF>> {
|
||||||
STRING_FINISH;
|
STRING_FINISH;
|
||||||
loc->start = code_start;
|
loc->start = code_start;
|
||||||
val->code = last_string;
|
|
||||||
BEGIN INITIAL;
|
BEGIN INITIAL;
|
||||||
return EPILOGUE;
|
RETURN_VALUE (EPILOGUE, last_string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user