|
From: | Akim Demaille |
Subject: | RFC: %param |
Date: | Mon, 7 Sep 2009 09:55:24 +0200 |
Hi, I was tired to read
%parse-param {::parser::ParserImpl& up} %lex-param {::parser::ParserImpl& up} %parse-param {yyFlexLexer& scanner} %lex-param {yyFlexLexer& scanner}
in my code, I wanted
%param {::parser::ParserImpl& up}{yyFlexLexer& scanner};
I pushed this feature in candidates/%param, but there are several issues:
- I had not noticed, but when I started upgrading the documentation, I discovered that in lalr1.java, the %lex-params are added to the signature of yyparse, which in my case would have allowed to use only %lex-params. It makes sense, but I am uncomfortable with the coexistence of several conventions within Bison.
- I like to keep related things close to each other. But sometimes it can clutter the code. Here, as often in my grammars, I have put together everything related to %(lex-|parse-)?param management, but it disrupts the reading of the grammar. What do people prefer? Currently, it reads:
/*---------. | %param. | `---------*/ %code requires { # ifndef PARAM_TYPE # define PARAM_TYPE typedef enum { param_none = 0, param_lex = 1 << 0, param_parse = 1 << 1, param_both = param_lex | param_parse } param_type; # endif }; %code { /** Add a lex-param and/or a parse-param. * * \param type where to push this formal argument. * \param decl the formal argument. Destroyed. * \param loc the location in the source. */ static void add_param (param_type type, char *decl, location loc); static param_type current_param = param_none; }; %union { param_type param; }; %token <param> PERCENT_PARAM "%param"; %printer { switch ($$) { #define CASE(In, Out) \ case param_ ## In: fputs ("%" #Out, stderr); break CASE(lex, lex-param); CASE(parse, parse-param); CASE(both, param); #undef CASE } } <param>; prologue_declaration:"%param" { current_param = $1; } params { current_param = param_none; }; params: params "{...}" { add_param (current_param, $2, @2); } | "{...}" { add_param (current_param, $1, @1); } ;
- I have not written the test suite yet, but I'm using the feature.
0001-param.txt
Description: Text document
0002-Regen.txt
Description: Text document
0003-parse-support-several-arguments.txt
Description: Text document
0004-Regen.txt
Description: Text document
0005-param-documentation.txt
Description: Text document
[Prev in Thread] | Current Thread | [Next in Thread] |