mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
Consolidate the 4 prologue alternative directives (%code, %requires,
%provides, and %code-top) into a single %code directive with an optional qualifier field. Discussed at <http://lists.gnu.org/archive/html/bison-patches/2007-01/msg00012.html>. * NEWS (2.3a+): Rewrite the existing entry for the prologue alternatives. * doc/bison.texinfo (Prologue Alternatives): Update. (Decl Summary): Update to %code "requires" and %code "provides". (Calc++ Parser): Update to %code "requires". (Bison Symbols): Remove entries for %requires, %provides, and %code-top. Rewrite %code entry, and add a %code "QUALIFIER" entry. * data/bison.m4 (b4_user_provides, b4_user_requires): Remove as these are replaced by b4_percent_code_provides and b4_percent_code_requires, which are skeleton-specific. (b4_check_percent_code_qualifiers): New. A skeleton can use this to declare what %code qualifiers it supports and to complain if any other qualifiers were used in the grammar. * data/glr.cc: Update to use b4_user_code([b4_percent_code_requires]) and b4_user_code([b4_percent_code_provides]) in place of b4_user_requires and b4_user_provides. * data/glr.c, data/lalr1.cc, data/push.c, data/yacc.c: Likewise. Add b4_user_code([b4_percent_code_top]) and b4_user_code([b4_percent_code]). Invoke b4_check_percent_code_qualifiers. * src/parse-gram.y (PERCENT_CODE_TOP, PERCENT_PROVIDES, PERCENT_REQUIRES): Remove. (grammar_declaration): Remove RHS's for %code-top, %provides, and %requires. Rewrite the %code RHS as the unqualified form defining the muscle b4_percent_code. Add another RHS for the qualified %code form, which defines muscles of the form b4_percent_code_QUALIFIER and the b4_used_percent_code_qualifiers muscle. * src/scan-gram.l (PERCENT_CODE_TOP, PERCENT_PROVIDES, PERCENT_REQUIRES): Remove. * tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Update to use %code "requires" and %code "provides". * tests/input.at (Reject bad %code qualifiers): New.
This commit is contained in:
39
ChangeLog
39
ChangeLog
@@ -1,3 +1,42 @@
|
||||
2007-01-04 Joel E. Denny <jdenny@ces.clemson.edu>
|
||||
|
||||
Consolidate the 4 prologue alternative directives (%code, %requires,
|
||||
%provides, and %code-top) into a single %code directive with an
|
||||
optional qualifier field. Discussed at
|
||||
<http://lists.gnu.org/archive/html/bison-patches/2007-01/msg00012.html>.
|
||||
* NEWS (2.3a+): Rewrite the existing entry for the prologue
|
||||
alternatives.
|
||||
* doc/bison.texinfo (Prologue Alternatives): Update.
|
||||
(Decl Summary): Update to %code "requires" and %code "provides".
|
||||
(Calc++ Parser): Update to %code "requires".
|
||||
(Bison Symbols): Remove entries for %requires, %provides, and
|
||||
%code-top. Rewrite %code entry, and add a %code "QUALIFIER" entry.
|
||||
* data/bison.m4 (b4_user_provides, b4_user_requires): Remove as these
|
||||
are replaced by b4_percent_code_provides and b4_percent_code_requires,
|
||||
which are skeleton-specific.
|
||||
(b4_check_percent_code_qualifiers): New. A skeleton can use this to
|
||||
declare what %code qualifiers it supports and to complain if any other
|
||||
qualifiers were used in the grammar.
|
||||
* data/glr.cc: Update to use b4_user_code([b4_percent_code_requires])
|
||||
and b4_user_code([b4_percent_code_provides]) in place of
|
||||
b4_user_requires and b4_user_provides.
|
||||
* data/glr.c, data/lalr1.cc, data/push.c, data/yacc.c: Likewise.
|
||||
Add b4_user_code([b4_percent_code_top]) and
|
||||
b4_user_code([b4_percent_code]).
|
||||
Invoke b4_check_percent_code_qualifiers.
|
||||
* src/parse-gram.y (PERCENT_CODE_TOP, PERCENT_PROVIDES,
|
||||
PERCENT_REQUIRES): Remove.
|
||||
(grammar_declaration): Remove RHS's for %code-top, %provides, and
|
||||
%requires. Rewrite the %code RHS as the unqualified form defining the
|
||||
muscle b4_percent_code. Add another RHS for the qualified %code form,
|
||||
which defines muscles of the form b4_percent_code_QUALIFIER and the
|
||||
b4_used_percent_code_qualifiers muscle.
|
||||
* src/scan-gram.l (PERCENT_CODE_TOP, PERCENT_PROVIDES,
|
||||
PERCENT_REQUIRES): Remove.
|
||||
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Update to use
|
||||
%code "requires" and %code "provides".
|
||||
* tests/input.at (Reject bad %code qualifiers): New.
|
||||
|
||||
2007-01-03 Joel E. Denny <jdenny@ces.clemson.edu>
|
||||
|
||||
Use the new code_props interface for destructors and printers.
|
||||
|
||||
89
NEWS
89
NEWS
@@ -23,6 +23,25 @@ Changes in version 2.3a+ (????-??-??):
|
||||
%name-prefix "c_"
|
||||
%output "parser.c"
|
||||
|
||||
* Bison 2.3a provided a new set of directives as a more flexible alternative to
|
||||
the traditional Yacc prologue blocks. Those have now been consolidated into
|
||||
a single %code directive with an optional qualifier field, which identifies
|
||||
the purpose of the code and thus the location(s) where Bison should generate
|
||||
it:
|
||||
|
||||
1. `%code {CODE}' replaces `%after-header {CODE}'
|
||||
2. `%code "requires" {CODE}' replaces `%start-header {CODE}'
|
||||
3. `%code "provides" {CODE}' replaces `%end-header {CODE}'
|
||||
4. `%code "top" {CODE}' replaces `%before-header {CODE}'
|
||||
|
||||
See the %code entries in `Appendix A Bison Symbols' in the Bison manual for a
|
||||
summary of the new functionality. See the new section `Prologue
|
||||
Alternatives' for a detailed discussion including the advantages of %code
|
||||
over the traditional Yacc prologues.
|
||||
|
||||
The prologue alternatives are experimental. More user feedback will help to
|
||||
determine whether they should become permanent features.
|
||||
|
||||
* Revised warning: unset or unused mid-rule values
|
||||
|
||||
Since Bison 2.2, Bison has warned about mid-rule values that are set but not
|
||||
@@ -66,76 +85,6 @@ Changes in version 2.3a+ (????-??-??):
|
||||
See the section `Freeing Discarded Symbols' in the Bison manual for further
|
||||
details.
|
||||
|
||||
* The Yacc prologue alternatives from Bison 2.3a have been rewritten as the
|
||||
following directives:
|
||||
|
||||
1. %code {CODE}
|
||||
|
||||
Other than semantic actions, this is probably the most common place you
|
||||
should write verbatim code for the parser implementation. It replaces
|
||||
the traditional Yacc prologue, `%{CODE%}', for most purposes. Compare
|
||||
with:
|
||||
|
||||
- `%{CODE%}' appearing after the first `%union {CODE}' in a grammar
|
||||
file. While Bison will continue to support `%{CODE%}' for backward
|
||||
compatibility, `%code {CODE}' is cleaner as its functionality does
|
||||
not depend on its position in the grammar file relative to any
|
||||
`%union {CODE}'. Specifically, `%code {CODE}' always inserts your
|
||||
CODE into the parser code file after the usual contents of the
|
||||
parser header file.
|
||||
- `%after-header {CODE}', which only Bison 2.3a supported.
|
||||
|
||||
2. %requires {CODE}
|
||||
|
||||
This is the right place to write dependency code for externally exposed
|
||||
definitions required by Bison. Such exposed definitions are those
|
||||
usually appearing in the parser header file. Thus, this is the right
|
||||
place to define types referenced in `%union {CODE}' directives, and it
|
||||
is the right place to override Bison's default YYSTYPE and YYLTYPE
|
||||
definitions. Compare with:
|
||||
|
||||
- `%{CODE%}' appearing before the first `%union {CODE}' in a grammar
|
||||
file. Unlike `%{CODE%}', `%requires {CODE}' inserts your CODE both
|
||||
into the parser code file and into the parser header file since
|
||||
Bison's required definitions should depend on it in both places.
|
||||
- `%start-header {CODE}', which only Bison 2.3a supported.
|
||||
|
||||
3. %provides {CODE}
|
||||
|
||||
This is the right place to write additional definitions you would like
|
||||
Bison to expose externally. That is, this directive inserts your CODE
|
||||
both into the parser header file and into the parser code file after
|
||||
Bison's required definitions. Compare with:
|
||||
|
||||
- `%end-header {CODE}', which only Bison 2.3a supported.
|
||||
|
||||
4. %code-top {CODE}
|
||||
|
||||
Occasionally it is desirable to insert code near the top of the parser
|
||||
code file. For example:
|
||||
|
||||
%code-top {
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
}
|
||||
|
||||
Compare with:
|
||||
|
||||
- `%{CODE%}' appearing before the first `%union {CODE}' in a grammar
|
||||
file. `%code-top {CODE}' is cleaner as its functionality does not
|
||||
depend on its position in the grammar file relative to any
|
||||
`%union {CODE}'.
|
||||
- `%before-header {CODE}', which only Bison 2.3a supported.
|
||||
|
||||
If you have multiple occurrences of any one of the above four directives,
|
||||
Bison will concatenate the contents in the order they appear in the grammar
|
||||
file.
|
||||
|
||||
The prologue alternatives are experimental. More user feedback will help to
|
||||
determine whether they should become permanent features.
|
||||
|
||||
Also see the new section `Prologue Alternatives' in the Bison manual.
|
||||
|
||||
Changes in version 2.3a, 2006-09-13:
|
||||
|
||||
* Instead of %union, you can define and use your own union type
|
||||
|
||||
@@ -184,8 +184,6 @@ m4_define([b4_define_user_code],
|
||||
# b4_user_initial_action
|
||||
# b4_user_post_prologue
|
||||
# b4_user_pre_prologue
|
||||
# b4_user_provides
|
||||
# b4_user_requires
|
||||
# b4_user_stype
|
||||
# ----------------------
|
||||
# Macros that issue user code, ending with synclines.
|
||||
@@ -193,8 +191,38 @@ b4_define_user_code([actions])
|
||||
b4_define_user_code([initial_action])
|
||||
b4_define_user_code([post_prologue])
|
||||
b4_define_user_code([pre_prologue])
|
||||
b4_define_user_code([provides])
|
||||
b4_define_user_code([requires])
|
||||
b4_define_user_code([stype])
|
||||
|
||||
|
||||
# b4_check_percent_code_qualifiers([VAILD_QUALIFIER], [VALID_QUALIFIER], ...)
|
||||
# ---------------------------------------------------------------------------
|
||||
# Complain if any %code qualifier used in the grammar is not a valid qualifier.
|
||||
#
|
||||
# b4_used_percent_code_qualifiers must expand to a comma-delimited list of the
|
||||
# %code qualifiers used in the grammar. The list as a whole must be quoted,
|
||||
# but individual qualifiers in it must not be. Qualifiers will not be
|
||||
# M4-expanded. Whitespace will not be stripped from the qualifiers. Any
|
||||
# qualifier that is the empty string will be correctly parsed as such. If
|
||||
# b4_used_percent_code_qualifiers expands to the empty string, then the list
|
||||
# contains one qualifier that is the empty string. If
|
||||
# b4_used_percent_code_qualifiers is undefined, then the list contains no
|
||||
# qualifiers. Multiple occurrences of the same qualifier are fine.
|
||||
#
|
||||
# Each VALID_QUALIFIER will be M4-expanded once to define a valid qualifier. A
|
||||
# VALID_QUALIFIER that expands to the empty string will correctly define the
|
||||
# empty string as a valid qualifier. If b4_used_percent_code_qualifiers is
|
||||
# invoked with empty parens, then there is one valid qualifier and it is the
|
||||
# empty string. To specify that there are no valid qualifiers, invoke
|
||||
# b4_check_percent_code_qualifiers without parens. Multiple occurrences of the
|
||||
# same valid qualifier are fine.
|
||||
#
|
||||
# Qualifiers and valid qualifiers must not contain the characters `,' or `&'.
|
||||
m4_define([b4_check_percent_code_qualifiers],
|
||||
[m4_ifdef([b4_used_percent_code_qualifiers], [
|
||||
m4_foreach([b4_qualifier],
|
||||
m4_dquote(m4_substr(m4_split(m4_translit(m4_dquote([,]b4_used_percent_code_qualifiers), [,], [&]), [[&]]), 4)),
|
||||
[m4_if(m4_index(m4_if($#, 0, [], [[,]m4_quote($*)[,]]),
|
||||
[,]m4_defn([b4_qualifier])[,]),
|
||||
[-1],
|
||||
[m4_fatal([`]m4_defn([b4_qualifier])[' is not a recognized %code qualifier.])])
|
||||
])
|
||||
])])
|
||||
|
||||
24
data/glr.c
24
data/glr.c
@@ -20,6 +20,7 @@ m4_divert(-1) -*- C -*-
|
||||
|
||||
|
||||
m4_include(b4_pkgdatadir/[c.m4])
|
||||
b4_check_percent_code_qualifiers([[requires]], [[provides]], [[top]])
|
||||
|
||||
b4_push_if([
|
||||
m4_fatal([Non-deterministic push parsers are not yet supported])])
|
||||
@@ -153,6 +154,9 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C],
|
||||
|
||||
]b4_identification
|
||||
|
||||
m4_ifdef([b4_percent_code_top],
|
||||
[[/* Copy the %code "top" blocks. */
|
||||
]b4_user_code([b4_percent_code_top])])[]dnl
|
||||
m4_if(b4_prefix, [yy], [],
|
||||
[/* Substitute the variable and function names. */
|
||||
#define yyparse b4_prefix[]parse
|
||||
@@ -172,9 +176,9 @@ dnl # ----------------------
|
||||
dnl # Declaration that might either go into the header (if --defines)
|
||||
dnl # or open coded in the parser body.
|
||||
m4_define([b4_shared_declarations],
|
||||
[m4_ifdef([b4_requires],
|
||||
[[/* Copy the %requires blocks. */
|
||||
]b4_user_requires])[]dnl
|
||||
[m4_ifdef([b4_percent_code_requires],
|
||||
[[/* Copy the %code "requires" blocks. */
|
||||
]b4_user_code([b4_percent_code_requires])])[]dnl
|
||||
|
||||
b4_token_enums(b4_tokens)
|
||||
|
||||
@@ -205,9 +209,9 @@ typedef struct YYLTYPE
|
||||
# define YYLTYPE_IS_TRIVIAL 1
|
||||
#endif
|
||||
|
||||
]m4_ifdef([b4_provides],
|
||||
[[/* Copy the %provides blocks. */
|
||||
]b4_user_provides])[]dnl
|
||||
]m4_ifdef([b4_percent_code_provides],
|
||||
[[/* Copy the %code "provides" blocks. */
|
||||
]b4_user_code([b4_percent_code_provides])])[]dnl
|
||||
])
|
||||
|
||||
b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
|
||||
@@ -239,9 +243,13 @@ b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
|
||||
static YYSTYPE yyval_default;
|
||||
|
||||
/* Copy the second part of user declarations. */
|
||||
]b4_user_post_prologue[
|
||||
]b4_user_post_prologue
|
||||
m4_ifdef([b4_percent_code],
|
||||
[[/* Copy the unqualified %code blocks. */
|
||||
]b4_user_code([b4_percent_code])
|
||||
])[]dnl
|
||||
|
||||
#include <stdio.h>
|
||||
[#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
12
data/glr.cc
12
data/glr.cc
@@ -225,9 +225,9 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C++],
|
||||
#ifndef PARSER_HEADER_H
|
||||
# define PARSER_HEADER_H
|
||||
|
||||
]m4_ifdef([b4_requires],
|
||||
[[/* Copy the %requires blocks. */
|
||||
]b4_user_requires])[
|
||||
]m4_ifdef([b4_percent_code_requires],
|
||||
[[/* Copy the %code "requires" blocks. */
|
||||
]b4_user_code([b4_percent_code_requires])])[
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
@@ -373,8 +373,8 @@ m4_ifset([b4_global_tokens_and_yystype],
|
||||
|
||||
}
|
||||
|
||||
]m4_ifdef([b4_provides],
|
||||
[[/* Copy the %provides blocks. */
|
||||
]b4_user_provides])[]dnl
|
||||
]m4_ifdef([b4_percent_code_provides],
|
||||
[[/* Copy the %code "provides" blocks. */
|
||||
]b4_user_code([b4_percent_code_provides])])[]dnl
|
||||
|
||||
[#endif /* ! defined PARSER_HEADER_H */]
|
||||
|
||||
@@ -20,6 +20,7 @@ m4_divert(-1)
|
||||
# 02110-1301 USA
|
||||
|
||||
m4_include(b4_pkgdatadir/[c++.m4])
|
||||
b4_check_percent_code_qualifiers([[requires]], [[provides]], [[top]])
|
||||
|
||||
# The header is mandatory.
|
||||
b4_defines_if([],
|
||||
@@ -43,9 +44,9 @@ dnl FIXME: This is wrong, we want computed header guards.
|
||||
#ifndef PARSER_HEADER_H
|
||||
# define PARSER_HEADER_H
|
||||
|
||||
]m4_ifdef([b4_requires],
|
||||
[[/* Copy the %requires blocks. */
|
||||
]b4_user_requires])[
|
||||
]m4_ifdef([b4_percent_code_requires],
|
||||
[[/* Copy the %code "requires" blocks. */
|
||||
]b4_user_code([b4_percent_code_requires])])[
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
@@ -295,15 +296,18 @@ b4_error_verbose_if([, int tok])[);
|
||||
# define YYSTYPE b4_namespace::b4_parser_class_name::semantic_type
|
||||
#endif
|
||||
])
|
||||
m4_ifdef([b4_provides],
|
||||
[[/* Copy the %provides blocks. */
|
||||
]b4_user_provides])[]dnl
|
||||
m4_ifdef([b4_percent_code_provides],
|
||||
[[/* Copy the %code "provides" blocks. */
|
||||
]b4_user_code([b4_percent_code_provides])])[]dnl
|
||||
|
||||
[#endif /* ! defined PARSER_HEADER_H */]
|
||||
])dnl
|
||||
@output b4_parser_file_name
|
||||
b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
|
||||
[2002, 2003, 2004, 2005, 2006])
|
||||
m4_ifdef([b4_percent_code_top],
|
||||
[[/* Copy the %code "top" blocks. */
|
||||
]b4_user_code([b4_percent_code_top])])[]dnl
|
||||
m4_if(b4_prefix, [yy], [],
|
||||
[
|
||||
// Take the name prefix into account.
|
||||
@@ -316,9 +320,13 @@ b4_defines_if([[
|
||||
#include "@basename(]b4_spec_defines_file[@)"]])[
|
||||
|
||||
/* User implementation prologue. */
|
||||
]b4_user_post_prologue[
|
||||
]b4_user_post_prologue
|
||||
m4_ifdef([b4_percent_code],
|
||||
[[/* Copy the unqualified %code blocks. */
|
||||
]b4_user_code([b4_percent_code])
|
||||
])[]dnl
|
||||
|
||||
#ifndef YY_
|
||||
[#ifndef YY_
|
||||
# if YYENABLE_NLS
|
||||
# if ENABLE_NLS
|
||||
# include <libintl.h> /* FIXME: INFRINGES ON USER NAME SPACE */
|
||||
|
||||
36
data/push.c
36
data/push.c
@@ -33,6 +33,7 @@ b4_use_push_for_pull_if([
|
||||
])])
|
||||
|
||||
m4_include(b4_pkgdatadir/[c.m4])
|
||||
b4_check_percent_code_qualifiers([[requires]], [[provides]], [[top]])
|
||||
|
||||
## ---------------- ##
|
||||
## Default values. ##
|
||||
@@ -160,6 +161,9 @@ b4_copyright([Skeleton implementation for Bison's Yacc-like parsers in C],dnl '
|
||||
USER NAME SPACE" below. */
|
||||
|
||||
]b4_identification
|
||||
m4_ifdef([b4_percent_code_top],
|
||||
[[/* Copy the %code "top" blocks. */
|
||||
]b4_user_code([b4_percent_code_top])])[]dnl
|
||||
m4_if(b4_prefix, [yy], [],
|
||||
[[/* Substitute the variable and function names. */
|
||||
]b4_pull_if([[#define yyparse ]b4_prefix[parse
|
||||
@@ -197,9 +201,9 @@ m4_if(b4_prefix, [yy], [],
|
||||
# define YYTOKEN_TABLE ]b4_token_table[
|
||||
#endif
|
||||
|
||||
]m4_ifdef([b4_requires],
|
||||
[[/* Copy the %requires blocks. */
|
||||
]b4_user_requires])[]dnl
|
||||
]m4_ifdef([b4_percent_code_requires],
|
||||
[[/* Copy the %code "requires" blocks. */
|
||||
]b4_user_code([b4_percent_code_requires])])[]dnl
|
||||
|
||||
b4_token_enums_defines(b4_tokens)[
|
||||
|
||||
@@ -250,14 +254,18 @@ b4_c_function_decl([[yypstate_delete]], [[void]],
|
||||
[[[yypstate *yyps]], [[yyps]]])[
|
||||
#endif
|
||||
]])
|
||||
m4_ifdef([b4_provides],
|
||||
[[/* Copy the %provides blocks. */
|
||||
]b4_user_provides])[]dnl
|
||||
m4_ifdef([b4_percent_code_provides],
|
||||
[[/* Copy the %code "provides" blocks. */
|
||||
]b4_user_code([b4_percent_code_provides])])[]dnl
|
||||
|
||||
[/* Copy the second part of user declarations. */
|
||||
]b4_user_post_prologue[
|
||||
]b4_user_post_prologue
|
||||
m4_ifdef([b4_percent_code],
|
||||
[[/* Copy the unqualified %code blocks. */
|
||||
]b4_user_code([b4_percent_code])
|
||||
])[]dnl
|
||||
|
||||
#ifdef short
|
||||
[#ifdef short
|
||||
# undef short
|
||||
#endif
|
||||
|
||||
@@ -1655,9 +1663,9 @@ b4_defines_if(
|
||||
b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl '
|
||||
[1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])
|
||||
|
||||
m4_ifdef([b4_requires],
|
||||
[[/* Copy the %requires blocks. */
|
||||
]b4_user_requires])[]dnl
|
||||
m4_ifdef([b4_percent_code_requires],
|
||||
[[/* Copy the %code "requires" blocks. */
|
||||
]b4_user_code([b4_percent_code_requires])])[]dnl
|
||||
|
||||
b4_token_enums_defines(b4_tokens)
|
||||
|
||||
@@ -1714,7 +1722,7 @@ b4_c_function_decl([b4_prefix[pstate_delete]], [[void]],
|
||||
[[b4_prefix[pstate *yyps]], [[yyps]]])[
|
||||
#endif
|
||||
]])
|
||||
m4_ifdef([b4_provides],
|
||||
[[/* Copy the %provides blocks. */
|
||||
]b4_user_provides])[]
|
||||
m4_ifdef([b4_percent_code_provides],
|
||||
[[/* Copy the %code "provides" blocks. */
|
||||
]b4_user_code([b4_percent_code_provides])])[]
|
||||
])dnl b4_defines_if
|
||||
|
||||
36
data/yacc.c
36
data/yacc.c
@@ -24,6 +24,7 @@ m4_divert(-1) -*- C -*-
|
||||
b4_use_push_for_pull_if([m4_include(b4_pkgdatadir/[push.c])m4_exit])
|
||||
|
||||
m4_include(b4_pkgdatadir/[c.m4])
|
||||
b4_check_percent_code_qualifiers([[requires]], [[provides]], [[top]])
|
||||
|
||||
## ---------------- ##
|
||||
## Default values. ##
|
||||
@@ -152,6 +153,9 @@ b4_copyright([Skeleton implementation for Bison's Yacc-like parsers in C],dnl '
|
||||
USER NAME SPACE" below. */
|
||||
|
||||
]b4_identification
|
||||
m4_ifdef([b4_percent_code_top],
|
||||
[[/* Copy the %code "top" blocks. */
|
||||
]b4_user_code([b4_percent_code_top])])[]dnl
|
||||
m4_if(b4_prefix, [yy], [],
|
||||
[/* Substitute the variable and function names. */
|
||||
#define yyparse b4_prefix[]parse
|
||||
@@ -184,9 +188,9 @@ b4_locations_if([#define yylloc b4_prefix[]lloc])])[
|
||||
# define YYTOKEN_TABLE ]b4_token_table[
|
||||
#endif
|
||||
|
||||
]m4_ifdef([b4_requires],
|
||||
[[/* Copy the %requires blocks. */
|
||||
]b4_user_requires])[]dnl
|
||||
]m4_ifdef([b4_percent_code_requires],
|
||||
[[/* Copy the %code "requires" blocks. */
|
||||
]b4_user_code([b4_percent_code_requires])])[]dnl
|
||||
|
||||
b4_token_enums_defines(b4_tokens)[
|
||||
|
||||
@@ -216,14 +220,18 @@ typedef struct YYLTYPE
|
||||
# define YYLTYPE_IS_TRIVIAL 1
|
||||
#endif])
|
||||
|
||||
m4_ifdef([b4_provides],
|
||||
[[/* Copy the %provides blocks. */
|
||||
]b4_user_provides])[]dnl
|
||||
m4_ifdef([b4_percent_code_provides],
|
||||
[[/* Copy the %code "provides" blocks. */
|
||||
]b4_user_code([b4_percent_code_provides])])[]dnl
|
||||
|
||||
[/* Copy the second part of user declarations. */
|
||||
]b4_user_post_prologue[
|
||||
]b4_user_post_prologue
|
||||
m4_ifdef([b4_percent_code],
|
||||
[[/* Copy the unqualified %code blocks. */
|
||||
]b4_user_code([b4_percent_code])
|
||||
])[]dnl
|
||||
|
||||
#ifdef short
|
||||
[#ifdef short
|
||||
# undef short
|
||||
#endif
|
||||
|
||||
@@ -1492,9 +1500,9 @@ b4_defines_if(
|
||||
b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl '
|
||||
[1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])
|
||||
|
||||
m4_ifdef([b4_requires],
|
||||
[[/* Copy the %requires blocks. */
|
||||
]b4_user_requires])[]dnl
|
||||
m4_ifdef([b4_percent_code_requires],
|
||||
[[/* Copy the %code "requires" blocks. */
|
||||
]b4_user_code([b4_percent_code_requires])])[]dnl
|
||||
|
||||
b4_token_enums_defines(b4_tokens)
|
||||
|
||||
@@ -1532,7 +1540,7 @@ typedef struct YYLTYPE
|
||||
[extern YYLTYPE b4_prefix[]lloc;])
|
||||
)dnl b4_locations_if
|
||||
|
||||
m4_ifdef([b4_provides],
|
||||
[[/* Copy the %provides blocks. */
|
||||
]b4_user_provides])[]
|
||||
m4_ifdef([b4_percent_code_provides],
|
||||
[[/* Copy the %code "provides" blocks. */
|
||||
]b4_user_code([b4_percent_code_provides])])[]
|
||||
])dnl b4_defines_if
|
||||
|
||||
@@ -2681,17 +2681,20 @@ feature test macros can affect the behavior of Bison-generated
|
||||
@cindex Prologue Alternatives
|
||||
|
||||
@findex %code
|
||||
@findex %requires
|
||||
@findex %provides
|
||||
@findex %code-top
|
||||
@findex %code "requires"
|
||||
@findex %code "provides"
|
||||
@findex %code "top"
|
||||
(The prologue alternatives described here are experimental.
|
||||
More user feedback will help to determine whether they should become permanent
|
||||
features.)
|
||||
|
||||
The functionality of @var{Prologue} sections can often be subtle and
|
||||
inflexible.
|
||||
As an alternative, Bison provides a set of more explicit directives:
|
||||
@code{%code}, @code{%requires}, @code{%provides}, and @code{%code-top}.
|
||||
As an alternative, Bison provides a %code directive with an explicit qualifier
|
||||
field, which identifies the purpose of the code and thus the location(s) where
|
||||
Bison should generate it.
|
||||
For C/C++, the qualifier can be omitted for the default location, or it can be
|
||||
"requires", "provides", or "top".
|
||||
@xref{Table of Symbols,,Bison Symbols}.
|
||||
|
||||
Look again at the example of the previous section:
|
||||
@@ -2723,7 +2726,7 @@ For example, if you decide to override Bison's default definition for
|
||||
@code{YYLTYPE}, in which @var{Prologue} section should you write your new
|
||||
definition?
|
||||
You should write it in the first since Bison will insert that code into the
|
||||
parser code file @emph{before} the default @code{YYLTYPE} definition.
|
||||
parser source code file @emph{before} the default @code{YYLTYPE} definition.
|
||||
In which @var{Prologue} section should you prototype an internal function,
|
||||
@code{trace_token}, that accepts @code{YYLTYPE} and @code{yytokentype} as
|
||||
arguments?
|
||||
@@ -2739,16 +2742,19 @@ Second, what if there is no @code{%union}?
|
||||
In that case, the second kind of @var{Prologue} section is not available.
|
||||
This behavior is not intuitive.
|
||||
|
||||
To avoid this subtle @code{%union} dependency, rewrite the example using
|
||||
@code{%code-top} and @code{%code}.
|
||||
To avoid this subtle @code{%union} dependency, rewrite the example using a
|
||||
@code{%code "top"} and an unqualified @code{%code}.
|
||||
Let's go ahead and add the new @code{YYLTYPE} definition and the
|
||||
@code{trace_token} prototype at the same time:
|
||||
|
||||
@smallexample
|
||||
%code-top @{
|
||||
%code "top" @{
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
/* The following code really belongs in a %requires; see below. */
|
||||
|
||||
/* WARNING: The following code really belongs
|
||||
* in a %code "requires"; see below. */
|
||||
|
||||
#include "ptypes.h"
|
||||
#define YYLTYPE YYLTYPE
|
||||
typedef struct YYLTYPE
|
||||
@@ -2776,33 +2782,34 @@ Let's go ahead and add the new @code{YYLTYPE} definition and the
|
||||
@end smallexample
|
||||
|
||||
@noindent
|
||||
In this way, @code{%code-top} and @code{%code} achieve the same functionality
|
||||
as the two kinds of @var{Prologue} sections, but it's always explicit which
|
||||
kind you intend.
|
||||
In this way, @code{%code "top"} and the unqualified @code{%code} achieve the
|
||||
same functionality as the two kinds of @var{Prologue} sections, but it's always
|
||||
explicit which kind you intend.
|
||||
Moreover, both kinds are always available even in the absence of @code{%union}.
|
||||
|
||||
The @code{%code-top} block above logically contains two parts.
|
||||
The first two lines need to appear in the parser code file.
|
||||
The fourth line is required by @code{YYSTYPE} and thus also needs to appear in
|
||||
the parser code file.
|
||||
The @code{%code "top"} block above logically contains two parts.
|
||||
The first two lines before the warning need to appear near the top of the
|
||||
parser source code file.
|
||||
The first line after the warning is required by @code{YYSTYPE} and thus also
|
||||
needs to appear in the parser source code file.
|
||||
However, if you've instructed Bison to generate a parser header file
|
||||
(@pxref{Table of Symbols, ,%defines}), you probably want the fourth line to
|
||||
appear before the @code{YYSTYPE} definition in that header file as well.
|
||||
Also, the @code{YYLTYPE} definition should appear in the parser header file to
|
||||
(@pxref{Table of Symbols, ,%defines}), you probably want that line to appear
|
||||
before the @code{YYSTYPE} definition in that header file as well.
|
||||
The @code{YYLTYPE} definition should also appear in the parser header file to
|
||||
override the default @code{YYLTYPE} definition there.
|
||||
|
||||
In other words, in the @code{%code-top} block above, all but the first two
|
||||
lines are dependency code for externally exposed definitions (@code{YYSTYPE}
|
||||
and @code{YYLTYPE}) required by Bison.
|
||||
Thus, they belong in one or more @code{%requires}:
|
||||
In other words, in the @code{%code "top"} block above, all but the first two
|
||||
lines are dependency code required by the @code{YYSTYPE} and @code{YYLTYPE}
|
||||
definitions.
|
||||
Thus, they belong in one or more @code{%code "requires"}:
|
||||
|
||||
@smallexample
|
||||
%code-top @{
|
||||
%code "top" @{
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
@}
|
||||
|
||||
%requires @{
|
||||
%code "requires" @{
|
||||
#include "ptypes.h"
|
||||
@}
|
||||
%union @{
|
||||
@@ -2810,7 +2817,7 @@ Thus, they belong in one or more @code{%requires}:
|
||||
tree t; /* @r{@code{tree} is defined in @file{ptypes.h}.} */
|
||||
@}
|
||||
|
||||
%requires @{
|
||||
%code "requires" @{
|
||||
#define YYLTYPE YYLTYPE
|
||||
typedef struct YYLTYPE
|
||||
@{
|
||||
@@ -2834,40 +2841,41 @@ Thus, they belong in one or more @code{%requires}:
|
||||
@noindent
|
||||
Now Bison will insert @code{#include "ptypes.h"} and the new @code{YYLTYPE}
|
||||
definition before the Bison-generated @code{YYSTYPE} and @code{YYLTYPE}
|
||||
definitions in both the parser code file and the parser header file.
|
||||
(By the same reasoning, @code{%requires} would also be the appropriate place to
|
||||
write your own definition for @code{YYSTYPE}.)
|
||||
definitions in both the parser source code file and the parser header file.
|
||||
(By the same reasoning, @code{%code "requires"} would also be the appropriate
|
||||
place to write your own definition for @code{YYSTYPE}.)
|
||||
|
||||
When you are writing dependency code for @code{YYSTYPE} and @code{YYLTYPE}, you
|
||||
should prefer @code{%requires} over @code{%code-top} regardless of whether you
|
||||
instruct Bison to generate a parser header file.
|
||||
should prefer @code{%code "requires"} over @code{%code "top"} regardless of
|
||||
whether you instruct Bison to generate a parser header file.
|
||||
When you are writing code that you need Bison to insert only into the parser
|
||||
code file and that has no special need to appear at the top of the code file,
|
||||
you should prefer @code{%code} over @code{%code-top}.
|
||||
source code file and that has no special need to appear at the top of that
|
||||
file, you should prefer the unqualified @code{%code} over @code{%code "top"}.
|
||||
These practices will make the purpose of each block of your code explicit to
|
||||
Bison and to other developers reading your grammar file.
|
||||
Following these practices, we expect @code{%code} and @code{%requires} to be
|
||||
the most important of the four @var{Prologue} alternative directives discussed
|
||||
in this section.
|
||||
Following these practices, we expect the unqualified @code{%code} and
|
||||
@code{%code "requires"} to be the most important of the four @var{Prologue}
|
||||
alternatives discussed in this section.
|
||||
|
||||
At some point while developing your parser, you might decide to provide
|
||||
@code{trace_token} to modules that are external to your parser.
|
||||
Thus, you might wish for Bison to insert the prototype into both the parser
|
||||
header file and the parser code file.
|
||||
Since this function is not a dependency of any Bison-required definition (such
|
||||
as @code{YYSTYPE}), it doesn't make sense to move its prototype to a
|
||||
@code{%requires}.
|
||||
header file and the parser source code file.
|
||||
Since this function is not a dependency required by @code{YYSTYPE} or
|
||||
@code{YYLTYPE}, it doesn't make sense to move its prototype to a
|
||||
@code{%code "requires"}.
|
||||
More importantly, since it depends upon @code{YYLTYPE} and @code{yytokentype},
|
||||
@code{%requires} is not sufficient.
|
||||
Instead, move its prototype from the @code{%code} to a @code{%provides}:
|
||||
@code{%code "requires"} is not sufficient.
|
||||
Instead, move its prototype from the unqualified @code{%code} to a
|
||||
@code{%code "provides"}:
|
||||
|
||||
@smallexample
|
||||
%code-top @{
|
||||
%code "top" @{
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
@}
|
||||
|
||||
%requires @{
|
||||
%code "requires" @{
|
||||
#include "ptypes.h"
|
||||
@}
|
||||
%union @{
|
||||
@@ -2875,7 +2883,7 @@ Instead, move its prototype from the @code{%code} to a @code{%provides}:
|
||||
tree t; /* @r{@code{tree} is defined in @file{ptypes.h}.} */
|
||||
@}
|
||||
|
||||
%requires @{
|
||||
%code "requires" @{
|
||||
#define YYLTYPE YYLTYPE
|
||||
typedef struct YYLTYPE
|
||||
@{
|
||||
@@ -2887,7 +2895,7 @@ Instead, move its prototype from the @code{%code} to a @code{%provides}:
|
||||
@} YYLTYPE;
|
||||
@}
|
||||
|
||||
%provides @{
|
||||
%code "provides" @{
|
||||
void trace_token (enum yytokentype token, YYLTYPE loc);
|
||||
@}
|
||||
|
||||
@@ -2901,12 +2909,13 @@ Instead, move its prototype from the @code{%code} to a @code{%provides}:
|
||||
|
||||
@noindent
|
||||
Bison will insert the @code{trace_token} prototype into both the parser header
|
||||
file and the parser code file after the definitions for @code{yytokentype},
|
||||
@code{YYLTYPE}, and @code{YYSTYPE}.
|
||||
file and the parser source code file after the definitions for
|
||||
@code{yytokentype}, @code{YYLTYPE}, and @code{YYSTYPE}.
|
||||
|
||||
The above examples are careful to write directives in an order that reflects
|
||||
the layout of the generated parser code and header files:
|
||||
@code{%code-top}, @code{%requires}, @code{%provides}, and then @code{%code}.
|
||||
the layout of the generated parser source code and header files:
|
||||
@code{%code "top"}, @code{%code "requires"}, @code{%code "provides"}, and then
|
||||
@code{%code}.
|
||||
While your grammar files may generally be easier to read if you also follow
|
||||
this order, Bison does not require it.
|
||||
Instead, Bison lets you choose an organization that makes sense to you.
|
||||
@@ -2922,12 +2931,12 @@ For example, you may organize semantic-type-related directives by semantic
|
||||
type:
|
||||
|
||||
@smallexample
|
||||
%requires @{ #include "type1.h" @}
|
||||
%code "requires" @{ #include "type1.h" @}
|
||||
%union @{ type1 field1; @}
|
||||
%destructor @{ type1_free ($$); @} <field1>
|
||||
%printer @{ type1_print ($$); @} <field1>
|
||||
|
||||
%requires @{ #include "type2.h" @}
|
||||
%code "requires" @{ #include "type2.h" @}
|
||||
%union @{ type2 field2; @}
|
||||
%destructor @{ type2_free ($$); @} <field2>
|
||||
%printer @{ type2_print ($$); @} <field2>
|
||||
@@ -2943,13 +2952,14 @@ counter-intuitive manner just because it comes first.
|
||||
Such an organization is not possible using @var{Prologue} sections.
|
||||
|
||||
This section has been concerned with explaining the advantages of the four
|
||||
@var{Prologue} alternative directives over the original Yacc @var{Prologue}.
|
||||
@var{Prologue} alternatives over the original Yacc @var{Prologue}.
|
||||
However, in most cases when using these directives, you shouldn't need to
|
||||
think about all the low-level ordering issues discussed here.
|
||||
Instead, you should simply use these directives to label each block of your
|
||||
code according to its purpose and let Bison handle the ordering.
|
||||
@code{%code} is the most generic label.
|
||||
Move code to @code{%requires}, @code{%provides}, or @code{%code-top} as needed.
|
||||
Move code to @code{%code "requires"}, @code{%code "provides"}, or
|
||||
@code{%code "top"} as needed.
|
||||
|
||||
@node Bison Declarations
|
||||
@subsection The Bison Declarations Section
|
||||
@@ -4598,11 +4608,11 @@ typically needs to be able to refer to the above-mentioned declarations
|
||||
and to the token type codes. @xref{Token Values, ,Semantic Values of
|
||||
Tokens}.
|
||||
|
||||
@findex %requires
|
||||
@findex %provides
|
||||
If you have declared @code{%requires} or @code{%provides}, the output
|
||||
header also contains their code.
|
||||
@xref{Table of Symbols, ,%requires}.
|
||||
@findex %code "requires"
|
||||
@findex %code "provides"
|
||||
If you have declared @code{%code "requires"} or @code{%code "provides"}, the
|
||||
output header also contains their code.
|
||||
@xref{Table of Symbols, ,%code}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} %defines @var{defines-file}
|
||||
@@ -7863,18 +7873,18 @@ the grammar for.
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
@findex %requires
|
||||
@findex %code "requires"
|
||||
Then come the declarations/inclusions needed to define the
|
||||
@code{%union}. Because the parser uses the parsing driver and
|
||||
reciprocally, both cannot include the header of the other. Because the
|
||||
driver's header needs detailed knowledge about the parser class (in
|
||||
particular its inner types), it is the parser's header which will simply
|
||||
use a forward declaration of the driver.
|
||||
@xref{Table of Symbols, ,%requires}.
|
||||
@xref{Table of Symbols, ,%code}.
|
||||
|
||||
@comment file: calc++-parser.yy
|
||||
@example
|
||||
%requires @{
|
||||
%code "requires" @{
|
||||
# include <string>
|
||||
class calcxx_driver;
|
||||
@}
|
||||
@@ -8634,63 +8644,109 @@ Start-Symbol}. It cannot be used in the grammar.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} %code @{@var{code}@}
|
||||
Other than semantic actions, this is probably the most common place you should
|
||||
write verbatim code for the parser implementation.
|
||||
It replaces the traditional Yacc prologue,
|
||||
@comment For C/C++, it replaces the traditional Yacc prologue,
|
||||
@code{%@{@var{code}%@}}, for most purposes.
|
||||
@comment For Java, it inserts code into the parser class.
|
||||
@findex %code
|
||||
This is the unqualified form of the @code{%code} directive.
|
||||
It inserts @var{code} verbatim at the default location in the output.
|
||||
That default location is determined by the selected target language and/or
|
||||
parser skeleton.
|
||||
|
||||
@cindex Prologue
|
||||
@findex %union
|
||||
Compare with @code{%@{@var{code}%@}} (@pxref{Prologue, ,The Prologue})
|
||||
appearing after the first @code{%union @{@var{code}@}} in a C/C++ based grammar
|
||||
file.
|
||||
While Bison will continue to support @code{%@{@var{code}%@}} for backward
|
||||
compatibility, @code{%code @{@var{code}@}} is cleaner as its functionality does
|
||||
not depend on its position in the grammar file relative to any
|
||||
@code{%union @{@var{code}@}}.
|
||||
Specifically, @code{%code @{@var{code}@}} always inserts your @var{code} into
|
||||
the parser code file after the usual contents of the parser header file.
|
||||
For the current C/C++ skeletons, the default location is the parser source code
|
||||
file after the usual contents of the parser header file.
|
||||
Thus, @code{%code} replaces the traditional Yacc prologue,
|
||||
@code{%@{@var{code}%@}}, for most purposes.
|
||||
For a detailed discussion, see @ref{Prologue Alternatives}.
|
||||
|
||||
(Like all the Yacc prologue alternative directives, this directive is
|
||||
experimental.
|
||||
@comment For Java, the default location is inside the parser class.
|
||||
|
||||
(Like all the Yacc prologue alternatives, this directive is experimental.
|
||||
More user feedback will help to determine whether it should become a permanent
|
||||
feature.)
|
||||
|
||||
@xref{Prologue Alternatives}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} %code-top @{@var{code}@}
|
||||
Occasionally it is desirable to insert code near the top of the
|
||||
@comment Occasionally for C/C++ it is desirable to insert code near the top of the
|
||||
parser code file.
|
||||
@deffn {Directive} %code "@var{qualifier}" @{@var{code}@}
|
||||
This is the qualified form of the @code{%code} directive.
|
||||
If you need to specify location-sensitive verbatim @var{code} that does not
|
||||
belong at the default location selected by the unqualified @code{%code} form,
|
||||
use this form instead.
|
||||
|
||||
@var{qualifier} identifies the purpose of @var{code} and thus the location(s)
|
||||
where Bison should generate it.
|
||||
Not all values of @var{qualifier} are available for all target languages:
|
||||
|
||||
@itemize @bullet
|
||||
@findex %code "requires"
|
||||
@item "requires"
|
||||
|
||||
@itemize @bullet
|
||||
@item Language(s): C, C++
|
||||
|
||||
@item Purpose: This is the best place to write dependency code required for
|
||||
@code{YYSTYPE} and @code{YYLTYPE}.
|
||||
In other words, it's the best place to define types referenced in @code{%union}
|
||||
directives, and it's the best place to override Bison's default @code{YYSTYPE}
|
||||
and @code{YYLTYPE} definitions.
|
||||
|
||||
@item Location(s): The parser header file and the parser source code file
|
||||
before the Bison-generated @code{YYSTYPE} and @code{YYLTYPE} definitions.
|
||||
@end itemize
|
||||
|
||||
@item "provides"
|
||||
@findex %code "provides"
|
||||
|
||||
@itemize @bullet
|
||||
@item Language(s): C, C++
|
||||
|
||||
@item Purpose: This is the best place to write additional definitions and
|
||||
declarations that should be provided to other modules.
|
||||
|
||||
@item Location(s): The parser header file and the parser source code file after
|
||||
the Bison-generated @code{YYSTYPE}, @code{YYLTYPE}, and token definitions.
|
||||
@end itemize
|
||||
|
||||
@item "top"
|
||||
@findex %code "top"
|
||||
|
||||
@itemize @bullet
|
||||
@item Language(s): C, C++
|
||||
|
||||
@item Purpose: The unqualified @code{%code} or @code{%code "requires"} should
|
||||
usually be more appropriate than @code{%code "top"}.
|
||||
However, occasionally it is necessary to insert code much nearer the top of the
|
||||
parser source code file.
|
||||
For example:
|
||||
|
||||
@smallexample
|
||||
%code-top @{
|
||||
%code "top" @{
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
@}
|
||||
@end smallexample
|
||||
|
||||
@comment @noindent
|
||||
@comment For Java, @code{%code-top @{@var{code}@}} is currently unused.
|
||||
@item Location(s): Near the top of the parser source code file.
|
||||
@end itemize
|
||||
@ignore
|
||||
@item "imports"
|
||||
@findex %code "imports"
|
||||
|
||||
@cindex Prologue
|
||||
@findex %union
|
||||
Compare with @code{%@{@var{code}%@}} appearing before the first
|
||||
@code{%union @{@var{code}@}} in a C/C++ based grammar file.
|
||||
@code{%code-top @{@var{code}@}} is cleaner as its functionality does not depend
|
||||
on its position in the grammar file relative to any
|
||||
@code{%union @{@var{code}@}}.
|
||||
@itemize @bullet
|
||||
@item Language(s): Java
|
||||
|
||||
(Like all the Yacc prologue alternative directives, this directive is
|
||||
experimental.
|
||||
@item Purpose: This is the best place to write Java import directives.
|
||||
|
||||
@item Location(s): The parser Java file after any Java package directive and
|
||||
before any class definitions.
|
||||
@end itemize
|
||||
@end ignore
|
||||
@end itemize
|
||||
|
||||
(Like all the Yacc prologue alternatives, this directive is experimental.
|
||||
More user feedback will help to determine whether it should become a permanent
|
||||
feature.)
|
||||
|
||||
@xref{Prologue Alternatives}.
|
||||
@cindex Prologue
|
||||
For a detailed discussion of how to use @code{%code} in place of the
|
||||
traditional Yacc prologue for C/C++, see @ref{Prologue Alternatives}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} %debug
|
||||
@@ -8826,24 +8882,6 @@ Bison declaration to assign a precedence to a specific rule.
|
||||
@xref{Contextual Precedence, ,Context-Dependent Precedence}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} %provides @{@var{code}@}
|
||||
This is the right place to write additional definitions you would like Bison to
|
||||
expose externally.
|
||||
That is, this directive inserts your @var{code} both into the parser header
|
||||
@comment For C/C++, this directive inserts your @var{code} both into the parser header
|
||||
file (if generated; @pxref{Table of Symbols, ,%defines}) and into the parser
|
||||
code file after Bison's required definitions.
|
||||
@comment For Java, it inserts your @var{code} into the parser java file after the parser
|
||||
@comment class.
|
||||
|
||||
(Like all the Yacc prologue alternative directives, this directive is
|
||||
experimental.
|
||||
More user feedback will help to determine whether it should become a permanent
|
||||
feature.)
|
||||
|
||||
@xref{Prologue Alternatives}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} %pure-parser
|
||||
Bison declaration to request a pure (reentrant) parser.
|
||||
@xref{Pure Decl, ,A Pure (Reentrant) Parser}.
|
||||
@@ -8854,35 +8892,6 @@ Require version @var{version} or higher of Bison. @xref{Require Decl, ,
|
||||
Require a Version of Bison}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} %requires @{@var{code}@}
|
||||
This is the right place to write dependency code for externally exposed
|
||||
definitions required by Bison.
|
||||
Such exposed definitions are those usually appearing in the parser
|
||||
@comment For C/C++, such exposed definitions are those usually appearing in the parser
|
||||
header file.
|
||||
Thus, this is the right place to define types referenced in
|
||||
@code{%union @{@var{code}@}} directives, and it is the right place to override
|
||||
Bison's default @code{YYSTYPE} and @code{YYLTYPE} definitions.
|
||||
@comment For Java, this is the right place to write import directives.
|
||||
|
||||
@cindex Prologue
|
||||
@findex %union
|
||||
Compare with @code{%@{@var{code}%@}} (@pxref{Prologue, ,The Prologue})
|
||||
appearing before the first @code{%union @{@var{code}@}} in a C/C++ based
|
||||
grammar file.
|
||||
Unlike @code{%@{@var{code}%@}}, @code{%requires @{@var{code}@}} inserts your
|
||||
@var{code} both into the parser code file and into the parser header file (if
|
||||
generated; @pxref{Table of Symbols, ,%defines}) since Bison's required
|
||||
definitions should depend on it in both places.
|
||||
|
||||
(Like all the Yacc prologue alternative directives, this directive is
|
||||
experimental.
|
||||
More user feedback will help to determine whether it should become a permanent
|
||||
feature.)
|
||||
|
||||
@xref{Prologue Alternatives}.
|
||||
@end deffn
|
||||
|
||||
@deffn {Directive} %right
|
||||
Bison declaration to assign right associativity to token(s).
|
||||
@xref{Precedence Decl, ,Operator Precedence}.
|
||||
|
||||
1195
src/parse-gram.c
1195
src/parse-gram.c
File diff suppressed because it is too large
Load Diff
180
src/parse-gram.h
180
src/parse-gram.h
@@ -55,51 +55,48 @@
|
||||
PERCENT_DPREC = 269,
|
||||
PERCENT_MERGE = 270,
|
||||
PERCENT_CODE = 271,
|
||||
PERCENT_CODE_TOP = 272,
|
||||
PERCENT_DEBUG = 273,
|
||||
PERCENT_DEFAULT_PREC = 274,
|
||||
PERCENT_DEFINE = 275,
|
||||
PERCENT_DEFINES = 276,
|
||||
PERCENT_ERROR_VERBOSE = 277,
|
||||
PERCENT_EXPECT = 278,
|
||||
PERCENT_EXPECT_RR = 279,
|
||||
PERCENT_FILE_PREFIX = 280,
|
||||
PERCENT_GLR_PARSER = 281,
|
||||
PERCENT_INITIAL_ACTION = 282,
|
||||
PERCENT_LANGUAGE = 283,
|
||||
PERCENT_LEX_PARAM = 284,
|
||||
PERCENT_LOCATIONS = 285,
|
||||
PERCENT_NAME_PREFIX = 286,
|
||||
PERCENT_NO_DEFAULT_PREC = 287,
|
||||
PERCENT_NO_LINES = 288,
|
||||
PERCENT_NONDETERMINISTIC_PARSER = 289,
|
||||
PERCENT_OUTPUT = 290,
|
||||
PERCENT_PARSE_PARAM = 291,
|
||||
PERCENT_PROVIDES = 292,
|
||||
PERCENT_PURE_PARSER = 293,
|
||||
PERCENT_PUSH_PARSER = 294,
|
||||
PERCENT_PUSH_PULL_PARSER = 295,
|
||||
PERCENT_REQUIRE = 296,
|
||||
PERCENT_REQUIRES = 297,
|
||||
PERCENT_SKELETON = 298,
|
||||
PERCENT_START = 299,
|
||||
PERCENT_TOKEN_TABLE = 300,
|
||||
PERCENT_VERBOSE = 301,
|
||||
PERCENT_YACC = 302,
|
||||
BRACED_CODE = 303,
|
||||
CHAR = 304,
|
||||
EPILOGUE = 305,
|
||||
EQUAL = 306,
|
||||
ID = 307,
|
||||
ID_COLON = 308,
|
||||
PERCENT_PERCENT = 309,
|
||||
PIPE = 310,
|
||||
PROLOGUE = 311,
|
||||
SEMICOLON = 312,
|
||||
TYPE = 313,
|
||||
TYPE_TAG_ANY = 314,
|
||||
TYPE_TAG_NONE = 315,
|
||||
PERCENT_UNION = 316
|
||||
PERCENT_DEBUG = 272,
|
||||
PERCENT_DEFAULT_PREC = 273,
|
||||
PERCENT_DEFINE = 274,
|
||||
PERCENT_DEFINES = 275,
|
||||
PERCENT_ERROR_VERBOSE = 276,
|
||||
PERCENT_EXPECT = 277,
|
||||
PERCENT_EXPECT_RR = 278,
|
||||
PERCENT_FILE_PREFIX = 279,
|
||||
PERCENT_GLR_PARSER = 280,
|
||||
PERCENT_INITIAL_ACTION = 281,
|
||||
PERCENT_LANGUAGE = 282,
|
||||
PERCENT_LEX_PARAM = 283,
|
||||
PERCENT_LOCATIONS = 284,
|
||||
PERCENT_NAME_PREFIX = 285,
|
||||
PERCENT_NO_DEFAULT_PREC = 286,
|
||||
PERCENT_NO_LINES = 287,
|
||||
PERCENT_NONDETERMINISTIC_PARSER = 288,
|
||||
PERCENT_OUTPUT = 289,
|
||||
PERCENT_PARSE_PARAM = 290,
|
||||
PERCENT_PURE_PARSER = 291,
|
||||
PERCENT_PUSH_PARSER = 292,
|
||||
PERCENT_PUSH_PULL_PARSER = 293,
|
||||
PERCENT_REQUIRE = 294,
|
||||
PERCENT_SKELETON = 295,
|
||||
PERCENT_START = 296,
|
||||
PERCENT_TOKEN_TABLE = 297,
|
||||
PERCENT_VERBOSE = 298,
|
||||
PERCENT_YACC = 299,
|
||||
BRACED_CODE = 300,
|
||||
CHAR = 301,
|
||||
EPILOGUE = 302,
|
||||
EQUAL = 303,
|
||||
ID = 304,
|
||||
ID_COLON = 305,
|
||||
PERCENT_PERCENT = 306,
|
||||
PIPE = 307,
|
||||
PROLOGUE = 308,
|
||||
SEMICOLON = 309,
|
||||
TYPE = 310,
|
||||
TYPE_TAG_ANY = 311,
|
||||
TYPE_TAG_NONE = 312,
|
||||
PERCENT_UNION = 313
|
||||
};
|
||||
#endif
|
||||
/* Tokens. */
|
||||
@@ -118,51 +115,48 @@
|
||||
#define PERCENT_DPREC 269
|
||||
#define PERCENT_MERGE 270
|
||||
#define PERCENT_CODE 271
|
||||
#define PERCENT_CODE_TOP 272
|
||||
#define PERCENT_DEBUG 273
|
||||
#define PERCENT_DEFAULT_PREC 274
|
||||
#define PERCENT_DEFINE 275
|
||||
#define PERCENT_DEFINES 276
|
||||
#define PERCENT_ERROR_VERBOSE 277
|
||||
#define PERCENT_EXPECT 278
|
||||
#define PERCENT_EXPECT_RR 279
|
||||
#define PERCENT_FILE_PREFIX 280
|
||||
#define PERCENT_GLR_PARSER 281
|
||||
#define PERCENT_INITIAL_ACTION 282
|
||||
#define PERCENT_LANGUAGE 283
|
||||
#define PERCENT_LEX_PARAM 284
|
||||
#define PERCENT_LOCATIONS 285
|
||||
#define PERCENT_NAME_PREFIX 286
|
||||
#define PERCENT_NO_DEFAULT_PREC 287
|
||||
#define PERCENT_NO_LINES 288
|
||||
#define PERCENT_NONDETERMINISTIC_PARSER 289
|
||||
#define PERCENT_OUTPUT 290
|
||||
#define PERCENT_PARSE_PARAM 291
|
||||
#define PERCENT_PROVIDES 292
|
||||
#define PERCENT_PURE_PARSER 293
|
||||
#define PERCENT_PUSH_PARSER 294
|
||||
#define PERCENT_PUSH_PULL_PARSER 295
|
||||
#define PERCENT_REQUIRE 296
|
||||
#define PERCENT_REQUIRES 297
|
||||
#define PERCENT_SKELETON 298
|
||||
#define PERCENT_START 299
|
||||
#define PERCENT_TOKEN_TABLE 300
|
||||
#define PERCENT_VERBOSE 301
|
||||
#define PERCENT_YACC 302
|
||||
#define BRACED_CODE 303
|
||||
#define CHAR 304
|
||||
#define EPILOGUE 305
|
||||
#define EQUAL 306
|
||||
#define ID 307
|
||||
#define ID_COLON 308
|
||||
#define PERCENT_PERCENT 309
|
||||
#define PIPE 310
|
||||
#define PROLOGUE 311
|
||||
#define SEMICOLON 312
|
||||
#define TYPE 313
|
||||
#define TYPE_TAG_ANY 314
|
||||
#define TYPE_TAG_NONE 315
|
||||
#define PERCENT_UNION 316
|
||||
#define PERCENT_DEBUG 272
|
||||
#define PERCENT_DEFAULT_PREC 273
|
||||
#define PERCENT_DEFINE 274
|
||||
#define PERCENT_DEFINES 275
|
||||
#define PERCENT_ERROR_VERBOSE 276
|
||||
#define PERCENT_EXPECT 277
|
||||
#define PERCENT_EXPECT_RR 278
|
||||
#define PERCENT_FILE_PREFIX 279
|
||||
#define PERCENT_GLR_PARSER 280
|
||||
#define PERCENT_INITIAL_ACTION 281
|
||||
#define PERCENT_LANGUAGE 282
|
||||
#define PERCENT_LEX_PARAM 283
|
||||
#define PERCENT_LOCATIONS 284
|
||||
#define PERCENT_NAME_PREFIX 285
|
||||
#define PERCENT_NO_DEFAULT_PREC 286
|
||||
#define PERCENT_NO_LINES 287
|
||||
#define PERCENT_NONDETERMINISTIC_PARSER 288
|
||||
#define PERCENT_OUTPUT 289
|
||||
#define PERCENT_PARSE_PARAM 290
|
||||
#define PERCENT_PURE_PARSER 291
|
||||
#define PERCENT_PUSH_PARSER 292
|
||||
#define PERCENT_PUSH_PULL_PARSER 293
|
||||
#define PERCENT_REQUIRE 294
|
||||
#define PERCENT_SKELETON 295
|
||||
#define PERCENT_START 296
|
||||
#define PERCENT_TOKEN_TABLE 297
|
||||
#define PERCENT_VERBOSE 298
|
||||
#define PERCENT_YACC 299
|
||||
#define BRACED_CODE 300
|
||||
#define CHAR 301
|
||||
#define EPILOGUE 302
|
||||
#define EQUAL 303
|
||||
#define ID 304
|
||||
#define ID_COLON 305
|
||||
#define PERCENT_PERCENT 306
|
||||
#define PIPE 307
|
||||
#define PROLOGUE 308
|
||||
#define SEMICOLON 309
|
||||
#define TYPE 310
|
||||
#define TYPE_TAG_ANY 311
|
||||
#define TYPE_TAG_NONE 312
|
||||
#define PERCENT_UNION 313
|
||||
|
||||
|
||||
|
||||
@@ -170,7 +164,7 @@
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef union YYSTYPE
|
||||
{
|
||||
/* Line 1538 of yacc.c */
|
||||
/* Line 1546 of yacc.c */
|
||||
#line 98 "parse-gram.y"
|
||||
|
||||
symbol *symbol;
|
||||
@@ -183,8 +177,8 @@ typedef union YYSTYPE
|
||||
unsigned char character;
|
||||
}
|
||||
|
||||
/* Line 1538 of yacc.c */
|
||||
#line 188 "parse-gram.h"
|
||||
/* Line 1546 of yacc.c */
|
||||
#line 182 "parse-gram.h"
|
||||
YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
|
||||
@@ -133,7 +133,6 @@ static int current_prec = 0;
|
||||
|
||||
%token
|
||||
PERCENT_CODE "%code"
|
||||
PERCENT_CODE_TOP "%code-top"
|
||||
PERCENT_DEBUG "%debug"
|
||||
PERCENT_DEFAULT_PREC "%default-prec"
|
||||
PERCENT_DEFINE "%define"
|
||||
@@ -154,13 +153,11 @@ static int current_prec = 0;
|
||||
"%nondeterministic-parser"
|
||||
PERCENT_OUTPUT "%output"
|
||||
PERCENT_PARSE_PARAM "%parse-param"
|
||||
PERCENT_PROVIDES "%provides"
|
||||
PERCENT_PURE_PARSER "%pure-parser"
|
||||
PERCENT_PUSH_PARSER "%push-parser"
|
||||
PERCENT_PUSH_PULL_PARSER
|
||||
"%push-pull-parser"
|
||||
PERCENT_REQUIRE "%require"
|
||||
PERCENT_REQUIRES "%requires"
|
||||
PERCENT_SKELETON "%skeleton"
|
||||
PERCENT_START "%start"
|
||||
PERCENT_TOKEN_TABLE "%token-table"
|
||||
@@ -312,10 +309,22 @@ grammar_declaration:
|
||||
{
|
||||
default_prec = false;
|
||||
}
|
||||
| "%code" braceless { prologue_augment ($2, @2, true); }
|
||||
| "%code-top" braceless { prologue_augment ($2, @2, false); }
|
||||
| "%provides" braceless { muscle_code_grow ("provides", $2, @2); }
|
||||
| "%requires" braceless { muscle_code_grow ("requires", $2, @2); }
|
||||
| "%code" braceless
|
||||
{
|
||||
muscle_code_grow ("percent_code", $2, @2);
|
||||
code_scanner_last_string_free ();
|
||||
}
|
||||
| "%code" STRING braceless
|
||||
{
|
||||
char const name_prefix[] = "percent_code_";
|
||||
char *name = xmalloc (sizeof name_prefix + strlen ($2));
|
||||
strcpy (name, name_prefix);
|
||||
strcpy (name + sizeof name_prefix - 1, $2);
|
||||
muscle_code_grow (uniqstr_new (name), $3, @3);
|
||||
free (name);
|
||||
code_scanner_last_string_free ();
|
||||
muscle_grow ("used_percent_code_qualifiers", $2, ",");
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
|
||||
@@ -159,7 +159,6 @@ splice (\\[ \f\t\v]*\n)*
|
||||
{
|
||||
"%binary" return PERCENT_NONASSOC;
|
||||
"%code" return PERCENT_CODE;
|
||||
"%code-top" return PERCENT_CODE_TOP;
|
||||
"%debug" return PERCENT_DEBUG;
|
||||
"%default"[-_]"prec" return PERCENT_DEFAULT_PREC;
|
||||
"%define" return PERCENT_DEFINE;
|
||||
@@ -188,12 +187,10 @@ splice (\\[ \f\t\v]*\n)*
|
||||
"%parse-param" return PERCENT_PARSE_PARAM;
|
||||
"%prec" return PERCENT_PREC;
|
||||
"%printer" return PERCENT_PRINTER;
|
||||
"%provides" return PERCENT_PROVIDES;
|
||||
"%pure"[-_]"parser" return PERCENT_PURE_PARSER;
|
||||
"%push-parser" return PERCENT_PUSH_PARSER;
|
||||
"%push-pull-parser" return PERCENT_PUSH_PULL_PARSER;
|
||||
"%require" return PERCENT_REQUIRE;
|
||||
"%requires" return PERCENT_REQUIRES;
|
||||
"%right" return PERCENT_RIGHT;
|
||||
"%skeleton" return PERCENT_SKELETON;
|
||||
"%start" return PERCENT_START;
|
||||
|
||||
@@ -178,7 +178,7 @@ m4_if([$1$2$3], $[1]$[2]$[3], [],
|
||||
# helping macros. So don't put any directly in the Bison file.
|
||||
AT_BISON_OPTION_PUSHDEFS([$5])
|
||||
AT_DATA_GRAMMAR([[input.y]],
|
||||
[[%requires {
|
||||
[[%code "requires" {
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -197,7 +197,7 @@ m4_ifval([$6], [%union
|
||||
int ival;
|
||||
}])
|
||||
AT_LALR1_CC_IF([%define "global_tokens_and_yystype"])
|
||||
m4_ifval([$6], [[%provides {]], [[%code {]])
|
||||
m4_ifval([$6], [[%code "provides" {]], [[%code {]])
|
||||
AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])
|
||||
[static int yylex (]AT_LEX_FORMALS[);
|
||||
]AT_LALR1_CC_IF([], [static void yyerror (const char *msg);])
|
||||
|
||||
@@ -701,3 +701,40 @@ AT_CHECK([bison input.y], [1], [],
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## ----------------------------- ##
|
||||
## Reject bad %code qualifiers. ##
|
||||
## ----------------------------- ##
|
||||
|
||||
AT_SETUP([Reject bad %code qualifiers])
|
||||
|
||||
AT_DATA([input-c.y],
|
||||
[[%code "" {}
|
||||
%%
|
||||
start: ;
|
||||
]])
|
||||
AT_CHECK([[bison input-c.y 2>&1 | grep 'error: `'"' is not a recognized" > /dev/null]])
|
||||
|
||||
AT_DATA([input-c-glr.y],
|
||||
[[%code "bad" {}
|
||||
%%
|
||||
start: ;
|
||||
]])
|
||||
AT_CHECK([[bison input-c-glr.y 2>&1 | grep 'error: `bad'"' is not a recognized" > /dev/null]])
|
||||
|
||||
AT_DATA([input-c++.y],
|
||||
[[%code "bad" {}
|
||||
%%
|
||||
start: ;
|
||||
]])
|
||||
AT_CHECK([[bison input-c++.y 2>&1 | grep 'error: `bad'"' is not a recognized" > /dev/null]])
|
||||
|
||||
AT_DATA([input-c++-glr.y],
|
||||
[[%code "bad" {}
|
||||
%%
|
||||
start: ;
|
||||
]])
|
||||
AT_CHECK([[bison input-c++-glr.y 2>&1 | grep 'error: `bad'"' is not a recognized" > /dev/null]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
Reference in New Issue
Block a user