mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 09:43:03 +00:00
parser: factor the symbol definition
* src/parse-gram.y (int.opt, string_as_id.opt): New. (symbol_def): Use it.
This commit is contained in:
@@ -503,52 +503,37 @@ symbol_def:
|
|||||||
current_type = $1;
|
current_type = $1;
|
||||||
tag_seen = true;
|
tag_seen = true;
|
||||||
}
|
}
|
||||||
| id
|
| id int.opt[num] string_as_id.opt[alias]
|
||||||
{
|
{
|
||||||
symbol_class_set ($1, current_class, @1, true);
|
symbol_class_set ($id, current_class, @id, true);
|
||||||
symbol_type_set ($1, current_type, @1);
|
symbol_type_set ($id, current_type, @id);
|
||||||
}
|
if (0 <= $num)
|
||||||
| id INT
|
|
||||||
{
|
|
||||||
if (current_class != token_sym)
|
|
||||||
{
|
{
|
||||||
gram_error (&@2,
|
if (current_class != token_sym)
|
||||||
_("non-terminals cannot be given an explicit number"));
|
gram_error (&@num,
|
||||||
YYERROR;
|
_("non-terminals cannot be given an explicit number"));
|
||||||
|
else
|
||||||
|
symbol_user_token_number_set ($id, $num, @num);
|
||||||
}
|
}
|
||||||
symbol_class_set ($1, current_class, @1, true);
|
if ($alias)
|
||||||
symbol_type_set ($1, current_type, @1);
|
|
||||||
symbol_user_token_number_set ($1, $2, @2);
|
|
||||||
}
|
|
||||||
| id string_as_id
|
|
||||||
{
|
|
||||||
if (current_class != token_sym)
|
|
||||||
{
|
{
|
||||||
gram_error (&@2,
|
if (current_class != token_sym)
|
||||||
_("non-terminals cannot be given a string alias"));
|
gram_error (&@alias,
|
||||||
YYERROR;
|
_("non-terminals cannot be given a string alias"));
|
||||||
|
else
|
||||||
|
symbol_make_alias ($id, $alias, @alias);
|
||||||
}
|
}
|
||||||
symbol_class_set ($1, current_class, @1, true);
|
if (current_class != token_sym && (0 <= $num || !$alias))
|
||||||
symbol_type_set ($1, current_type, @1);
|
YYERROR;
|
||||||
symbol_make_alias ($1, $2, @2);
|
|
||||||
}
|
|
||||||
| id INT string_as_id
|
|
||||||
{
|
|
||||||
if (current_class != token_sym)
|
|
||||||
{
|
|
||||||
gram_error (&@2,
|
|
||||||
_("non-terminals cannot be given an explicit number"));
|
|
||||||
gram_error (&@3,
|
|
||||||
_("non-terminals cannot be given a string alias"));
|
|
||||||
YYERROR;
|
|
||||||
}
|
|
||||||
symbol_class_set ($1, current_class, @1, true);
|
|
||||||
symbol_type_set ($1, current_type, @1);
|
|
||||||
symbol_user_token_number_set ($1, $2, @2);
|
|
||||||
symbol_make_alias ($1, $3, @3);
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
%type <int> int.opt;
|
||||||
|
int.opt:
|
||||||
|
%empty { $$ = -1; }
|
||||||
|
| INT
|
||||||
|
;
|
||||||
|
|
||||||
/* One or more symbol definitions. */
|
/* One or more symbol definitions. */
|
||||||
symbol_defs.1:
|
symbol_defs.1:
|
||||||
symbol_def
|
symbol_def
|
||||||
@@ -703,6 +688,12 @@ string_as_id:
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
%type <symbol*> string_as_id.opt;
|
||||||
|
string_as_id.opt:
|
||||||
|
%empty { $$ = NULL; }
|
||||||
|
| string_as_id
|
||||||
|
;
|
||||||
|
|
||||||
epilogue.opt:
|
epilogue.opt:
|
||||||
%empty
|
%empty
|
||||||
| "%%" EPILOGUE
|
| "%%" EPILOGUE
|
||||||
|
|||||||
Reference in New Issue
Block a user