diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2020-07-05 08:00:20 +0200 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2020-09-27 09:44:18 +0200 |
commit | d9cf99b6a5cb0345e91dfb90fe6d6473024ea97a (patch) | |
tree | c0ab689746ca8d41afa3d0acd2342b471a3e5e1c /TODO | |
parent | a6805bb8d93cfcdb058139661b73ea3f101eb6da (diff) | |
download | bison-d9cf99b6a5cb0345e91dfb90fe6d6473024ea97a.tar.gz |
multistart: use b4_accept instead of action post-processing
For each start symbol, generate a parsing function with a richer
return value than the usual of yyparse. Reserve a place for the
returned semantic value, in order to avoid having to pass a pointer as
argument to "return" that value. This also makes the call to the
parsing function independent of whether a given start-symbol is typed.
For instance, if the grammar file contains:
%type <int> expression
%start input expression
(so "input" is valueless) we get
typedef struct
{
int yystatus;
} yyparse_input_t;
yyparse_input_t yyparse_input (void);
typedef struct
{
int yyvalue;
int yystatus;
} yyparse_expression_t;
yyparse_expression_t yyparse_expression (void);
This commit also changes the implementation of the parser termination:
when there are multiple start symbols, it is the initial rules that
explicitly YYACCEPT. They do that after having exported the
start-symbol's value (if it is typed):
switch (yyn)
{
case 1: /* $accept: YY_EXPRESSION expression $end */
{ ((*yyvalue).TOK_expression) = (yyvsp[-1].TOK_expression); YYACCEPT; }
break;
case 2: /* $accept: YY_INPUT input $end */
{ YYACCEPT; }
break;
I have tried several ways to deal with termination, and this is the
one that appears the best one to me. It is also the most natural.
* src/scan-code.h, src/scan-code.l (obstack_for_actions): New.
* src/reader.c (grammar_rule_check_and_complete): Generate the actions
of the rules for each start symbol.
* data/skeletons/bison.m4 (b4_symbol_slot): New, with safer semantics
than type and type_tag.
* data/skeletons/yacc.c (b4_accept): New.
Generates the body of the action of the start rules.
(_b4_declare_sub_yyparse): For each start symbol define a dedicated
return type for its parsing function.
Adjust the declaration of its parsing function.
(_b4_define_sub_yyparse): Adjust the definition of the function.
* examples/c/lexcalc/parse.y: Check the case of valueless symbols.
* examples/c/lexcalc/lexcalc.test: Check start symbols.
Diffstat (limited to 'TODO')
-rw-r--r-- | TODO | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -240,6 +240,10 @@ functions. states/nstates, rules/nrules, ..., ritem/nritems Fix the latter. +*** m4: slot, type, type_tag +The meaning of type_tag varies depending on api.value.type. We should avoid +that and using clear definitions with stable semantics. + * D programming language There's a number of features that are missing, here sorted in _suggested_ order of implementation. |