[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Enhancement Request
From: |
Domingo Alvarez Duarte |
Subject: |
Re: Enhancement Request |
Date: |
Sun, 19 Jun 2022 20:06:12 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 |
Hello Kaz !
As I said before here in the list, I also have that need for other
purposes (compare, reuse, convert, ... grammars) and did that first with
byacc and then lemon and bison here
https://github.com/mingodad/lalr-parser-test
For example here is what I call naked grammar from bison 3.8.2:
====
bison-nb --help
Usage: bison-nb [OPTION]... FILE
Generate a deterministic LR or generalized LR (GLR) parser employing
LALR(1), IELR(1), or canonical LR(1) parser tables.
Mandatory arguments to long options are mandatory for short options too.
The same is true for optional arguments.
Operation Modes:
-h, --help display this help and exit
-V, --version output version information and exit
--print-localedir output directory containing
locale-dependent data
and exit
--print-datadir output directory containing skeletons and XSLT
and exit
-u, --update apply fixes to the source grammar file and
exit
-f, --feature[=FEATURES] activate miscellaneous features
FEATURES is a list of comma separated words that can include:
caret, diagnostics-show-caret
show errors with carets
fixit, diagnostics-parseable-fixits
show machine-readable fixes
syntax-only do not generate any file
all all of the above
none disable all of the above
Diagnostics:
-W, --warnings[=CATEGORY] report the warnings falling in CATEGORY
--color[=WHEN] whether to colorize the diagnostics
--style=FILE specify the CSS FILE for colorizer diagnostics
Warning categories include:
conflicts-sr S/R conflicts (enabled by default)
conflicts-rr R/R conflicts (enabled by default)
counterexamples, cex
generate conflict counterexamples
dangling-alias string aliases not attached to a symbol
deprecated obsolete constructs
empty-rule empty rules without %empty
midrule-values unset or unused midrule values
precedence useless precedence and associativity
yacc incompatibilities with POSIX Yacc
other all other warnings (enabled by default)
all all the warnings except 'counterexamples',
'dangling-alias' and 'yacc'
no-CATEGORY turn off warnings in CATEGORY
none turn off all the warnings
error[=CATEGORY] treat warnings as errors
WHEN can be one of the following:
always, yes colorize the output
never, no don't colorize the output
auto, tty colorize if the output device is a tty
Tuning the Parser:
-L, --language=LANGUAGE specify the output programming language
-S, --skeleton=FILE specify the skeleton to use
-t, --debug instrument the parser for tracing
same as '-Dparse.trace'
--locations enable location support
-D, --define=NAME[=VALUE] similar to '%define NAME VALUE'
-F, --force-define=NAME[=VALUE] override '%define NAME VALUE'
-p, --name-prefix=PREFIX prepend PREFIX to the external symbols
deprecated by '-Dapi.prefix={PREFIX}'
-l, --no-lines don't generate '#line' directives
-k, --token-table include a table of token names
-y, --yacc emulate POSIX Yacc
-z, --noprec ignore all precedences
Output Files:
-e generate RREBNF
-n generate naked grammar
-N generate lemon grammar
-s generate sql
-H, --header=[FILE] also produce a header file
-d likewise but cannot specify FILE (for
POSIX Yacc)
-r, --report=THINGS also produce details on the automaton
--report-file=FILE write report to FILE
-v, --verbose same as '--report=state'
-b, --file-prefix=PREFIX specify a PREFIX for output files
-o, --output=FILE leave output to FILE
-g, --graph[=FILE] also output a graph of the automaton
--html[=FILE] also output an HTML report of the automaton
-x, --xml[=FILE] also output an XML report of the automaton
-M, --file-prefix-map=OLD=NEW replace prefix OLD with NEW when
writing file paths
in output files
THINGS is a list of comma separated words that can include:
states describe the states
itemsets complete the core item sets with their closure
lookaheads explicitly associate lookahead tokens to items
solved describe shift/reduce conflicts solving
counterexamples, cex
generate conflict counterexamples
all include all the above information
none disable the report
Report bugs to <bug-bison@gnu.org>.
GNU Bison home page: <https://www.gnu.org/software/bison/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
Report translation bugs to <https://translationproject.org/team/>.
For complete documentation, run: info bison.
====
====
bison-nb -n parse-gram.y
/*Tokens*/
%token YYEOF
%token YYerror
%token YYUNDEF
%token STRING
%token TSTRING
%token PERCENT_TOKEN
%token PERCENT_NTERM
%token PERCENT_TYPE
%token PERCENT_DESTRUCTOR
%token PERCENT_PRINTER
%token PERCENT_LEFT
%token PERCENT_RIGHT
%token PERCENT_NONASSOC
%token PERCENT_PRECEDENCE
%token PERCENT_PREC
%token PERCENT_DPREC
%token PERCENT_MERGE
%token PERCENT_CODE
%token PERCENT_DEFAULT_PREC
%token PERCENT_DEFINE
%token PERCENT_ERROR_VERBOSE
%token PERCENT_EXPECT
%token PERCENT_EXPECT_RR
%token PERCENT_FILE_PREFIX
%token PERCENT_FLAG
%token PERCENT_GLR_PARSER
%token PERCENT_HEADER
%token PERCENT_INITIAL_ACTION
%token PERCENT_LANGUAGE
%token PERCENT_NAME_PREFIX
%token PERCENT_NO_DEFAULT_PREC
%token PERCENT_NO_LINES
%token PERCENT_NONDETERMINISTIC_PARSER
%token PERCENT_OUTPUT
%token PERCENT_PURE_PARSER
%token PERCENT_REQUIRE
%token PERCENT_SKELETON
%token PERCENT_START
%token PERCENT_TOKEN_TABLE
%token PERCENT_VERBOSE
%token PERCENT_YACC
%token BRACED_CODE
%token BRACED_PREDICATE
%token BRACKETED_ID
%token CHAR_LITERAL
%token COLON
%token EPILOGUE
%token EQUAL
%token ID
%token ID_COLON
%token PERCENT_PERCENT
%token PIPE
%token PROLOGUE
%token SEMICOLON
%token TAG
%token TAG_ANY
%token TAG_NONE
%token INT_LITERAL
%token PERCENT_PARAM
%token PERCENT_UNION
%token PERCENT_EMPTY
%start input
%%
input :
YYEOF
| prologue_declarations "%%" grammar epilogue.opt
;
prologue_declarations :
/*empty*/
| prologue_declarations prologue_declaration
;
prologue_declaration :
grammar_declaration
| "%{...%}"
| "%<flag>"
| "%define" variable value
| "%header" string.opt
| "%error-verbose"
| "%expect" INT_LITERAL
| "%expect-rr" INT_LITERAL
| "%file-prefix" STRING
| "%glr-parser"
| "%initial-action" "{...}"
| "%language" STRING
| "%name-prefix" STRING
| "%no-lines"
| "%nondeterministic-parser"
| "%output" STRING
| "%param" params
| "%pure-parser"
| "%require" STRING
| "%skeleton" STRING
| "%token-table"
| "%verbose"
| "%yacc"
| error ";"
| ";"
;
params :
params "{...}"
| "{...}"
;
grammar_declaration :
symbol_declaration
| "%start" symbols.1
| code_props_type "{...}" generic_symlist
| "%default-prec"
| "%no-default-prec"
| "%code" "{...}"
| "%code" ID "{...}"
;
code_props_type :
"%destructor"
| "%printer"
;
union_name :
/*empty*/
| ID
;
grammar_declaration :
"%union" union_name "{...}"
;
symbol_declaration :
"%nterm" nterm_decls
| "%token" token_decls
| "%type" symbol_decls
| precedence_declarator token_decls_for_prec
;
precedence_declarator :
"%left"
| "%right"
| "%nonassoc"
| "%precedence"
;
string.opt :
/*empty*/
| STRING
;
tag.opt :
/*empty*/
| TAG
;
generic_symlist :
generic_symlist_item
| generic_symlist generic_symlist_item
;
generic_symlist_item :
symbol
| tag
;
tag :
TAG
| "<*>"
| "<>"
;
nterm_decls :
token_decls
;
token_decls :
token_decl.1
| TAG token_decl.1
| token_decls TAG token_decl.1
;
token_decl.1 :
token_decl
| token_decl.1 token_decl
;
token_decl :
id int.opt alias
;
int.opt :
/*empty*/
| INT_LITERAL
;
alias :
/*empty*/
| string_as_id
| TSTRING
;
token_decls_for_prec :
token_decl_for_prec.1
| TAG token_decl_for_prec.1
| token_decls_for_prec TAG token_decl_for_prec.1
;
token_decl_for_prec.1 :
token_decl_for_prec
| token_decl_for_prec.1 token_decl_for_prec
;
token_decl_for_prec :
id int.opt
| string_as_id
;
symbol_decls :
symbols.1
| TAG symbols.1
| symbol_decls TAG symbols.1
;
symbols.1 :
symbol
| symbols.1 symbol
;
grammar :
rules_or_grammar_declaration
| grammar rules_or_grammar_declaration
;
rules_or_grammar_declaration :
rules
| grammar_declaration ";"
| error ";"
;
rules :
id_colon named_ref.opt ":" rhses.1
;
rhses.1 :
rhs
| rhses.1 "|" rhs
| rhses.1 ";"
;
rhs :
/*empty*/
| rhs symbol named_ref.opt
| rhs tag.opt "{...}" named_ref.opt
| rhs "%?{...}"
| rhs "%empty"
| rhs "%prec" symbol
| rhs "%dprec" INT_LITERAL
| rhs "%merge" TAG
| rhs "%expect" INT_LITERAL
| rhs "%expect-rr" INT_LITERAL
;
named_ref.opt :
/*empty*/
| BRACKETED_ID
;
variable :
ID
;
value :
/*empty*/
| ID
| STRING
| "{...}"
;
id :
ID
| CHAR_LITERAL
;
id_colon :
ID_COLON
;
symbol :
id
| string_as_id
;
string_as_id :
STRING
;
epilogue.opt :
/*empty*/
| "%%" EPILOGUE
;
====
Cheers !
On 19/6/22 19:58, Kaz Kylheku wrote:
On 2022-06-17 10:58, slipbits wrote:
Given that Bison has the ability to (and does) generate a parser for
itself, is there any possibility of removing all %code tags in future releases.
This is not clear; remove what from where? For what purpose?
How does Bison being partially self-hosted play into the removal?
This means that one code block, %code { declarations }, is all that is
required and removes the placement requirements and discussion in
the Bison User's Manual.
By tag, do you want to remove the %code <qualifier> feature?
From where?
The Bison grammar file parse-gram.y uses multiple
%oode <qualifier> construcs.
Are you looking to edit that file so that it has only one unqualified
%code block?
Why shouldn't it it have multiple, qualified blocks?
This is a documented feature of Bison; the Bison grammar is just
"eating the dogfood", which is good.
Bison ships the generated parser as parse-gram.c, which means that
it builds without needing an installation of Bison, and the grammar
file can use the latest features provided in that same version
of Bison.
Removing the multiple qualified %oode blocks from Bison's own
grammer would just mean that the feature is exercised less.
The documentation makes it clear that the %code feature makes
placement less important compared to the traditional %{ ... %}
Bison gathers code from multiple %code blocks, then catenates
them together (by qualifier) type. For any qualifier, the order
is preserved. The code is then generated into the appropriate
location based on the output type.