mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-08-14 13:15:14 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b948b7696 | ||
|
|
8b5fb7c4c3 | ||
|
|
d6ae95fb50 | ||
|
|
e86b14069d | ||
|
|
5d983253f7 | ||
|
|
caadfc552b | ||
|
|
c4c25e091c | ||
|
|
fc18b4313a | ||
|
|
758172a8b9 | ||
|
|
e9454c3456 | ||
|
|
8f01cf0269 | ||
|
|
dab08da605 | ||
|
|
8cedb4b40e | ||
|
|
258c2c967f | ||
|
|
9a33570493 | ||
|
|
42ab6c1e44 | ||
|
|
dc1035bada | ||
|
|
71e3f6d4da | ||
|
|
3877b7210e | ||
|
|
64aec0a8d8 | ||
|
|
5e2e9af56d | ||
|
|
7a226860ef | ||
|
|
c973361138 | ||
|
|
5839f4d289 | ||
|
|
ffa46e6516 | ||
|
|
ff50f6f223 | ||
|
|
05be0fef95 | ||
|
|
72c9fa4510 | ||
|
|
a555b41990 | ||
|
|
ecf5cb7e0e | ||
|
|
e50de09886 | ||
|
|
95421df67b | ||
|
|
a4ed94bc13 | ||
|
|
07726f1178 | ||
|
|
e78596955d | ||
|
|
ecd5cae2d4 | ||
|
|
8dcc25a1e4 | ||
|
|
1a5f74d2f6 | ||
|
|
00a654c8ad | ||
|
|
6c5f690da4 | ||
|
|
007e1b5f0a | ||
|
|
bbb9750b3e | ||
|
|
52d0e77c2c | ||
|
|
088d5668a9 | ||
|
|
87579e03e0 | ||
|
|
11225a5d2f | ||
|
|
3dcfb4fd88 | ||
|
|
c0ccb8e5b4 | ||
|
|
79f967ac0d | ||
|
|
0f6ab8e692 | ||
|
|
e657f04b62 | ||
|
|
10e61eec6d | ||
|
|
149e280aab | ||
|
|
e9fddab715 | ||
|
|
cc68bbf799 | ||
|
|
f0bb82ae9e | ||
|
|
04d62346f3 | ||
|
|
9b70d69f39 | ||
|
|
2b7bde9d13 | ||
|
|
ff2fc62138 | ||
|
|
2c05fc750a | ||
|
|
57bc3c9013 | ||
|
|
7aee4586ca | ||
|
|
6c44f2dce3 | ||
|
|
5604903f7a | ||
|
|
225a67321b | ||
|
|
4e3c06b0f8 | ||
|
|
4e26809ab9 | ||
|
|
678853da7e | ||
|
|
76e11b5a3e | ||
|
|
f9c73eec5f | ||
|
|
f6dcecb287 | ||
|
|
ad31c3cdf4 | ||
|
|
7fa23136ca | ||
|
|
961ea2ac85 | ||
|
|
cc6e5cf854 | ||
|
|
1376a7c6e2 | ||
|
|
1c273826d4 | ||
|
|
4a55a5ea9a | ||
|
|
72f04ca80f | ||
|
|
fd98afaf10 | ||
|
|
cca8c73431 | ||
|
|
cb40f5c624 | ||
|
|
6c23b012b9 | ||
|
|
ef88dfba81 | ||
|
|
6e89bc0fd2 | ||
|
|
e3e21cc0d8 | ||
|
|
a0ee2a7543 | ||
|
|
7e28dbea11 | ||
|
|
65df8d6747 | ||
|
|
beea39b2ec | ||
|
|
086506bf23 | ||
|
|
39792f57fb | ||
|
|
65bbaf9598 | ||
|
|
9039c571f4 | ||
|
|
d3db22d788 | ||
|
|
9434571f95 | ||
|
|
0cdbcee0ce | ||
|
|
fd37eb057e | ||
|
|
ecc3a13c34 | ||
|
|
04904e4d28 | ||
|
|
75a605454d | ||
|
|
d7f39ac507 | ||
|
|
f3c18c8e80 | ||
|
|
00c80bc96c | ||
|
|
f62f1db298 | ||
|
|
3ba001baac | ||
|
|
4140320a0a | ||
|
|
af19fd7e0f | ||
|
|
2c74872991 | ||
|
|
50517d578c | ||
|
|
59d820d1ef | ||
|
|
90f0500ef8 | ||
|
|
17a9542c4f | ||
|
|
b7045aa706 | ||
|
|
ee56b6e0f2 | ||
|
|
1edc98f793 | ||
|
|
4192de1f41 | ||
|
|
00b0d02955 | ||
|
|
1045c8d0ef | ||
|
|
ef8965b5f5 | ||
|
|
84b1972c96 | ||
|
|
1079595b2a | ||
|
|
e364bcdbc5 | ||
|
|
5a8db8a739 | ||
|
|
5acc29041e | ||
|
|
5b0b0a1e08 | ||
|
|
1c694e08cc | ||
|
|
4cfb067d93 | ||
|
|
cf60d0a617 | ||
|
|
c0e8489605 | ||
|
|
788b1a6858 | ||
|
|
56414791e9 | ||
|
|
675dcf1962 | ||
|
|
466fb66578 | ||
|
|
cbb967dbad | ||
|
|
44ac18d136 | ||
|
|
0c3dd3a669 | ||
|
|
951da960e6 | ||
|
|
15ea35019f | ||
|
|
ecd922024e | ||
|
|
2353ce7216 | ||
|
|
9cc76ee62c | ||
|
|
2f83ef57f3 | ||
|
|
744171ddbf | ||
|
|
4fd3282dd7 | ||
|
|
67793793e8 | ||
|
|
f334775dbf | ||
|
|
feb1011c8b | ||
|
|
99bedadf23 | ||
|
|
79c3f2b8fd | ||
|
|
4cca30d2e6 | ||
|
|
5789f9d91e | ||
|
|
b269a45fa4 | ||
|
|
1478fccd23 | ||
|
|
535281f0ff | ||
|
|
c4a7e7a1ab | ||
|
|
388e12ac0f | ||
|
|
b870d5fee4 | ||
|
|
30d01b21e7 | ||
|
|
c2cca46795 | ||
|
|
879530cb95 | ||
|
|
72acecb30c | ||
|
|
d4fcd5c3d0 | ||
|
|
368fcf0af5 | ||
|
|
6fe063da8f | ||
|
|
296660304c | ||
|
|
323731ff74 | ||
|
|
6f7f949708 | ||
|
|
15e57d9108 | ||
|
|
30ba94081c | ||
|
|
0e7bc7a6d8 | ||
|
|
eff4d16175 | ||
|
|
b0e11f4523 | ||
|
|
d9b2270bed | ||
|
|
7a28659495 | ||
|
|
e09a72eeb0 | ||
|
|
a09d0ae4d1 | ||
|
|
1e25cb44d1 | ||
|
|
3ed42d2487 | ||
|
|
e7a202d762 | ||
|
|
11e2b755f0 | ||
|
|
f3d33c3613 | ||
|
|
163a35d6dd | ||
|
|
cdb42f7730 | ||
|
|
126252333d | ||
|
|
8637f2c7d6 | ||
|
|
6946149701 | ||
|
|
1368b9dbc9 | ||
|
|
0e96eaf612 | ||
|
|
77bdcc6f0c | ||
|
|
57647bb656 | ||
|
|
63cd2918ff | ||
|
|
d810aa3d8f | ||
|
|
ed1eedbbcb | ||
|
|
bc74b4b15a | ||
|
|
8dd8137c38 | ||
|
|
1388e5b276 | ||
|
|
6f5465c917 | ||
|
|
bb02acc2ed | ||
|
|
80a4389377 | ||
|
|
ef097719ea | ||
|
|
0c90c59795 | ||
|
|
18a7cfc7cf | ||
|
|
088356cb2f | ||
|
|
52db24b2bc | ||
|
|
650b253843 | ||
|
|
7781254e01 | ||
|
|
fa226d773c | ||
|
|
1cc83505c5 | ||
|
|
2d97fe86fd | ||
|
|
3239866f4a | ||
|
|
ebab1ffca8 | ||
|
|
f705e9abdb | ||
|
|
d6f576102e | ||
|
|
0f587e9931 | ||
|
|
48be689a73 | ||
|
|
d727e0ff23 | ||
|
|
37aeda6fb3 | ||
|
|
bba2f0a3a0 | ||
|
|
fe14fb1c40 | ||
|
|
88d1ab421a | ||
|
|
edf495b38e | ||
|
|
ba69beafac | ||
|
|
c16fcaf2fb | ||
|
|
7e99f67592 | ||
|
|
d5f929d407 | ||
|
|
c5b215b5e6 | ||
|
|
0774b2c6e3 | ||
|
|
493359b758 | ||
|
|
23ba9e5dfa | ||
|
|
792fc34016 | ||
|
|
c4a08d1899 | ||
|
|
50fb1e6e0c | ||
|
|
6bd0527a50 | ||
|
|
1aa9d40b24 | ||
|
|
a1da9b9fe8 | ||
|
|
c80cdf2db2 | ||
|
|
3197d0fac9 | ||
|
|
78e43ce8ff | ||
|
|
fe23e19323 | ||
|
|
f374310119 | ||
|
|
7bfff37f01 | ||
|
|
26fba6fc94 | ||
|
|
c592202345 | ||
|
|
0917f4dc76 | ||
|
|
0f792833c2 | ||
|
|
b62e063df5 | ||
|
|
e6b0612f91 | ||
|
|
2eb3328afc | ||
|
|
81849520cd | ||
|
|
fc2191f137 | ||
|
|
6fb362c87a | ||
|
|
46ab1d0cbe | ||
|
|
f54a5b303b | ||
|
|
2cc361387c | ||
|
|
e6d1289f4a | ||
|
|
16c77b4ba2 | ||
|
|
172f103c1e | ||
|
|
6ada985ff3 | ||
|
|
2e12257803 | ||
|
|
1db962716a | ||
|
|
9096955fba | ||
|
|
e9d404415a | ||
|
|
d9df62bfcd | ||
|
|
adac9a17f0 | ||
|
|
3b4b157369 | ||
|
|
5c332d70d7 | ||
|
|
91247f50d7 | ||
|
|
f443673450 | ||
|
|
8e6233353f | ||
|
|
e5a5da16ed | ||
|
|
ebe427bbf3 | ||
|
|
c6e2dcabae | ||
|
|
e1197fcc3d | ||
|
|
1854429e40 | ||
|
|
cece227f95 | ||
|
|
e83077c617 | ||
|
|
fd33cc9c8b | ||
|
|
8637438cee | ||
|
|
ee97f37cb4 | ||
|
|
68ef3a0466 | ||
|
|
cda1934606 | ||
|
|
5b883180e6 | ||
|
|
135d0336d5 | ||
|
|
cc6c647f00 | ||
|
|
a1aef9825a | ||
|
|
ece99a890c | ||
|
|
169c2530e4 | ||
|
|
c894a6e2ce | ||
|
|
187c2ac344 | ||
|
|
f06c0d2c05 | ||
|
|
975be86ccc | ||
|
|
1c0adb410d | ||
|
|
32b529f038 | ||
|
|
46cce832fd | ||
|
|
98a1045bea | ||
|
|
8426663631 | ||
|
|
a0675d707f | ||
|
|
e419eda5e2 | ||
|
|
2116af766a | ||
|
|
8036635251 | ||
|
|
c442b5de9d | ||
|
|
da4587fcd7 | ||
|
|
86a3ec0f8d | ||
|
|
7122d747cf | ||
|
|
69fe4b9eb6 | ||
|
|
385fb345bf | ||
|
|
f983d00e77 |
+1
-1
@@ -1 +1 @@
|
|||||||
3.5.2
|
3.5.4
|
||||||
|
|||||||
+47
-5
@@ -67,14 +67,13 @@ jobs:
|
|||||||
## First. ##
|
## First. ##
|
||||||
## ------- ##
|
## ------- ##
|
||||||
|
|
||||||
# Start with three completely different environments, to get
|
# Start with three completely different environments, to get errors asap.
|
||||||
# errors asap.
|
|
||||||
|
|
||||||
- name: "GCC 9 -O3"
|
- name: "GCC 9 -O3"
|
||||||
stage: check
|
stage: check
|
||||||
os: linux
|
os: linux
|
||||||
dist: bionic
|
dist: bionic
|
||||||
addons:
|
addons: &gcc9
|
||||||
apt:
|
apt:
|
||||||
sources:
|
sources:
|
||||||
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
|
# See https://github.com/travis-ci/apt-source-safelist/issues/410.
|
||||||
@@ -136,6 +135,49 @@ jobs:
|
|||||||
packages:
|
packages:
|
||||||
- intel-oneapi-icc
|
- intel-oneapi-icc
|
||||||
|
|
||||||
|
## ------- ##
|
||||||
|
## First. ##
|
||||||
|
## ------- ##
|
||||||
|
|
||||||
|
# Start with three completely different environments, to get
|
||||||
|
# errors asap.
|
||||||
|
|
||||||
|
- name: "ARM64: GCC 9 -O3 part 1"
|
||||||
|
stage: check
|
||||||
|
os: linux
|
||||||
|
arch: arm64
|
||||||
|
dist: bionic
|
||||||
|
addons: *gcc9
|
||||||
|
env:
|
||||||
|
- CC=gcc-9
|
||||||
|
- CXX=g++-9
|
||||||
|
- CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'
|
||||||
|
- PART=1
|
||||||
|
|
||||||
|
- name: "PPC64le: GCC 9 part 1"
|
||||||
|
stage: check
|
||||||
|
os: linux
|
||||||
|
arch: ppc64le
|
||||||
|
dist: bionic
|
||||||
|
addons: *gcc9
|
||||||
|
env:
|
||||||
|
- CC=gcc-9
|
||||||
|
- CXX=g++-9
|
||||||
|
- CONFIGUREFLAGS='CFLAGS=-O3 CXXFLAGS=-O3'
|
||||||
|
- PART=1
|
||||||
|
|
||||||
|
- name: "s390x: GCC 9 part 1"
|
||||||
|
stage: check
|
||||||
|
os: linux
|
||||||
|
arch: s390x
|
||||||
|
dist: bionic
|
||||||
|
addons: *gcc9
|
||||||
|
env:
|
||||||
|
- CC=gcc-9
|
||||||
|
- CXX=g++-9
|
||||||
|
- CONFIGUREFLAGS='CFLAGS=-O3 CXXFLAGS=-O3'
|
||||||
|
- PART=1
|
||||||
|
|
||||||
## ----- ##
|
## ----- ##
|
||||||
## GCC. ##
|
## GCC. ##
|
||||||
## ----- ##
|
## ----- ##
|
||||||
@@ -437,11 +479,11 @@ script:
|
|||||||
- sudo apt-get install -qq doxygen flex m4
|
- sudo apt-get install -qq doxygen flex m4
|
||||||
# Install and activate dmd.
|
# Install and activate dmd.
|
||||||
- mkdir -p ~/dlang && wget https://dlang.org/install.sh -O ~/dlang/install.sh
|
- mkdir -p ~/dlang && wget https://dlang.org/install.sh -O ~/dlang/install.sh
|
||||||
- source $(source ~/dlang/install.sh dmd -a)
|
- source $(source ~/dlang/install.sh dmd -a) || true
|
||||||
|
|
||||||
- $CC --version
|
- $CC --version
|
||||||
- $CXX --version
|
- $CXX --version
|
||||||
- dmd --version
|
- dmd --version || true
|
||||||
- doxygen --version
|
- doxygen --version
|
||||||
- flex --version
|
- flex --version
|
||||||
- ld --version
|
- ld --version
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ dependencies = $(BISON_IN) $(src_bison_SOURCES) $(dist_skeletons_DATA)
|
|||||||
BISON = $(top_builddir)/tests/bison
|
BISON = $(top_builddir)/tests/bison
|
||||||
BISON_IN = $(top_srcdir)/tests/bison.in
|
BISON_IN = $(top_srcdir)/tests/bison.in
|
||||||
YACC = $(BISON) -o y.tab.c
|
YACC = $(BISON) -o y.tab.c
|
||||||
AM_YFLAGS_WITH_LINES = --defines -Werror -Wall --report=all
|
AM_YFLAGS_WITH_LINES = --defines -Werror -Wall,dangling-alias --report=all
|
||||||
AM_YFLAGS = $(AM_YFLAGS_WITH_LINES) --no-lines
|
AM_YFLAGS = $(AM_YFLAGS_WITH_LINES) --no-lines
|
||||||
|
|
||||||
# Initialization before completion by local.mk's.
|
# Initialization before completion by local.mk's.
|
||||||
|
|||||||
@@ -1,5 +1,229 @@
|
|||||||
GNU Bison NEWS
|
GNU Bison NEWS
|
||||||
|
|
||||||
|
* Noteworthy changes in release 3.5.90 (2020-04-18) [beta]
|
||||||
|
|
||||||
|
** Backward incompatible changes
|
||||||
|
|
||||||
|
TL;DR: replace "#define YYERROR_VERBOSE 1" by "%define parse.error verbose".
|
||||||
|
|
||||||
|
The YYERROR_VERBOSE macro is no longer supported; the parsers that still
|
||||||
|
depend on it will now produce Yacc-like error messages (just "syntax
|
||||||
|
error"). It was superseded by the "%error-verbose" directive in Bison
|
||||||
|
1.875 (2003-01-01). Bison 2.6 (2012-07-19) clearly announced that support
|
||||||
|
for YYERROR_VERBOSE would be removed. Note that since Bison 3.0
|
||||||
|
(2013-07-25), "%error-verbose" is deprecated in favor of "%define
|
||||||
|
parse.error verbose".
|
||||||
|
|
||||||
|
** New features
|
||||||
|
|
||||||
|
*** Improved syntax error messages
|
||||||
|
|
||||||
|
Two new values for the %define parse.error variable offer more control to
|
||||||
|
the user. Available in all the skeletons (C, C++, Java).
|
||||||
|
|
||||||
|
**** %define parse.error detailed
|
||||||
|
|
||||||
|
The behavior of "%define parse.error detailed" is closely resembling that
|
||||||
|
of "%define parse.error verbose" with a few exceptions. First, it is safe
|
||||||
|
to use non-ASCII characters in token aliases (with 'verbose', the result
|
||||||
|
depends on the locale with which bison was run). Second, a yysymbol_name
|
||||||
|
function is exposed to the user, instead of the yytnamerr function and the
|
||||||
|
yytname table. Third, token internationalization is supported (see
|
||||||
|
below).
|
||||||
|
|
||||||
|
**** %define parse.error custom
|
||||||
|
|
||||||
|
With this directive, the user forges and emits the syntax error message
|
||||||
|
herself by defining the yyreport_syntax_error function. A new type,
|
||||||
|
yypcontext_t, captures the circumstances of the error, and provides the
|
||||||
|
user with functions to get details, such as yypcontext_expected_tokens to
|
||||||
|
get the list of expected token kinds.
|
||||||
|
|
||||||
|
A possible implementation of yyreport_syntax_error is:
|
||||||
|
|
||||||
|
int
|
||||||
|
yyreport_syntax_error (const yypcontext_t *ctx)
|
||||||
|
{
|
||||||
|
int res = 0;
|
||||||
|
YY_LOCATION_PRINT (stderr, *yypcontext_location (ctx));
|
||||||
|
fprintf (stderr, ": syntax error");
|
||||||
|
// Report the tokens expected at this point.
|
||||||
|
{
|
||||||
|
enum { TOKENMAX = 10 };
|
||||||
|
yysymbol_kind_t expected[TOKENMAX];
|
||||||
|
int n = yypcontext_expected_tokens (ctx, expected, TOKENMAX);
|
||||||
|
if (n < 0)
|
||||||
|
// Forward errors to yyparse.
|
||||||
|
res = n;
|
||||||
|
else
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
fprintf (stderr, "%s %s",
|
||||||
|
i == 0 ? ": expected" : " or", yysymbol_name (expected[i]));
|
||||||
|
}
|
||||||
|
// Report the unexpected token.
|
||||||
|
{
|
||||||
|
yysymbol_kind_t lookahead = yypcontext_token (ctx);
|
||||||
|
if (lookahead != YYSYMBOL_YYEMPTY)
|
||||||
|
fprintf (stderr, " before %s", yysymbol_name (lookahead));
|
||||||
|
}
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
**** Token aliases internationalization
|
||||||
|
|
||||||
|
When the %define variable parse.error is set to `custom` or `detailed`,
|
||||||
|
one may specify which token aliases are to be translated using _(). For
|
||||||
|
instance
|
||||||
|
|
||||||
|
%token
|
||||||
|
PLUS "+"
|
||||||
|
MINUS "-"
|
||||||
|
<double>
|
||||||
|
NUM _("double precision number")
|
||||||
|
<symrec*>
|
||||||
|
FUN _("function")
|
||||||
|
VAR _("variable")
|
||||||
|
|
||||||
|
In that case the user must define _() and N_(), and yysymbol_name returns
|
||||||
|
the translated symbol (i.e., it returns '_("variable")' rather that
|
||||||
|
'"variable"'). In Java, the user must provide an i18n() function.
|
||||||
|
|
||||||
|
*** List of expected tokens (yacc.c)
|
||||||
|
|
||||||
|
Push parsers may invoke yypstate_expected_tokens at any point during
|
||||||
|
parsing (including even before submitting the first token) to get the list
|
||||||
|
of possible tokens. This feature can be used to propose autocompletion
|
||||||
|
(see below the "bistromathic" example).
|
||||||
|
|
||||||
|
It makes little sense to use this feature without enabling LAC (lookahead
|
||||||
|
correction).
|
||||||
|
|
||||||
|
*** Deep overhaul of the symbol and token kinds
|
||||||
|
|
||||||
|
To avoid the confusion with types in programming languages, we now refer
|
||||||
|
to token and symbol "kinds" instead of token and symbol "types". The
|
||||||
|
documentation and error messages have been revised.
|
||||||
|
|
||||||
|
All the skeletons have been updated to use dedicated enum types rather
|
||||||
|
than integral types. Special symbols are now regular citizens, instead of
|
||||||
|
being declared in ad hoc ways.
|
||||||
|
|
||||||
|
**** Token kinds
|
||||||
|
|
||||||
|
The "token kind" is what is returned by the scanner, e.g., PLUS, NUMBER,
|
||||||
|
LPAREN, etc. While backward compatibility is of course ensured, users are
|
||||||
|
nonetheless invited to replace their uses of "enum yytokentype" by
|
||||||
|
"yytoken_kind_t".
|
||||||
|
|
||||||
|
This type now also includes tokens that were previously hidden: YYEOF (end
|
||||||
|
of input), YYUNDEF (undefined token), and YYERRCODE (error token). They
|
||||||
|
now have string aliases, internationalized when internationalization is
|
||||||
|
enabled. Therefore, by default, error messages now refer to "end of file"
|
||||||
|
(internationalized) rather than the cryptic "$end", or to "invaid token"
|
||||||
|
rather than "$undefined".
|
||||||
|
|
||||||
|
Therefore in most cases it is now useless to define the end-of-line token
|
||||||
|
as follows:
|
||||||
|
|
||||||
|
%token T_EOF 0 "end of file"
|
||||||
|
|
||||||
|
Rather simply use "YYEOF" in your scanner.
|
||||||
|
|
||||||
|
**** Symbol kinds
|
||||||
|
|
||||||
|
The "symbol kinds" is what the parser actually uses. (Unless the
|
||||||
|
api.token.raw %define variable is used, the symbol kind of a terminal
|
||||||
|
differs from the corresponding token kind.)
|
||||||
|
|
||||||
|
They are now exposed as a enum, "yysymbol_kind_t".
|
||||||
|
|
||||||
|
This allows users to tailor the error messages the way they want, or to
|
||||||
|
process some symbols in a specific way in autocompletion (see the
|
||||||
|
bistromathic example below).
|
||||||
|
|
||||||
|
*** Modernize display of explanatory statements in diagnostics
|
||||||
|
|
||||||
|
Since Bison 2.7, output was indented four spaces for explanatory
|
||||||
|
statements. For example:
|
||||||
|
|
||||||
|
input.y:2.7-13: error: %type redeclaration for exp
|
||||||
|
input.y:1.7-11: previous declaration
|
||||||
|
|
||||||
|
Since the introduction of caret-diagnostics, it became less clear. This
|
||||||
|
indentation has been removed and submessages are displayed similarly as in
|
||||||
|
GCC:
|
||||||
|
|
||||||
|
input.y:2.7-13: error: %type redeclaration for exp
|
||||||
|
2 | %type <float> exp
|
||||||
|
| ^~~~~~~
|
||||||
|
input.y:1.7-11: note: previous declaration
|
||||||
|
1 | %type <int> exp
|
||||||
|
| ^~~~~
|
||||||
|
|
||||||
|
Contributed by Victor Morales Cayuela.
|
||||||
|
|
||||||
|
*** C++
|
||||||
|
|
||||||
|
The token and symbol kinds are yy::parser::token_kind_type and
|
||||||
|
yy::parser::symbol_kind_type.
|
||||||
|
|
||||||
|
The symbol_type::kind() member function allows to get the kind of a
|
||||||
|
symbol. This can be used to write unit tests for scanners, e.g.,
|
||||||
|
|
||||||
|
yy::parser::symbol_type t = make_NUMBER ("123");
|
||||||
|
assert (t.kind () == yy::parser::symbol_kind::S_NUMBER);
|
||||||
|
assert (t.value.as<int> () == 123);
|
||||||
|
|
||||||
|
** Documentation
|
||||||
|
|
||||||
|
*** User Manual
|
||||||
|
|
||||||
|
In order to avoid ambiguities with "type" as in "typing", we now refer to
|
||||||
|
the "token kind" (e.g., `PLUS`, `NUMBER`, etc.) rather than the "token
|
||||||
|
type". We now also refer to the "symbol type" (e.g., `PLUS`, `expr`,
|
||||||
|
etc.).
|
||||||
|
|
||||||
|
*** Examples
|
||||||
|
|
||||||
|
There are now two examples in examples/java: a very simple calculator, and
|
||||||
|
one that tracks locations to provide accurate error messages.
|
||||||
|
|
||||||
|
The lexcalc example (a simple example in C based on Flex and Bison) now
|
||||||
|
also demonstrates location tracking.
|
||||||
|
|
||||||
|
|
||||||
|
A new C example, bistromathic, is a fully featured interactive calculator
|
||||||
|
using many Bison features: pure interface, push parser, autocompletion
|
||||||
|
based on the current parser state (using yypstate_expected_tokens),
|
||||||
|
location tracking, internationalized custom error messages, lookahead
|
||||||
|
correction, rich debug traces, etc.
|
||||||
|
|
||||||
|
It shows how to depend on the symbol kinds to tailor autocompletion. For
|
||||||
|
instance it recognizes the symbol kind "VARIABLE" to propose
|
||||||
|
autocompletion on the existing variables, rather than of the word
|
||||||
|
"variable".
|
||||||
|
|
||||||
|
* Noteworthy changes in release 3.5.4 (2020-04-05) [stable]
|
||||||
|
|
||||||
|
** WARNING: Future backward-incompatibilities!
|
||||||
|
|
||||||
|
TL;DR: replace "#define YYERROR_VERBOSE 1" by "%define parse.error verbose".
|
||||||
|
|
||||||
|
Bison 3.6 will no longer support the YYERROR_VERBOSE macro; the parsers
|
||||||
|
that still depend on it will produce Yacc-like error messages (just
|
||||||
|
"syntax error"). It was superseded by the "%error-verbose" directive in
|
||||||
|
Bison 1.875 (2003-01-01). Bison 2.6 (2012-07-19) clearly announced that
|
||||||
|
support for YYERROR_VERBOSE would be removed. Note that since Bison 3.0
|
||||||
|
(2013-07-25), "%error-verbose" is deprecated in favor of "%define
|
||||||
|
parse.error verbose".
|
||||||
|
|
||||||
|
** Bug fixes
|
||||||
|
|
||||||
|
Fix portability issues of the package itself on old compilers.
|
||||||
|
|
||||||
|
Fix api.token.raw support in Java.
|
||||||
|
|
||||||
* Noteworthy changes in release 3.5.3 (2020-03-08) [stable]
|
* Noteworthy changes in release 3.5.3 (2020-03-08) [stable]
|
||||||
|
|
||||||
** Bug fixes
|
** Bug fixes
|
||||||
@@ -3886,7 +4110,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
LocalWords: Wdeprecated yytext Variadic variadic yyrhs yyphrs RCS README
|
LocalWords: Wdeprecated yytext Variadic variadic yyrhs yyphrs RCS README
|
||||||
LocalWords: noexcept constexpr ispell american deprecations backend Teoh
|
LocalWords: noexcept constexpr ispell american deprecations backend Teoh
|
||||||
LocalWords: YYPRINT Mangold Bonzini's Wdangling exVal baz checkable gcc
|
LocalWords: YYPRINT Mangold Bonzini's Wdangling exVal baz checkable gcc
|
||||||
LocalWords: fsanitize Vogelsgesang lis redeclared stdint automata
|
LocalWords: fsanitize Vogelsgesang lis redeclared stdint automata yytname
|
||||||
|
LocalWords: yysymbol yytnamerr yyreport ctx ARGMAX yysyntax stderr LPAREN
|
||||||
|
LocalWords: symrec yypcontext TOKENMAX yyexpected YYEMPTY yypstate YYEOF
|
||||||
|
LocalWords: autocompletion bistromathic submessages Cayuela lexcalc
|
||||||
|
LocalWords: yytoken YYUNDEF YYERRCODE
|
||||||
|
|
||||||
Local Variables:
|
Local Variables:
|
||||||
ispell-dictionary: "american"
|
ispell-dictionary: "american"
|
||||||
|
|||||||
@@ -1,4 +1,19 @@
|
|||||||
This package contains the GNU Bison parser generator.
|
GNU Bison is a general-purpose parser generator that converts an annotated
|
||||||
|
context-free grammar into a deterministic LR or generalized LR (GLR) parser
|
||||||
|
employing LALR(1) parser tables. Bison can also generate IELR(1) or
|
||||||
|
canonical LR(1) parser tables. Once you are proficient with Bison, you can
|
||||||
|
use it to develop a wide range of language parsers, from those used in
|
||||||
|
simple desk calculators to complex programming languages.
|
||||||
|
|
||||||
|
Bison is upward compatible with Yacc: all properly-written Yacc grammars
|
||||||
|
work with Bison with no change. Anyone familiar with Yacc should be able to
|
||||||
|
use Bison with little trouble. You need to be fluent in C, C++ or Java
|
||||||
|
programming in order to use Bison.
|
||||||
|
|
||||||
|
Bison and the parsers it generates are portable, they do not require any
|
||||||
|
specific compilers.
|
||||||
|
|
||||||
|
GNU Bison's home page is https://gnu.org/software/bison/.
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
## Build from git
|
## Build from git
|
||||||
@@ -103,7 +118,8 @@ fill-column: 76
|
|||||||
ispell-dictionary: "american"
|
ispell-dictionary: "american"
|
||||||
End:
|
End:
|
||||||
|
|
||||||
LocalWords: parsers ngettext Texinfo pdf html YYYY ZZZZ ispell american
|
LocalWords: parsers ngettext Texinfo pdf html YYYY ZZZZ ispell american md
|
||||||
LocalWords: MERCHANTABILITY
|
LocalWords: MERCHANTABILITY GLR LALR IELR submodule init README src bw
|
||||||
|
LocalWords: Relocatability symlinks symlink
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
|||||||
+113
-180
@@ -5,7 +5,8 @@ Everything related to the development of Bison is on Savannah:
|
|||||||
http://savannah.gnu.org/projects/bison/.
|
http://savannah.gnu.org/projects/bison/.
|
||||||
|
|
||||||
|
|
||||||
# Administrivia
|
Administrivia
|
||||||
|
=============
|
||||||
|
|
||||||
## If you incorporate a change from somebody on the net:
|
## If you incorporate a change from somebody on the net:
|
||||||
First, if it is a large change, you must make sure they have signed the
|
First, if it is a large change, you must make sure they have signed the
|
||||||
@@ -23,9 +24,11 @@ demonstrates the bug. Then fix the bug, re-run the test suite, and check
|
|||||||
everything in.
|
everything in.
|
||||||
|
|
||||||
|
|
||||||
# Hacking
|
|
||||||
|
|
||||||
## Visible changes
|
Hacking
|
||||||
|
=======
|
||||||
|
|
||||||
|
## Visible Changes
|
||||||
Which include serious bug fixes, must be mentioned in NEWS.
|
Which include serious bug fixes, must be mentioned in NEWS.
|
||||||
|
|
||||||
## Translations
|
## Translations
|
||||||
@@ -34,22 +37,77 @@ Only user visible strings are to be translated: error messages, bits of the
|
|||||||
assert/abort), and all the --trace output which is meant for the maintainers
|
assert/abort), and all the --trace output which is meant for the maintainers
|
||||||
only.
|
only.
|
||||||
|
|
||||||
## Coding style
|
## Coding Style
|
||||||
Follow the GNU Coding Standards.
|
|
||||||
|
|
||||||
Don't reinvent the wheel: we use gnulib, which features many components.
|
|
||||||
Actually, Bison has legacy code that we should replace with gnulib modules
|
|
||||||
(e.g., many adhoc implementations of lists).
|
|
||||||
|
|
||||||
Do not add horizontal tab characters to any file in Bison's repository
|
Do not add horizontal tab characters to any file in Bison's repository
|
||||||
except where required. For example, do not use tabs to format C code.
|
except where required. For example, do not use tabs to format C code.
|
||||||
However, make files, ChangeLog, and some regular expressions require tabs.
|
However, make files, ChangeLog, and some regular expressions require tabs.
|
||||||
Also, test cases might need to contain tabs to check that Bison properly
|
Also, test cases might need to contain tabs to check that Bison properly
|
||||||
processes tabs in its input.
|
processes tabs in its input.
|
||||||
|
|
||||||
## Commit messages
|
Prefer "res" as the name of the local variable that will be "return"ed by
|
||||||
Please, imitate the style we use. Use `git log` to get sources of
|
the function.
|
||||||
inspiration.
|
|
||||||
|
### Bison
|
||||||
|
Follow the GNU Coding Standards.
|
||||||
|
|
||||||
|
Don't reinvent the wheel: we use gnulib, which features many components.
|
||||||
|
Actually, Bison has legacy code that we should replace with gnulib modules
|
||||||
|
(e.g., many ad hoc implementations of lists).
|
||||||
|
|
||||||
|
### Skeletons
|
||||||
|
We try to use the "typical" coding style for each language.
|
||||||
|
|
||||||
|
#### C/C++
|
||||||
|
Follow the GNU Coding Standards.
|
||||||
|
|
||||||
|
The `glr.c` skeleton was implemented with `camlCase`. We are migrating it
|
||||||
|
to `snake_case`. Because we are standardizing the code, it is currently
|
||||||
|
inconsistent.
|
||||||
|
|
||||||
|
Use `YYFOO` and `yyfoo` for entities that are exposed to the user. They are
|
||||||
|
part of our contract with the users wrt backward compatibility.
|
||||||
|
|
||||||
|
Use `YY_FOO` and `yy_foo` for private matters. Users should not use them,
|
||||||
|
we are free to change them without fear of backward compatibility issues.
|
||||||
|
|
||||||
|
Use `*_t` for types, especially for `yy*_t` in which case we shouldn't worry
|
||||||
|
about the C standard introducing such a name.
|
||||||
|
|
||||||
|
#### C++
|
||||||
|
Follow the C++ Core Guidelines
|
||||||
|
(http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines). The Google
|
||||||
|
ones may be interesting too
|
||||||
|
(https://google.github.io/styleguide/cppguide.html).
|
||||||
|
|
||||||
|
Our enumerators, such as the kinds (symbol and token kinds), should be lower
|
||||||
|
case, but it was too late to follow that track for token kinds, and symbol
|
||||||
|
kind enumerators are made to be consistent with them.
|
||||||
|
|
||||||
|
Use `*_type` for type aliases. Use `foo_get()` and `foo_set(v)` for
|
||||||
|
accessors, or simply `foo()` and `foo(v)`.
|
||||||
|
|
||||||
|
Use the `yy` prefix for private stuff, but there's no need for it in the
|
||||||
|
public API. The `yy` prefix is already taken care of via the namespace.
|
||||||
|
|
||||||
|
#### Java
|
||||||
|
We follow https://www.oracle.com/technetwork/java/codeconventions-150003.pdf
|
||||||
|
and https://google.github.io/styleguide/javaguide.html. Unfortunately at
|
||||||
|
some point some GNU Coding Style was installed in Java, but it's an error.
|
||||||
|
So we should for instance stop putting spaces in function calls. Because we
|
||||||
|
are standardizing the code, it is currently inconsistent.
|
||||||
|
|
||||||
|
Use a 2-space indentation (Google) rather than 4 (Oracle).
|
||||||
|
|
||||||
|
Don't use the "yy" prefix for public members: "getExpectedTokens", not
|
||||||
|
"yyexpectedTokens" or "yygetExpectedTokens".
|
||||||
|
|
||||||
|
## Commit Messages
|
||||||
|
Imitate the style we use. Use `git log` to get sources of inspiration.
|
||||||
|
|
||||||
|
If the changes have a small impact on Bison's generated parser, embed these
|
||||||
|
changes in the commit itself. If the impact is large, first push all the
|
||||||
|
changes except those about src/parse-gram.[ch], and then another commit
|
||||||
|
named "regen" which is only about them.
|
||||||
|
|
||||||
## Debugging
|
## Debugging
|
||||||
Bison supports tracing of its various steps, via the `--trace` option.
|
Bison supports tracing of its various steps, via the `--trace` option.
|
||||||
@@ -57,7 +115,10 @@ Since it is not meant for the end user, it is not displayed by `bison
|
|||||||
--help`, nor is it documented in the manual. Instead, run `bison
|
--help`, nor is it documented in the manual. Instead, run `bison
|
||||||
--trace=help`.
|
--trace=help`.
|
||||||
|
|
||||||
# Working from the repository
|
|
||||||
|
|
||||||
|
Working from the Repository
|
||||||
|
===========================
|
||||||
|
|
||||||
These notes intend to help people working on the checked-out sources. These
|
These notes intend to help people working on the checked-out sources. These
|
||||||
requirements do not apply when building from a distribution tarball.
|
requirements do not apply when building from a distribution tarball.
|
||||||
@@ -200,7 +261,36 @@ These files don't change very often in Autoconf, so it should be relatively
|
|||||||
straight-forward to examine the differences in order to decide whether to
|
straight-forward to examine the differences in order to decide whether to
|
||||||
update.
|
update.
|
||||||
|
|
||||||
# Test Suite
|
## Troubleshooting
|
||||||
|
|
||||||
|
Bison is self-hosted: its parser is generated by Bison. We don't force
|
||||||
|
ourselves to use the previous release of Bison, we use the current git
|
||||||
|
master for several reasons:
|
||||||
|
- dogfooding: let Bison be its first user
|
||||||
|
- monitoring: seeing the diff on the generated parsers with git is very
|
||||||
|
helpful, as it allows to see easily the impact of the changes on a real
|
||||||
|
case parser.
|
||||||
|
|
||||||
|
If you are unlucky the generated files, src/parse-gram.[ch], may be older
|
||||||
|
than their source, src/parse-gram.y. And your current version of Bison
|
||||||
|
might not be able to grok it. In that case, first refresh the generated
|
||||||
|
files:
|
||||||
|
|
||||||
|
$ touch src/parse-gram.[ch]
|
||||||
|
|
||||||
|
Then proceed.
|
||||||
|
|
||||||
|
In case you wrecked your current copy of the parser, get back the previous
|
||||||
|
version, compile bison, then force it to recreate the files:
|
||||||
|
|
||||||
|
$ git checkout HEAD^ src/parse-gram.[ch]
|
||||||
|
$ make -C _build
|
||||||
|
$ touch src/parse-gram.y
|
||||||
|
$ make -C _build
|
||||||
|
|
||||||
|
|
||||||
|
Test Suite
|
||||||
|
==========
|
||||||
|
|
||||||
## make check
|
## make check
|
||||||
Consume without moderation. It is composed of two kinds of tests: the
|
Consume without moderation. It is composed of two kinds of tests: the
|
||||||
@@ -354,172 +444,13 @@ re-run the tests, run:
|
|||||||
./configure -C CC='gcc-mp-8 -fsanitize=undefined' CFLAGS='-ggdb'
|
./configure -C CC='gcc-mp-8 -fsanitize=undefined' CFLAGS='-ggdb'
|
||||||
make check
|
make check
|
||||||
|
|
||||||
# Release Procedure
|
|
||||||
This section needs to be updated to take into account features from gnulib.
|
|
||||||
In particular, be sure to read README-release.
|
|
||||||
|
|
||||||
## Update the submodules. See above.
|
|
||||||
|
|
||||||
## Update maintainer tools, such as Autoconf. See above.
|
Release Procedure
|
||||||
|
=================
|
||||||
## Try to get the *.pot files to the Translation Project at least one
|
|
||||||
week before a stable release, to give them time to translate them. Before
|
|
||||||
generating the *.pot files, make sure that po/POTFILES.in and
|
|
||||||
runtime-po/POTFILES.in list all files with translatable strings. This
|
|
||||||
helps: `grep -l '\<_(' *`.
|
|
||||||
|
|
||||||
## Tests
|
|
||||||
See above.
|
|
||||||
|
|
||||||
## Update the foreign files
|
|
||||||
Running `./bootstrap` in the top level should update them all for you. This
|
|
||||||
covers PO files too. Sometimes a PO file contains problems that causes it
|
|
||||||
to be rejected by recent Gettext releases; please report these to the
|
|
||||||
Translation Project.
|
|
||||||
|
|
||||||
## Update README
|
|
||||||
Make sure the information in README is current. Most notably, make sure it
|
|
||||||
recommends a version of GNU M4 that is compatible with the latest Bison
|
|
||||||
sources.
|
|
||||||
|
|
||||||
## Check copyright years.
|
|
||||||
We update years in copyright statements throughout Bison once at the start
|
|
||||||
of every year by running `make update-copyright`. However, before a
|
|
||||||
release, it's good to verify that it's actually been run. Besides the
|
|
||||||
copyright statement for each Bison file, check the copyright statements that
|
|
||||||
the skeletons insert into generated parsers, and check all occurrences of
|
|
||||||
`PACKAGE_COPYRIGHT_YEAR` in configure.ac.
|
|
||||||
|
|
||||||
## Update NEWS, commit and tag.
|
|
||||||
See do-release-commit-and-tag in README-release. For a while, we used beta
|
|
||||||
names such as `2.6_rc1`. Now that we use gnulib in the release procedure,
|
|
||||||
we must use `2.5.90`, which has the additional benefit of being properly
|
|
||||||
sorted in `git tag -l`.
|
|
||||||
|
|
||||||
## make alpha, beta, or stable
|
|
||||||
See README-release.
|
|
||||||
|
|
||||||
## Upload
|
|
||||||
There are two ways to upload the tarballs to the GNU servers: using gnupload
|
|
||||||
(from gnulib), or by hand. Obviously prefer the former. But in either
|
|
||||||
case, be sure to read the following paragraph.
|
|
||||||
|
|
||||||
### Setup
|
|
||||||
You need `gnupg`.
|
|
||||||
|
|
||||||
Make sure your public key has been uploaded at least to keys.gnupg.net. You
|
|
||||||
can upload it with:
|
|
||||||
|
|
||||||
gpg --keyserver keys.gnupg.net --send-keys F125BDF3
|
|
||||||
|
|
||||||
where F125BDF3 should be replaced with your key ID.
|
|
||||||
|
|
||||||
### Using gnupload
|
|
||||||
You need `ncftp`.
|
|
||||||
|
|
||||||
At the end `make stable` (or alpha/beta) will display the procedure to run.
|
|
||||||
Just copy and paste it in your shell.
|
|
||||||
|
|
||||||
### By hand
|
|
||||||
|
|
||||||
The generic GNU upload procedure is at
|
|
||||||
http://www.gnu.org/prep/maintain/maintain.html#Automated-FTP-Uploads.
|
|
||||||
|
|
||||||
Follow the instructions there to register your information so you're permitted
|
|
||||||
to upload.
|
|
||||||
|
|
||||||
Here's a brief reminder of how to roll the tarballs and upload them:
|
|
||||||
|
|
||||||
### make distcheck
|
|
||||||
### gpg -b bison-2.3b.tar.gz
|
|
||||||
### In a file named `bison-2.3b.tar.gz.directive`, type:
|
|
||||||
|
|
||||||
version: 1.1
|
|
||||||
directory: bison
|
|
||||||
filename: bison-2.3b.tar.gz
|
|
||||||
|
|
||||||
### gpg --clearsign bison-2.3b.tar.gz.directive
|
|
||||||
### ftp ftp-upload.gnu.org # Log in as anonymous.
|
|
||||||
### cd /incoming/alpha # cd /incoming/ftp for full release.
|
|
||||||
### put bison-2.3b.tar.gz # This can take a while.
|
|
||||||
### put bison-2.3b.tar.gz.sig
|
|
||||||
### put bison-2.3b.tar.gz.directive.asc
|
|
||||||
### Repeat all these steps for bison-2.3b.tar.xz.
|
|
||||||
|
|
||||||
## Update Bison manual on www.gnu.org.
|
|
||||||
|
|
||||||
The instructions below are obsolete, and left in case one would like to run
|
|
||||||
the commands by hand. Today, one just needs to run
|
|
||||||
|
|
||||||
$ make web-manual-update
|
|
||||||
|
|
||||||
See README-release.
|
See README-release.
|
||||||
|
|
||||||
### You need a non-anonymous checkout of the web pages directory.
|
|
||||||
|
|
||||||
$ cvs -d YOUR_USERID@cvs.savannah.gnu.org:/web/bison checkout bison
|
|
||||||
|
|
||||||
### Get familiar with the instructions for web page maintainers.
|
|
||||||
http://www.gnu.org/server/standards/readme_index.html
|
|
||||||
http://www.gnu.org/server/standards/README.software.html
|
|
||||||
especially the note about symlinks.
|
|
||||||
|
|
||||||
### Build the web pages.
|
|
||||||
Assuming BISON_CHECKOUT refers to a checkout of the Bison dir, and
|
|
||||||
BISON_WWW_CHECKOUT refers to the web directory created above, do:
|
|
||||||
|
|
||||||
$ cd $BISON_CHECKOUT/doc
|
|
||||||
$ make stamp-vti
|
|
||||||
$ ../build-aux/gendocs.sh -o "$BISON_WWW_CHECKOUT/manual" \
|
|
||||||
bison "Bison - GNU parser generator"
|
|
||||||
$ cd $BISON_WWW_CHECKOUT
|
|
||||||
|
|
||||||
Verify that the result looks sane.
|
|
||||||
|
|
||||||
### Commit the modified and the new files.
|
|
||||||
|
|
||||||
### Remove old files.
|
|
||||||
Find the files which have not been overwritten (because they belonged to
|
|
||||||
sections that have been removed or renamed):
|
|
||||||
|
|
||||||
$ cd manual/html_node
|
|
||||||
$ ls -lt
|
|
||||||
|
|
||||||
Remove these files and commit their removal to CVS. For each of these
|
|
||||||
files, add a line to the file .symlinks. This will ensure that hyperlinks
|
|
||||||
to the removed files will redirect to the entire manual; this is better than
|
|
||||||
a 404 error.
|
|
||||||
|
|
||||||
## Announce
|
|
||||||
The "make release" command just created a template,
|
|
||||||
`$HOME/announce-bison-X.Y`. Otherwise, to generate it, run:
|
|
||||||
|
|
||||||
make RELEASE_TYPE=alpha gpg_key_ID=F125BDF3 announcement
|
|
||||||
|
|
||||||
where alpha can be replaced by `beta` or `table` and F125BDF3 should be
|
|
||||||
replaced with your key ID.
|
|
||||||
|
|
||||||
Complete/fix the announcement file. The generated list of recipients
|
|
||||||
(info-gnu@gnu.org, bison-announce@gnu.org, bug-bison@gnu.org,
|
|
||||||
help-bison@gnu.org, bison-patches@gnu.org, and
|
|
||||||
coordinator@translationproject.org) is appropriate for a stable release or a
|
|
||||||
"serious beta". For any other release, drop at least info-gnu@gnu.org. For
|
|
||||||
an example of how to fill out the rest of the template, search the mailing
|
|
||||||
list archives for the most recent release announcement.
|
|
||||||
|
|
||||||
For a stable release, send the same announcement on the comp.compilers
|
|
||||||
newsgroup by sending email to compilers@iecc.com. Do not make any Cc as the
|
|
||||||
moderator will throw away anything cross-posted or Cc'ed. It really needs
|
|
||||||
to be a separate message.
|
|
||||||
|
|
||||||
## Prepare NEWS
|
|
||||||
So that developers don't accidentally add new items to the old NEWS entry,
|
|
||||||
create a new empty entry in line 3 (without the two leading spaces):
|
|
||||||
|
|
||||||
* Noteworthy changes in release ?.? (????-??-??) [?]
|
|
||||||
|
|
||||||
Push these changes.
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|
||||||
Copyright (C) 2002-2005, 2007-2015, 2018-2020 Free Software Foundation,
|
Copyright (C) 2002-2005, 2007-2015, 2018-2020 Free Software Foundation,
|
||||||
@@ -551,9 +482,11 @@ LocalWords: submodule init cd distcheck ChangeLog valgrind sigreturn sudo
|
|||||||
LocalWords: UC gcc DGNULIB POSIXCHECK xml XSLT glr lalr README po runtime rc
|
LocalWords: UC gcc DGNULIB POSIXCHECK xml XSLT glr lalr README po runtime rc
|
||||||
LocalWords: gnupload gnupg gpg keyserver BDF ncftp filename clearsign cvs dir
|
LocalWords: gnupload gnupg gpg keyserver BDF ncftp filename clearsign cvs dir
|
||||||
LocalWords: symlinks vti html lt POSIX Cc'ed Graphviz Texinfo autoconf jN
|
LocalWords: symlinks vti html lt POSIX Cc'ed Graphviz Texinfo autoconf jN
|
||||||
LocalWords: automake autopoint graphviz texinfo PROG Wother parsers
|
LocalWords: automake autopoint graphviz texinfo PROG Wother parsers YYFOO
|
||||||
LocalWords: TESTSUITEFLAGS deprec struct gnulib's getopt config ggdb
|
LocalWords: TESTSUITEFLAGS deprec struct gnulib's getopt config ggdb yyfoo
|
||||||
LocalWords: bitset fsanitize symlink CFLAGS MERCHANTABILITY ispell
|
LocalWords: bitset fsanitize symlink CFLAGS MERCHANTABILITY ispell wrt YY
|
||||||
LocalWords: american
|
LocalWords: american Administrivia camlCase yy accessors namespace src
|
||||||
|
LocalWords: getExpectedTokens yyexpectedTokens yygetExpectedTokens
|
||||||
|
LocalWords: regen dogfooding Autotest testsuite
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ it is today without the invaluable help of these people:
|
|||||||
Aaro Koskinen [email protected]
|
Aaro Koskinen [email protected]
|
||||||
Аскар Сафин [email protected]
|
Аскар Сафин [email protected]
|
||||||
Adam Sampson [email protected]
|
Adam Sampson [email protected]
|
||||||
|
Adrian Vogelsgesang [email protected]
|
||||||
Ahcheong Lee [email protected]
|
Ahcheong Lee [email protected]
|
||||||
Airy Andre [email protected]
|
Airy Andre [email protected]
|
||||||
Akim Demaille [email protected]
|
Akim Demaille [email protected]
|
||||||
@@ -61,6 +62,7 @@ Enrico Scholz [email protected]
|
|||||||
Eric Blake [email protected]
|
Eric Blake [email protected]
|
||||||
Eric S. Raymond [email protected]
|
Eric S. Raymond [email protected]
|
||||||
Étienne Renault [email protected]
|
Étienne Renault [email protected]
|
||||||
|
Evan Lavelle [email protected]
|
||||||
Evan Nemerson [email protected]
|
Evan Nemerson [email protected]
|
||||||
Evgeny Stambulchik [email protected]
|
Evgeny Stambulchik [email protected]
|
||||||
Fabrice Bauzac [email protected]
|
Fabrice Bauzac [email protected]
|
||||||
|
|||||||
@@ -1,121 +1,65 @@
|
|||||||
* Bison 3.6
|
* Bison 3.6
|
||||||
|
** Questions
|
||||||
|
*** Java
|
||||||
|
- Should i18n be part of the Lexer? Currently it's a static method of
|
||||||
|
Lexer.
|
||||||
|
|
||||||
|
- is there a migration path that would allow to use TokenKinds in
|
||||||
|
yylex?
|
||||||
|
|
||||||
|
*** D
|
||||||
|
- is there a way to attach yysymbol_name to the enum itself? As we did
|
||||||
|
in Java.
|
||||||
|
|
||||||
|
- It would be better to have TokenKind as return value. Can we use
|
||||||
|
reflection to support both output types?
|
||||||
|
|
||||||
|
** Documentation
|
||||||
|
- YYERRCODE, YYUNDEF, YYEOF
|
||||||
|
- YYERRCODE and translation
|
||||||
|
|
||||||
|
** Java
|
||||||
|
*** Examples
|
||||||
|
Have an example with a push parser. Use autocompletion in that case.
|
||||||
|
|
||||||
|
*** calc.at
|
||||||
|
Stop hard-coding "Calc". Adjust local.at (look for FIXME).
|
||||||
|
|
||||||
** doc
|
** doc
|
||||||
I feel its ugly to use the GNU style to declare functions in the doc. It
|
I feel it's ugly to use the GNU style to declare functions in the doc. It
|
||||||
generates tons of white space in the page, and may contribute to bad page
|
generates tons of white space in the page, and may contribute to bad page
|
||||||
breaks.
|
breaks.
|
||||||
|
|
||||||
Also, we seem to teach YYPRINT very early on, although it should be
|
|
||||||
considered deprecated: %printer is superior.
|
|
||||||
|
|
||||||
** improve syntax errors (UTF-8, internationalization)
|
|
||||||
Bison depends on the current locale. For instance:
|
|
||||||
|
|
||||||
%define parse.error verbose
|
|
||||||
%code top {
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
void yyerror(const char* msg) { fprintf(stderr, "%s\n", msg); }
|
|
||||||
int yylex() { return 0; }
|
|
||||||
}
|
|
||||||
%%
|
|
||||||
exp: "↦" | "🎅🐃" | '\n'
|
|
||||||
%%
|
|
||||||
int main() { return yyparse(); }
|
|
||||||
|
|
||||||
gives different results with/without LC_ALL=C.
|
|
||||||
|
|
||||||
$ LC_ALL=C /opt/local/bin/bison /tmp/mangle.y -o ascii.c
|
|
||||||
$ /opt/local/bin/bison /tmp/mangle.y -o utf8.c
|
|
||||||
$ diff -u ascii.c utf8.c -I#line
|
|
||||||
--- ascii.c 2019-01-12 08:15:35.878010093 +0100
|
|
||||||
+++ utf8.c 2019-01-12 08:15:38.856495929 +0100
|
|
||||||
@@ -415,9 +415,8 @@
|
|
||||||
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
|
|
||||||
static const char *const yytname[] =
|
|
||||||
{
|
|
||||||
- "$end", "error", "$undefined", "\"\\342\\206\\246\"",
|
|
||||||
- "\"\\360\\237\\216\\205\\360\\237\\220\\203\"", "'\\n'", "$accept",
|
|
||||||
- "exp", YY_NULLPTR
|
|
||||||
+ "$end", "error", "$undefined", "\"↦\"", "\"🎅🐃\"", "'\\n'",
|
|
||||||
+ "$accept", "exp", YY_NULLPTR
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
$ gcc ascii.c -o ascii && ./ascii
|
|
||||||
syntax error, unexpected $end, expecting "\342\206\246" or "\360\237\216\205\360\237\220\203" or '\n'
|
|
||||||
$ gcc utf8.c -o utf8 && ./utf8
|
|
||||||
syntax error, unexpected $end, expecting ↦ or 🎅🐃 or '\n'
|
|
||||||
|
|
||||||
|
|
||||||
While at it, we should stop using "$end" by default, in favor of "end of
|
|
||||||
file", or "end of input", whatever. See how lalr1.java does that.
|
|
||||||
|
|
||||||
** consistency
|
** consistency
|
||||||
token vs terminal, variable vs non terminal.
|
token vs terminal, variable vs non terminal.
|
||||||
|
|
||||||
** Stop indentation in diagnostics
|
|
||||||
Before Bison 2.7, we printed "flatly" the dependencies in long diagnostics:
|
|
||||||
|
|
||||||
input.y:2.7-12: %type redeclaration for exp
|
|
||||||
input.y:1.7-12: previous declaration
|
|
||||||
|
|
||||||
In Bison 2.7, we indented them
|
|
||||||
|
|
||||||
input.y:2.7-12: error: %type redeclaration for exp
|
|
||||||
input.y:1.7-12: previous declaration
|
|
||||||
|
|
||||||
Later we quoted the source in the diagnostics, and today we have:
|
|
||||||
|
|
||||||
/tmp/foo.y:1.12-14: warning: symbol FOO redeclared [-Wother]
|
|
||||||
1 | %token FOO FOO
|
|
||||||
| ^~~
|
|
||||||
/tmp/foo.y:1.8-10: previous declaration
|
|
||||||
1 | %token FOO FOO
|
|
||||||
| ^~~
|
|
||||||
|
|
||||||
The indentation is no longer helping. We should probably get rid of it, or
|
|
||||||
maybe keep it only when -fno-caret. GCC displays this as a "note":
|
|
||||||
|
|
||||||
$ g++-mp-9 -Wall /tmp/foo.c -c
|
|
||||||
/tmp/foo.c:1:10: error: redefinition of 'int foo'
|
|
||||||
1 | int foo, foo;
|
|
||||||
| ^~~
|
|
||||||
/tmp/foo.c:1:5: note: 'int foo' previously declared here
|
|
||||||
1 | int foo, foo;
|
|
||||||
| ^~~
|
|
||||||
|
|
||||||
Likewise for Clang, contrary to what I believed (because "note:" is written
|
|
||||||
in black, so it doesn't show in my terminal :-)
|
|
||||||
|
|
||||||
$ clang++-mp-8.0 -Wall /tmp/foo.c -c
|
|
||||||
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
|
|
||||||
/tmp/foo.c:1:10: error: redefinition of 'foo'
|
|
||||||
int foo, foo;
|
|
||||||
^
|
|
||||||
/tmp/foo.c:1:5: note: previous definition is here
|
|
||||||
int foo, foo;
|
|
||||||
^
|
|
||||||
1 error generated.
|
|
||||||
|
|
||||||
See also the item "Complaint submessage indentation" below.
|
|
||||||
|
|
||||||
** api.token.raw
|
** api.token.raw
|
||||||
Maybe we should exhibit the YYUNDEFTOK token. It could also be assigned a
|
The YYUNDEFTOK could be assigned a semantic value so that yyerror could be
|
||||||
semantic value so that yyerror could be used to report invalid lexemes.
|
used to report invalid lexemes. See also the item "$undefined" below.
|
||||||
See also the item "$undefined" below.
|
|
||||||
|
|
||||||
** C++
|
** push parsers
|
||||||
Move to int everywhere instead of unsigned? stack_size, etc. The parser
|
Consider deprecating impure push parsers. They add a lot of complexity, for
|
||||||
itself uses int (for yylen for instance), yet stack is based on size_t.
|
a bad feature. On the other hand, that would make it much harder to sit
|
||||||
|
push parsers on top of pull parser. Which is currently not relevant, since
|
||||||
Maybe locations should also move to ints.
|
push parsers are measurably slower.
|
||||||
|
|
||||||
Paul Eggert already covered most of this. But before publishing these
|
|
||||||
changes, we need to ask our C++ users if they agree with that change, or if
|
|
||||||
we need some migration path. Could be a %define variable, or simply
|
|
||||||
%require "3.5".
|
|
||||||
|
|
||||||
* Bison 3.7
|
* Bison 3.7
|
||||||
|
** Counter example generation
|
||||||
|
See https://github.com/akimd/bison/pull/15.
|
||||||
|
|
||||||
|
** Clean up
|
||||||
|
Rename user_token_number for tokens as "code". It's not a "user number",
|
||||||
|
it's the token code, and the user can control it, but this code always
|
||||||
|
exists.
|
||||||
|
|
||||||
|
Rename endtoken as eoftoken.
|
||||||
|
|
||||||
|
Also do it in data/skeletons.
|
||||||
|
|
||||||
|
Don't rename in Bison 3.6 (it would be logical to do so) because that
|
||||||
|
would probably create many conflicts in Vincent's work (see previous point).
|
||||||
|
|
||||||
|
* Bison 3.8
|
||||||
** Unit rules / Injection rules (Akim Demaille)
|
** Unit rules / Injection rules (Akim Demaille)
|
||||||
Maybe we could expand unit rules (or "injections", see
|
Maybe we could expand unit rules (or "injections", see
|
||||||
https://homepages.cwi.nl/~daybuild/daily-books/syntax/2-sdf/sdf.html), i.e.,
|
https://homepages.cwi.nl/~daybuild/daily-books/syntax/2-sdf/sdf.html), i.e.,
|
||||||
@@ -170,6 +114,16 @@ functions.
|
|||||||
states/nstates, rules/nrules, ..., ritem/nritems
|
states/nstates, rules/nrules, ..., ritem/nritems
|
||||||
Fix the latter.
|
Fix the latter.
|
||||||
|
|
||||||
|
* Better error messages
|
||||||
|
The users are not provided with enough tools to forge their error messages.
|
||||||
|
See for instance "Is there an option to change the message produced by
|
||||||
|
YYERROR_VERBOSE?" by Simon Sobisch, on bison-help.
|
||||||
|
|
||||||
|
See also
|
||||||
|
https://www.cs.tufts.edu/~nr/cs257/archive/clinton-jefferey/lr-error-messages.pdf
|
||||||
|
https://research.swtch.com/yyerror
|
||||||
|
http://gallium.inria.fr/~fpottier/publis/fpottier-reachability-cc2016.pdf
|
||||||
|
|
||||||
* Modernization
|
* Modernization
|
||||||
Fix data/skeletons/yacc.c so that it defines YYPTRDIFF_T properly for modern
|
Fix data/skeletons/yacc.c so that it defines YYPTRDIFF_T properly for modern
|
||||||
and older C++ compilers. Currently the code defaults to defining it to
|
and older C++ compilers. Currently the code defaults to defining it to
|
||||||
@@ -179,10 +133,10 @@ define it to the same type as the C ptrdiff_t type.
|
|||||||
* Completion
|
* Completion
|
||||||
Several features are not available in all the backends.
|
Several features are not available in all the backends.
|
||||||
|
|
||||||
- push parsers: glr.cc, lalr1.cc
|
- push parsers: glr.c, glr.cc, lalr1.cc
|
||||||
- ielr: C++ and Java
|
- lac: D, Java
|
||||||
- glr: Java
|
- glr: D, Java
|
||||||
- token constructors: Java and C
|
- token constructors: Java, C, D
|
||||||
|
|
||||||
* Bugs
|
* Bugs
|
||||||
** Autotest has quotation issues
|
** Autotest has quotation issues
|
||||||
@@ -198,8 +152,8 @@ $ ./tests/testsuite -l | grep errors | sed q
|
|||||||
Besides yytoknum is wrong when api.token.raw is defined.
|
Besides yytoknum is wrong when api.token.raw is defined.
|
||||||
|
|
||||||
** Better design for diagnostics
|
** Better design for diagnostics
|
||||||
The current implementation of diagnostics is adhoc, it grew organically. It
|
The current implementation of diagnostics is ad hoc, it grew organically.
|
||||||
works as a series of calls to several functions, with dependency of the
|
It works as a series of calls to several functions, with dependency of the
|
||||||
latter calls on the former. For instance:
|
latter calls on the former. For instance:
|
||||||
|
|
||||||
complain (&sym->location,
|
complain (&sym->location,
|
||||||
@@ -314,47 +268,7 @@ It would be a very nice source of inspiration for the other languages.
|
|||||||
|
|
||||||
Valentin Tolmer is working on this.
|
Valentin Tolmer is working on this.
|
||||||
|
|
||||||
** YYERRCODE
|
** yychar == YYEMPTY
|
||||||
Why don't we output the token name of the error token in the output? It is
|
|
||||||
explicitly skipped:
|
|
||||||
|
|
||||||
/* Skip error token and tokens without identifier. */
|
|
||||||
if (sym != errtoken && id)
|
|
||||||
|
|
||||||
Of course there are issues with name spaces, but if we disable we have
|
|
||||||
something which seems to be more simpler and more consistent instead
|
|
||||||
of the special case YYERRCODE.
|
|
||||||
|
|
||||||
enum yytokentype {
|
|
||||||
error = 256,
|
|
||||||
// ...
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
We could (should?) also treat the case of the undef_token, which is
|
|
||||||
numbered 257 for yylex, and 2 internal. Both appear for instance in
|
|
||||||
toknum:
|
|
||||||
|
|
||||||
const unsigned short
|
|
||||||
parser::yytoken_number_[] =
|
|
||||||
{
|
|
||||||
0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
|
|
||||||
|
|
||||||
while here
|
|
||||||
|
|
||||||
enum yytokentype {
|
|
||||||
TOK_EOF = 0,
|
|
||||||
TOK_EQ = 258,
|
|
||||||
|
|
||||||
so both 256 and 257 are "mysterious".
|
|
||||||
|
|
||||||
const char*
|
|
||||||
const parser::yytname_[] =
|
|
||||||
{
|
|
||||||
"\"end of command\"", "error", "$undefined", "\"=\"", "\"break\"",
|
|
||||||
|
|
||||||
|
|
||||||
** yychar == yyempty_
|
|
||||||
The code in yyerrlab reads:
|
The code in yyerrlab reads:
|
||||||
|
|
||||||
if (yychar <= YYEOF)
|
if (yychar <= YYEOF)
|
||||||
@@ -386,14 +300,6 @@ We need trustworthy benchmarks for Bison, for all our backends. Akim has a
|
|||||||
few things scattered around; we need to put them in the repo, and make them
|
few things scattered around; we need to put them in the repo, and make them
|
||||||
more useful.
|
more useful.
|
||||||
|
|
||||||
** yysyntax_error
|
|
||||||
The code bw glr.c and yacc.c is really alike, we can certainly factor
|
|
||||||
some parts.
|
|
||||||
|
|
||||||
This should be worked on when we also address the expected improvements for
|
|
||||||
error generation (e.g., i18n).
|
|
||||||
|
|
||||||
|
|
||||||
* Report
|
* Report
|
||||||
|
|
||||||
** Figures
|
** Figures
|
||||||
@@ -431,6 +337,11 @@ An Experimental Ambiguity Detection Tool ∗ Sylvain Schmitz
|
|||||||
LORIA, INRIA Nancy - Grand Est, Nancy, France
|
LORIA, INRIA Nancy - Grand Est, Nancy, France
|
||||||
|
|
||||||
* Extensions
|
* Extensions
|
||||||
|
** More languages?
|
||||||
|
Well, only if there is really some demand for it.
|
||||||
|
|
||||||
|
https://github.com/scfc/bison-php/blob/master/data/lalr1.php
|
||||||
|
|
||||||
** Multiple start symbols
|
** Multiple start symbols
|
||||||
Would be very useful when parsing closely related languages. The idea is to
|
Would be very useful when parsing closely related languages. The idea is to
|
||||||
declare several start symbols, for instance
|
declare several start symbols, for instance
|
||||||
@@ -453,15 +364,6 @@ happen with yy_start: stmt | expr). Then adjust the skeletons so that this
|
|||||||
initial token (YY_START_STMT, YY_START_EXPR) be shifted first in the
|
initial token (YY_START_STMT, YY_START_EXPR) be shifted first in the
|
||||||
corresponding parse function.
|
corresponding parse function.
|
||||||
|
|
||||||
** Better error messages
|
|
||||||
The users are not provided with enough tools to forge their error messages.
|
|
||||||
See for instance "Is there an option to change the message produced by
|
|
||||||
YYERROR_VERBOSE?" by Simon Sobisch, on bison-help.
|
|
||||||
|
|
||||||
See also
|
|
||||||
https://www.cs.tufts.edu/~nr/cs257/archive/clinton-jefferey/lr-error-messages.pdf
|
|
||||||
and https://research.swtch.com/yyerror.
|
|
||||||
|
|
||||||
** %include
|
** %include
|
||||||
This is a popular demand. We already made many changes in the parser that
|
This is a popular demand. We already made many changes in the parser that
|
||||||
should make this reasonably easy to implement.
|
should make this reasonably easy to implement.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# Print a version string.
|
# Print a version string.
|
||||||
scriptversion=2019-01-04.17; # UTC
|
scriptversion=2020-04-13.15; # UTC
|
||||||
|
|
||||||
# Bootstrap this package from checked-out sources.
|
# Bootstrap this package from checked-out sources.
|
||||||
|
|
||||||
@@ -970,7 +970,7 @@ bootstrap_post_import_hook \
|
|||||||
# Uninitialized submodules are listed with an initial dash.
|
# Uninitialized submodules are listed with an initial dash.
|
||||||
if $use_git && git submodule | grep '^-' >/dev/null; then
|
if $use_git && git submodule | grep '^-' >/dev/null; then
|
||||||
die "some git submodules are not initialized. " \
|
die "some git submodules are not initialized. " \
|
||||||
"Run 'git submodule init' and bootstrap again."
|
"Run 'git submodule update --init' and bootstrap again."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
|
# Remove any dangling symlink matching "*.m4" or "*.[ch]" in some
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ gnulib_modules='
|
|||||||
obstack-printf
|
obstack-printf
|
||||||
perror progname
|
perror progname
|
||||||
quote quotearg
|
quote quotearg
|
||||||
|
readline
|
||||||
readme-release
|
readme-release
|
||||||
realloc-posix
|
realloc-posix
|
||||||
relocatable-prog relocatable-script
|
relocatable-prog relocatable-script
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ def update(at_file, logfile):
|
|||||||
def process(logfile):
|
def process(logfile):
|
||||||
log = contents(logfile)
|
log = contents(logfile)
|
||||||
# Look for the file to update.
|
# Look for the file to update.
|
||||||
m = re.search(r'^\d+\. ([-\w]+\.at):\d+: ', log, re.MULTILINE)
|
m = re.search(r'^\d+\. ([\-\+\w]+\.at):\d+: ', log, re.MULTILINE)
|
||||||
if not m:
|
if not m:
|
||||||
trace("no diff found:", logfile)
|
trace("no diff found:", logfile)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ exclude = \
|
|||||||
$(call exclude, \
|
$(call exclude, \
|
||||||
bindtextdomain=^lib/main.c$$ \
|
bindtextdomain=^lib/main.c$$ \
|
||||||
cast_of_argument_to_free=^src/muscle-tab.c$$ \
|
cast_of_argument_to_free=^src/muscle-tab.c$$ \
|
||||||
po_check=(^po/POTFILES.in|.md)$$ \
|
po_check=^(examples|tests)/|(^po/POTFILES.in|.md)$$ \
|
||||||
preprocessor_indentation=^data/|^lib/|^src/parse-gram.[ch]$$ \
|
preprocessor_indentation=^data/|^lib/|^src/parse-gram.[ch]$$ \
|
||||||
program_name=^lib/main.c$$ \
|
program_name=^lib/main.c$$ \
|
||||||
prohibit_always-defined_macros=^data/skeletons/yacc.c$$ \
|
prohibit_always-defined_macros=^data/skeletons/yacc.c$$ \
|
||||||
@@ -165,7 +165,7 @@ $(call exclude,
|
|||||||
prohibit_doubled_word=^tests/named-refs.at$$ \
|
prohibit_doubled_word=^tests/named-refs.at$$ \
|
||||||
prohibit_magic_number_exit=^doc/bison.texi$$ \
|
prohibit_magic_number_exit=^doc/bison.texi$$ \
|
||||||
prohibit_magic_number_exit+=?|^tests/(conflicts|regression).at$$ \
|
prohibit_magic_number_exit+=?|^tests/(conflicts|regression).at$$ \
|
||||||
prohibit_strcmp=^doc/bison\.texi|examples|tests/local\.at$$ \
|
prohibit_strcmp=^doc/bison\.texi|examples|tests \
|
||||||
prohibit_tab_based_indentation=install-icc.sh|\.(am|mk)$$|^\.git|tests/input.at|Makefile$$ \
|
prohibit_tab_based_indentation=install-icc.sh|\.(am|mk)$$|^\.git|tests/input.at|Makefile$$ \
|
||||||
require_config_h=^(lib/yyerror|data/skeletons/(glr|yacc))\.c$$ \
|
require_config_h=^(lib/yyerror|data/skeletons/(glr|yacc))\.c$$ \
|
||||||
require_config_h_first=^(lib/yyerror|data/skeletons/(glr|yacc))\.c$$ \
|
require_config_h_first=^(lib/yyerror|data/skeletons/(glr|yacc))\.c$$ \
|
||||||
|
|||||||
+12
-5
@@ -83,18 +83,20 @@ field), where field can `has_id`, `id`, etc.: see
|
|||||||
|
|
||||||
The macro `b4_symbol(NUM, FIELD)` gives access to the following FIELDS:
|
The macro `b4_symbol(NUM, FIELD)` gives access to the following FIELDS:
|
||||||
|
|
||||||
- `has_id`: 0 or 1.
|
- `has_id`: 0 or 1
|
||||||
|
|
||||||
Whether the symbol has an id.
|
Whether the symbol has an id.
|
||||||
|
|
||||||
- `id`: string
|
- `id`: string
|
||||||
If has_id, the id (prefixed by api.token.prefix if defined), otherwise
|
If has_id, the id (prefixed by api.token.prefix if defined), otherwise
|
||||||
defined as empty. Guaranteed to be usable as a C identifier.
|
defined as empty. Guaranteed to be usable as a C identifier. This is
|
||||||
|
used to define the token kind (i.e., the enum used by the return value of
|
||||||
|
yylex).
|
||||||
|
|
||||||
- `tag`: string.
|
- `tag`: string
|
||||||
A representation of the symbol. Can be 'foo', 'foo.id', '"foo"' etc.
|
A human representation of the symbol. Can be 'foo', 'foo.id', '"foo"' etc.
|
||||||
|
|
||||||
- `user_number`: integer
|
- `user_number`: integer
|
||||||
|
The code associated to the `id`.
|
||||||
The external number as used by yylex. Can be ASCII code when a character,
|
The external number as used by yylex. Can be ASCII code when a character,
|
||||||
some number chosen by bison, or some user number in the case of
|
some number chosen by bison, or some user number in the case of
|
||||||
%token FOO <NUM>. Corresponds to yychar in yacc.c.
|
%token FOO <NUM>. Corresponds to yychar in yacc.c.
|
||||||
@@ -102,7 +104,12 @@ The macro `b4_symbol(NUM, FIELD)` gives access to the following FIELDS:
|
|||||||
- `is_token`: 0 or 1
|
- `is_token`: 0 or 1
|
||||||
Whether this is a terminal symbol.
|
Whether this is a terminal symbol.
|
||||||
|
|
||||||
|
- `kind`: string
|
||||||
|
The symbol kind, i.e., the enumerator of this symbol (token or nonterminal)
|
||||||
|
which is mapping to its `number`.
|
||||||
|
|
||||||
- `number`: integer
|
- `number`: integer
|
||||||
|
The code associated to the `kind`.
|
||||||
The internal number (computed from the external number by yytranslate).
|
The internal number (computed from the external number by yytranslate).
|
||||||
Corresponds to yytoken in yacc.c. This is the same number that serves as
|
Corresponds to yytoken in yacc.c. This is the same number that serves as
|
||||||
key in b4_symbol(NUM, FIELD).
|
key in b4_symbol(NUM, FIELD).
|
||||||
|
|||||||
@@ -29,3 +29,6 @@
|
|||||||
|
|
||||||
/* "Sections" in traces (--trace). */
|
/* "Sections" in traces (--trace). */
|
||||||
.trace0 { color: green; }
|
.trace0 { color: green; }
|
||||||
|
|
||||||
|
.expected { color: green; }
|
||||||
|
.unexpected { color: red; }
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public interface Lexer
|
|||||||
* to the next token and prepares to return the semantic value
|
* to the next token and prepares to return the semantic value
|
||||||
* and beginning/ending positions of the token.
|
* and beginning/ending positions of the token.
|
||||||
* @return the token identifier corresponding to the next token. */
|
* @return the token identifier corresponding to the next token. */
|
||||||
YYTokenType yylex ();
|
TokenKind yylex ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entry point for error reporting. Emits an error
|
* Entry point for error reporting. Emits an error
|
||||||
@@ -39,7 +39,7 @@ public interface Lexer
|
|||||||
void yyerror (YYLocation loc, string s);
|
void yyerror (YYLocation loc, string s);
|
||||||
}
|
}
|
||||||
|
|
||||||
- semantic types are handled by D usions (same as for C/C++ parsers)
|
- semantic types are handled by D unions (same as for C/C++ parsers)
|
||||||
|
|
||||||
- the following (non-standard) %defines are supported:
|
- the following (non-standard) %defines are supported:
|
||||||
|
|
||||||
|
|||||||
+86
-34
@@ -384,37 +384,64 @@ m4_define([b4_glr_cc_if],
|
|||||||
## Symbols. ##
|
## Symbols. ##
|
||||||
## --------- ##
|
## --------- ##
|
||||||
|
|
||||||
# For a description of the Symbol handling, see README.
|
# For a description of the Symbol handling, see README.md.
|
||||||
#
|
#
|
||||||
# The following macros provide access to symbol related values.
|
# The following macros provide access to symbol related values.
|
||||||
|
|
||||||
# __b4_symbol(NUM, FIELD)
|
# __b4_symbol(NUM, FIELD)
|
||||||
# -----------------------
|
# -----------------------
|
||||||
# Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if
|
# Fetch FIELD of symbol #NUM. Fail if undefined.
|
||||||
# undefined.
|
|
||||||
m4_define([__b4_symbol],
|
m4_define([__b4_symbol],
|
||||||
[m4_indir([b4_symbol($1, $2)])])
|
[m4_indir([b4_symbol($1, $2)])])
|
||||||
|
|
||||||
|
|
||||||
# _b4_symbol(NUM, FIELD)
|
# _b4_symbol(NUM, FIELD)
|
||||||
# ----------------------
|
# ----------------------
|
||||||
# Recover a FIELD about symbol #NUM (or "orig NUM"). Fails if
|
# Fetch FIELD of symbol #NUM (or "orig NUM", see README.md).
|
||||||
# undefined.
|
# Fail if undefined.
|
||||||
m4_define([_b4_symbol],
|
m4_define([_b4_symbol],
|
||||||
[m4_ifdef([b4_symbol($1, number)],
|
[m4_ifdef([b4_symbol($1, number)],
|
||||||
[__b4_symbol(m4_indir([b4_symbol($1, number)]), $2)],
|
[__b4_symbol(m4_indir([b4_symbol($1, number)]), $2)],
|
||||||
[__b4_symbol([$1], [$2])])])
|
[__b4_symbol([$1], [$2])])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_symbol_token_kind(NUM)
|
||||||
|
# -------------------------
|
||||||
|
# The token kind of this symbol.
|
||||||
|
m4_define([b4_symbol_token_kind],
|
||||||
|
[b4_percent_define_get([api.token.prefix])dnl
|
||||||
|
_b4_symbol([$1], [id])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_symbol_kind(NUM)
|
||||||
|
# -------------------
|
||||||
|
# Build the name of the kind of this symbol. It must always exist,
|
||||||
|
# otherwise some symbols might not be represented in the enum, which
|
||||||
|
# might be compiled into too small a type to contain all the symbol
|
||||||
|
# numbers.
|
||||||
|
m4_define([b4_symbol_prefix], [b4_percent_define_get([api.symbol.prefix])])
|
||||||
|
m4_define([b4_symbol_kind],
|
||||||
|
[b4_percent_define_get([api.symbol.prefix])dnl
|
||||||
|
m4_case([$1],
|
||||||
|
[-2], [[YYEMPTY]],
|
||||||
|
[0], [[YYEOF]],
|
||||||
|
[1], [[YYERROR]],
|
||||||
|
[2], [[YYUNDEF]],
|
||||||
|
[m4_case(b4_symbol([$1], [tag]),
|
||||||
|
[$accept], [[YYACCEPT]],
|
||||||
|
[b4_symbol_if([$1], [has_id], _b4_symbol([$1], [id]),
|
||||||
|
[m4_bpatsubst([$1-][]_b4_symbol([$1], [tag]), [[^a-zA-Z_0-9]+], [_])])])])])
|
||||||
|
|
||||||
|
|
||||||
# b4_symbol(NUM, FIELD)
|
# b4_symbol(NUM, FIELD)
|
||||||
# ---------------------
|
# ---------------------
|
||||||
# Recover a FIELD about symbol #NUM (or "orig NUM"). Fails if
|
# Fetch FIELD of symbol #NUM (or "orig NUM"). Fail if undefined.
|
||||||
# undefined. If FIELD = id, prepend the token prefix.
|
#
|
||||||
|
# If FIELD = id, prepend the token prefix.
|
||||||
m4_define([b4_symbol],
|
m4_define([b4_symbol],
|
||||||
[m4_case([$2],
|
[m4_case([$2],
|
||||||
[id], [m4_do([b4_percent_define_get([api.token.prefix])],
|
[id], [b4_symbol_token_kind([$1])],
|
||||||
[_b4_symbol([$1], [id])])],
|
[kind], [b4_symbol_kind([$1])],
|
||||||
[_b4_symbol($@)])])
|
[_b4_symbol($@)])])
|
||||||
|
|
||||||
|
|
||||||
@@ -437,9 +464,9 @@ m4_define([b4_symbol_tag_comment],
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
# b4_symbol_action(SYMBOL-NUM, KIND)
|
# b4_symbol_action(SYMBOL-NUM, ACTION)
|
||||||
# ----------------------------------
|
# ------------------------------------
|
||||||
# Run the action KIND (destructor or printer) for SYMBOL-NUM.
|
# Run the action ACTION ("destructor" or "printer") for SYMBOL-NUM.
|
||||||
m4_define([b4_symbol_action],
|
m4_define([b4_symbol_action],
|
||||||
[b4_symbol_if([$1], [has_$2],
|
[b4_symbol_if([$1], [has_$2],
|
||||||
[b4_dollar_pushdef([(*yyvaluep)],
|
[b4_dollar_pushdef([(*yyvaluep)],
|
||||||
@@ -463,21 +490,21 @@ m4_define([b4_symbol_destructor], [b4_symbol_action([$1], [destructor])])
|
|||||||
m4_define([b4_symbol_printer], [b4_symbol_action([$1], [printer])])
|
m4_define([b4_symbol_printer], [b4_symbol_action([$1], [printer])])
|
||||||
|
|
||||||
|
|
||||||
# b4_symbol_actions(KIND, [TYPE = yytype])
|
# b4_symbol_actions(ACTION, [KIND = yykind])
|
||||||
# ----------------------------------------
|
# ------------------------------------------
|
||||||
# Emit the symbol actions for KIND ("printer" or "destructor").
|
# Emit the symbol actions for ACTION ("destructor" or "printer").
|
||||||
# Dispatch on TYPE.
|
# Dispatch on KIND.
|
||||||
m4_define([b4_symbol_actions],
|
m4_define([b4_symbol_actions],
|
||||||
[m4_pushdef([b4_actions_], m4_expand([b4_symbol_foreach([b4_symbol_$1])]))dnl
|
[m4_pushdef([b4_actions_], m4_expand([b4_symbol_foreach([b4_symbol_$1])]))dnl
|
||||||
m4_ifval(m4_defn([b4_actions_]),
|
m4_ifval(m4_defn([b4_actions_]),
|
||||||
[switch (m4_default([$2], [yytype]))
|
[switch (m4_default([$2], [yykind]))
|
||||||
{
|
{
|
||||||
m4_defn([b4_actions_])[]dnl
|
m4_defn([b4_actions_])[]dnl
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}dnl
|
}dnl
|
||||||
],
|
],
|
||||||
[YYUSE (m4_default([$2], [yytype]));])dnl
|
[YYUSE (m4_default([$2], [yykind]));])dnl
|
||||||
m4_popdef([b4_actions_])dnl
|
m4_popdef([b4_actions_])dnl
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -507,13 +534,14 @@ m4_define([b4_symbol_map],
|
|||||||
|
|
||||||
# b4_token_visible_if(NUM, IF-TRUE, IF-FALSE)
|
# b4_token_visible_if(NUM, IF-TRUE, IF-FALSE)
|
||||||
# -------------------------------------------
|
# -------------------------------------------
|
||||||
# Whether NUM denotes a token that has an exported definition (i.e.,
|
# Whether NUM denotes a token kind that has an exported definition
|
||||||
# shows in enum yytokentype).
|
# (i.e., shows in enum yytokentype).
|
||||||
m4_define([b4_token_visible_if],
|
m4_define([b4_token_visible_if],
|
||||||
[b4_symbol_if([$1], [is_token],
|
[b4_symbol_if([$1], [is_token],
|
||||||
[b4_symbol_if([$1], [has_id], [$2], [$3])],
|
[b4_symbol_if([$1], [has_id], [$2], [$3])],
|
||||||
[$3])])
|
[$3])])
|
||||||
|
|
||||||
|
|
||||||
# b4_token_has_definition(NUM)
|
# b4_token_has_definition(NUM)
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
# 1 if NUM is visible, nothing otherwise.
|
# 1 if NUM is visible, nothing otherwise.
|
||||||
@@ -530,13 +558,27 @@ m4_define([b4_any_token_visible_if],
|
|||||||
|
|
||||||
# b4_token_format(FORMAT, NUM)
|
# b4_token_format(FORMAT, NUM)
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
|
# If token NUM has a visible ID, format FORMAT with ID, USER_NUMBER.
|
||||||
m4_define([b4_token_format],
|
m4_define([b4_token_format],
|
||||||
[b4_token_visible_if([$2],
|
[b4_token_visible_if([$2],
|
||||||
[m4_format([[$1]],
|
[m4_format([[$1]],
|
||||||
m4_quote(b4_symbol([$2], [id])),
|
m4_expand(b4_symbol([$2], [id])),
|
||||||
m4_quote(b4_symbol([$2], b4_api_token_raw_if([[number]], [[user_number]]))))])])
|
m4_expand(b4_symbol([$2], b4_api_token_raw_if([[number]], [[user_number]]))))])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_last_enum_token
|
||||||
|
# ------------------
|
||||||
|
# The code of the last token visible token.
|
||||||
|
m4_define([_b4_last_enum_token],
|
||||||
|
[b4_token_visible_if([$1],
|
||||||
|
[m4_define([b4_last_enum_token], [$1])])])
|
||||||
|
b4_symbol_foreach([_b4_last_enum_token])
|
||||||
|
|
||||||
|
# b4_last_symbol
|
||||||
|
# --------------
|
||||||
|
# The code of the last symbol.
|
||||||
|
m4_define([b4_last_symbol], m4_eval(b4_tokens_number + b4_nterms_number - 1))
|
||||||
|
|
||||||
## ------- ##
|
## ------- ##
|
||||||
## Types. ##
|
## Types. ##
|
||||||
## ------- ##
|
## ------- ##
|
||||||
@@ -603,7 +645,7 @@ m4_define([b4_sync_end], [ b4_comment([$2:$1])]
|
|||||||
# This generates dependencies on the Bison skeletons hence lots of
|
# This generates dependencies on the Bison skeletons hence lots of
|
||||||
# useless 'git diff'. This location is useless for the regular
|
# useless 'git diff'. This location is useless for the regular
|
||||||
# user (who does not care about the skeletons) and is actually not
|
# user (who does not care about the skeletons) and is actually not
|
||||||
# useful for Bison developpers too (I, Akim, never used this to locate
|
# useful for Bison developers too (I, Akim, never used this to locate
|
||||||
# the code in skeletons that generated output). So disable it
|
# the code in skeletons that generated output). So disable it
|
||||||
# completely. If someone thinks this was actually useful, a %define
|
# completely. If someone thinks this was actually useful, a %define
|
||||||
# variable should be provided to control the level of verbosity of
|
# variable should be provided to control the level of verbosity of
|
||||||
@@ -1016,21 +1058,23 @@ m4_define([b4_bison_locations_if],
|
|||||||
[b4_locations_if([b4_percent_define_ifdef([[api.location.type]], [], [$1])])])
|
[b4_locations_if([b4_percent_define_ifdef([[api.location.type]], [], [$1])])])
|
||||||
|
|
||||||
|
|
||||||
# b4_error_verbose_if([IF-ERRORS-ARE-VERBOSE], [IF-NOT])
|
|
||||||
|
# %define parse.error "(custom|detailed|simple|verbose)"
|
||||||
# ------------------------------------------------------
|
# ------------------------------------------------------
|
||||||
# Map %define parse.error "(simple|verbose)" to b4_error_verbose_if and
|
|
||||||
# b4_error_verbose_flag.
|
|
||||||
b4_percent_define_default([[parse.error]], [[simple]])
|
b4_percent_define_default([[parse.error]], [[simple]])
|
||||||
b4_percent_define_check_values([[[[parse.error]],
|
b4_percent_define_check_values([[[[parse.error]],
|
||||||
[[simple]], [[verbose]]]])
|
[[custom]], [[detailed]], [[simple]], [[verbose]]]])
|
||||||
m4_define([b4_error_verbose_flag],
|
|
||||||
[m4_case(b4_percent_define_get([[parse.error]]),
|
# b4_parse_error_case(CASE1, THEN1, CASE2, THEN2, ..., ELSE)
|
||||||
[simple], [[0]],
|
# ----------------------------------------------------------
|
||||||
[verbose], [[1]])])
|
m4_define([b4_parse_error_case],
|
||||||
b4_define_flag_if([error_verbose])
|
[m4_case(b4_percent_define_get([[parse.error]]), $@)])
|
||||||
|
|
||||||
|
# b4_parse_error_bmatch(PATTERN1, THEN1, PATTERN2, THEN2, ..., ELSE)
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
m4_define([b4_parse_error_bmatch],
|
||||||
|
[m4_bmatch(b4_percent_define_get([[parse.error]]), $@)])
|
||||||
|
|
||||||
# yytoken_table is needed to support verbose errors.
|
|
||||||
b4_error_verbose_if([m4_define([b4_token_table_flag], [1])])
|
|
||||||
|
|
||||||
|
|
||||||
# b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT])
|
# b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT])
|
||||||
@@ -1116,3 +1160,11 @@ b4_percent_define_ifdef([api.value.type],
|
|||||||
|
|
||||||
# api.value.union.name.
|
# api.value.union.name.
|
||||||
b4_percent_define_check_kind([api.value.union.name], [keyword])
|
b4_percent_define_check_kind([api.value.union.name], [keyword])
|
||||||
|
|
||||||
|
# parse.error (custom|detailed) >< token-table.
|
||||||
|
b4_token_table_if(
|
||||||
|
[b4_parse_error_bmatch([custom\|detailed],
|
||||||
|
[b4_complain_at(b4_percent_define_get_loc([parse.error]),
|
||||||
|
[['%s' and '%s' cannot be used together]],
|
||||||
|
[%token-table],
|
||||||
|
[%define parse.error (custom|detailed)])])])
|
||||||
|
|||||||
+92
-56
@@ -22,6 +22,8 @@ b4_percent_define_ifdef([[api.value.union.name]],
|
|||||||
[b4_complain_at(b4_percent_define_get_loc([[api.value.union.name]]),
|
[b4_complain_at(b4_percent_define_get_loc([[api.value.union.name]]),
|
||||||
[named %union is invalid in C++])])
|
[named %union is invalid in C++])])
|
||||||
|
|
||||||
|
b4_percent_define_default([[api.symbol.prefix]], [[S_]])
|
||||||
|
|
||||||
m4_include(b4_skeletonsdir/[c.m4])
|
m4_include(b4_skeletonsdir/[c.m4])
|
||||||
|
|
||||||
b4_percent_define_check_kind([api.namespace], [code], [deprecated])
|
b4_percent_define_check_kind([api.namespace], [code], [deprecated])
|
||||||
@@ -160,20 +162,42 @@ m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]),
|
|||||||
[::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])])
|
[::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])])
|
||||||
|
|
||||||
|
|
||||||
|
## ------------- ##
|
||||||
|
## Token kinds. ##
|
||||||
|
## ------------- ##
|
||||||
|
|
||||||
|
|
||||||
# b4_token_enums
|
# b4_token_enums
|
||||||
# --------------
|
# --------------
|
||||||
# Output the definition of the tokens as enums.
|
# Output the definition of the token kinds.
|
||||||
m4_define([b4_token_enums],
|
m4_define([b4_token_enums],
|
||||||
[[enum yytokentype
|
[[enum token_kind_type
|
||||||
{
|
{
|
||||||
]m4_join([,
|
]b4_symbol([-2], [id])[ = -2,
|
||||||
],
|
]b4_symbol_foreach([b4_token_enum])dnl
|
||||||
b4_symbol_map([b4_token_enum]))[
|
[ };]dnl
|
||||||
};]dnl
|
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## -------------- ##
|
||||||
|
## Symbol kinds. ##
|
||||||
|
## -------------- ##
|
||||||
|
|
||||||
|
# b4_declare_symbol_enum
|
||||||
|
# ----------------------
|
||||||
|
# The definition of the symbol internal numbers as an enum.
|
||||||
|
# Defining YYEMPTY here is important: it forces the compiler
|
||||||
|
# to use a signed type, which matters for yytoken.
|
||||||
|
m4_define([b4_declare_symbol_enum],
|
||||||
|
[[enum symbol_kind_type
|
||||||
|
{
|
||||||
|
YYNTOKENS = ]b4_tokens_number[, ///< Number of tokens.
|
||||||
|
]b4_symbol_kind([-2])[ = -2,
|
||||||
|
]b4_symbol_foreach([ b4_symbol_enum])dnl
|
||||||
|
[ };]])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## ----------------- ##
|
## ----------------- ##
|
||||||
## Semantic Values. ##
|
## Semantic Values. ##
|
||||||
@@ -231,23 +255,31 @@ m4_define([b4_public_types_declare],
|
|||||||
location_type location;])[
|
location_type location;])[
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Tokens.
|
/// Token kinds.
|
||||||
struct token
|
struct token
|
||||||
{
|
{
|
||||||
]b4_token_enums[
|
]b4_token_enums[
|
||||||
|
/// Backward compatibility alias.
|
||||||
|
typedef token_kind_type yytokentype;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// (External) token type, as returned by yylex.
|
/// Token kind, as returned by yylex.
|
||||||
typedef token::yytokentype token_type;
|
typedef token::yytokentype token_kind_type;
|
||||||
|
|
||||||
/// Symbol type: an internal symbol number.
|
/// Backward compatibility alias.
|
||||||
typedef int symbol_number_type;
|
typedef token_kind_type token_type;
|
||||||
|
|
||||||
/// The symbol type number to denote an empty symbol.
|
/// Symbol kinds.
|
||||||
enum { empty_symbol = -2 };
|
struct symbol_kind
|
||||||
|
{
|
||||||
|
]b4_declare_symbol_enum[
|
||||||
|
};
|
||||||
|
|
||||||
/// Internal symbol number for tokens (subsumed by symbol_number_type).
|
/// (Internal) symbol kind.
|
||||||
typedef ]b4_int_type_for([b4_translate])[ token_number_type;
|
typedef symbol_kind::symbol_kind_type symbol_kind_type;
|
||||||
|
|
||||||
|
/// The number of tokens.
|
||||||
|
static const symbol_kind_type YYNTOKENS = symbol_kind::YYNTOKENS;
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
|
||||||
@@ -258,8 +290,8 @@ m4_define([b4_public_types_declare],
|
|||||||
m4_define([b4_symbol_type_define],
|
m4_define([b4_symbol_type_define],
|
||||||
[[ /// A complete symbol.
|
[[ /// A complete symbol.
|
||||||
///
|
///
|
||||||
/// Expects its Base type to provide access to the symbol type
|
/// Expects its Base type to provide access to the symbol kind
|
||||||
/// via type_get ().
|
/// via kind ().
|
||||||
///
|
///
|
||||||
/// Provide access to semantic value]b4_locations_if([ and location])[.
|
/// Provide access to semantic value]b4_locations_if([ and location])[.
|
||||||
template <typename Base>
|
template <typename Base>
|
||||||
@@ -276,7 +308,14 @@ m4_define([b4_symbol_type_define],
|
|||||||
|
|
||||||
#if 201103L <= YY_CPLUSPLUS
|
#if 201103L <= YY_CPLUSPLUS
|
||||||
/// Move constructor.
|
/// Move constructor.
|
||||||
basic_symbol (basic_symbol&& that);
|
basic_symbol (basic_symbol&& that)
|
||||||
|
: Base (std::move (that))
|
||||||
|
, value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([
|
||||||
|
, location (std::move (that.location))])[
|
||||||
|
{]b4_variant_if([
|
||||||
|
b4_symbol_variant([this->kind ()], [value], [move],
|
||||||
|
[std::move (that.value)])
|
||||||
|
])[}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Copy constructor.
|
/// Copy constructor.
|
||||||
@@ -303,10 +342,10 @@ m4_define([b4_symbol_type_define],
|
|||||||
void clear ()
|
void clear ()
|
||||||
{]b4_variant_if([[
|
{]b4_variant_if([[
|
||||||
// User destructor.
|
// User destructor.
|
||||||
symbol_number_type yytype = this->type_get ();
|
symbol_kind_type yykind = this->kind ();
|
||||||
basic_symbol<Base>& yysym = *this;
|
basic_symbol<Base>& yysym = *this;
|
||||||
(void) yysym;
|
(void) yysym;
|
||||||
switch (yytype)
|
switch (yykind)
|
||||||
{
|
{
|
||||||
]b4_symbol_foreach([b4_symbol_destructor])dnl
|
]b4_symbol_foreach([b4_symbol_destructor])dnl
|
||||||
[ default:
|
[ default:
|
||||||
@@ -314,10 +353,13 @@ m4_define([b4_symbol_type_define],
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Type destructor.
|
// Type destructor.
|
||||||
]b4_symbol_variant([[yytype]], [[value]], [[template destroy]])])[
|
]b4_symbol_variant([[yykind]], [[value]], [[template destroy]])])[
|
||||||
Base::clear ();
|
Base::clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Backward compatibility.
|
||||||
|
symbol_kind_type type_get () const YY_NOEXCEPT;
|
||||||
|
|
||||||
/// Whether empty.
|
/// Whether empty.
|
||||||
bool empty () const YY_NOEXCEPT;
|
bool empty () const YY_NOEXCEPT;
|
||||||
|
|
||||||
@@ -351,8 +393,8 @@ m4_define([b4_symbol_type_define],
|
|||||||
/// Copy constructor.
|
/// Copy constructor.
|
||||||
by_type (const by_type& that);
|
by_type (const by_type& that);
|
||||||
|
|
||||||
/// The symbol type as needed by the constructor.
|
/// The symbol kind as needed by the constructor.
|
||||||
typedef token_type kind_type;
|
typedef token_kind_type kind_type;
|
||||||
|
|
||||||
/// Constructor from (external) token numbers.
|
/// Constructor from (external) token numbers.
|
||||||
by_type (kind_type t);
|
by_type (kind_type t);
|
||||||
@@ -360,17 +402,16 @@ m4_define([b4_symbol_type_define],
|
|||||||
/// Record that this symbol is empty.
|
/// Record that this symbol is empty.
|
||||||
void clear ();
|
void clear ();
|
||||||
|
|
||||||
/// Steal the symbol type from \a that.
|
/// Steal the symbol kind from \a that.
|
||||||
void move (by_type& that);
|
void move (by_type& that);
|
||||||
|
|
||||||
/// The (internal) type number (corresponding to \a type).
|
/// The (internal) type number (corresponding to \a type).
|
||||||
/// \a empty when empty.
|
/// \a empty when empty.
|
||||||
symbol_number_type type_get () const YY_NOEXCEPT;
|
symbol_kind_type kind () const YY_NOEXCEPT;
|
||||||
|
|
||||||
/// The symbol type.
|
/// The symbol kind.
|
||||||
/// \a empty_symbol when empty.
|
/// \a ]b4_symbol_prefix[YYEMPTY when empty.
|
||||||
/// An int, not token_number_type, to be able to store empty_symbol.
|
symbol_kind_type type;
|
||||||
int type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// "External" symbols: returned by the scanner.
|
/// "External" symbols: returned by the scanner.
|
||||||
@@ -393,25 +434,13 @@ m4_define([b4_symbol_type_define],
|
|||||||
# Provide the implementation needed by the public types.
|
# Provide the implementation needed by the public types.
|
||||||
m4_define([b4_public_types_define],
|
m4_define([b4_public_types_define],
|
||||||
[[ // basic_symbol.
|
[[ // basic_symbol.
|
||||||
#if 201103L <= YY_CPLUSPLUS
|
|
||||||
template <typename Base>
|
|
||||||
]b4_parser_class[::basic_symbol<Base>::basic_symbol (basic_symbol&& that)
|
|
||||||
: Base (std::move (that))
|
|
||||||
, value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([
|
|
||||||
, location (std::move (that.location))])[
|
|
||||||
{]b4_variant_if([
|
|
||||||
b4_symbol_variant([this->type_get ()], [value], [move],
|
|
||||||
[std::move (that.value)])
|
|
||||||
])[}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <typename Base>
|
template <typename Base>
|
||||||
]b4_parser_class[::basic_symbol<Base>::basic_symbol (const basic_symbol& that)
|
]b4_parser_class[::basic_symbol<Base>::basic_symbol (const basic_symbol& that)
|
||||||
: Base (that)
|
: Base (that)
|
||||||
, value (]b4_variant_if([], [that.value]))b4_locations_if([
|
, value (]b4_variant_if([], [that.value]))b4_locations_if([
|
||||||
, location (that.location)])[
|
, location (that.location)])[
|
||||||
{]b4_variant_if([
|
{]b4_variant_if([
|
||||||
b4_symbol_variant([this->type_get ()], [value], [copy],
|
b4_symbol_variant([this->kind ()], [value], [copy],
|
||||||
[YY_MOVE (that.value)])
|
[YY_MOVE (that.value)])
|
||||||
])[}
|
])[}
|
||||||
|
|
||||||
@@ -436,13 +465,20 @@ m4_define([b4_public_types_define],
|
|||||||
, location (YY_MOVE (l))])[
|
, location (YY_MOVE (l))])[
|
||||||
{]b4_variant_if([[
|
{]b4_variant_if([[
|
||||||
(void) v;
|
(void) v;
|
||||||
]b4_symbol_variant([this->type_get ()], [value], [YY_MOVE_OR_COPY], [YY_MOVE (v)])])[}]])[
|
]b4_symbol_variant([this->kind ()], [value], [YY_MOVE_OR_COPY], [YY_MOVE (v)])])[}]])[
|
||||||
|
|
||||||
|
template <typename Base>
|
||||||
|
]b4_parser_class[::symbol_kind_type
|
||||||
|
]b4_parser_class[::basic_symbol<Base>::type_get () const YY_NOEXCEPT
|
||||||
|
{
|
||||||
|
return this->kind ();
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Base>
|
template <typename Base>
|
||||||
bool
|
bool
|
||||||
]b4_parser_class[::basic_symbol<Base>::empty () const YY_NOEXCEPT
|
]b4_parser_class[::basic_symbol<Base>::empty () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
return Base::type_get () == empty_symbol;
|
return this->kind () == symbol_kind::]b4_symbol_prefix[YYEMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Base>
|
template <typename Base>
|
||||||
@@ -450,7 +486,7 @@ m4_define([b4_public_types_define],
|
|||||||
]b4_parser_class[::basic_symbol<Base>::move (basic_symbol& s)
|
]b4_parser_class[::basic_symbol<Base>::move (basic_symbol& s)
|
||||||
{
|
{
|
||||||
super_type::move (s);
|
super_type::move (s);
|
||||||
]b4_variant_if([b4_symbol_variant([this->type_get ()], [value], [move],
|
]b4_variant_if([b4_symbol_variant([this->kind ()], [value], [move],
|
||||||
[YY_MOVE (s.value)])],
|
[YY_MOVE (s.value)])],
|
||||||
[value = YY_MOVE (s.value);])[]b4_locations_if([
|
[value = YY_MOVE (s.value);])[]b4_locations_if([
|
||||||
location = YY_MOVE (s.location);])[
|
location = YY_MOVE (s.location);])[
|
||||||
@@ -458,7 +494,7 @@ m4_define([b4_public_types_define],
|
|||||||
|
|
||||||
// by_type.
|
// by_type.
|
||||||
]b4_inline([$1])b4_parser_class[::by_type::by_type ()
|
]b4_inline([$1])b4_parser_class[::by_type::by_type ()
|
||||||
: type (empty_symbol)
|
: type (symbol_kind::]b4_symbol_prefix[YYEMPTY)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
#if 201103L <= YY_CPLUSPLUS
|
#if 201103L <= YY_CPLUSPLUS
|
||||||
@@ -473,14 +509,14 @@ m4_define([b4_public_types_define],
|
|||||||
: type (that.type)
|
: type (that.type)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
]b4_inline([$1])b4_parser_class[::by_type::by_type (token_type t)
|
]b4_inline([$1])b4_parser_class[::by_type::by_type (token_kind_type t)
|
||||||
: type (yytranslate_ (t))
|
: type (yytranslate_ (t))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
]b4_inline([$1])[void
|
]b4_inline([$1])[void
|
||||||
]b4_parser_class[::by_type::clear ()
|
]b4_parser_class[::by_type::clear ()
|
||||||
{
|
{
|
||||||
type = empty_symbol;
|
type = symbol_kind::]b4_symbol_prefix[YYEMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
]b4_inline([$1])[void
|
]b4_inline([$1])[void
|
||||||
@@ -490,8 +526,8 @@ m4_define([b4_public_types_define],
|
|||||||
that.clear ();
|
that.clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
]b4_inline([$1])[int
|
]b4_inline([$1])[]b4_parser_class[::symbol_kind_type
|
||||||
]b4_parser_class[::by_type::type_get () const YY_NOEXCEPT
|
]b4_parser_class[::by_type::kind () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@@ -510,15 +546,15 @@ m4_define([b4_token_constructor_define], [])
|
|||||||
# Define yytranslate_. Sometimes used in the header file ($1=hh),
|
# Define yytranslate_. Sometimes used in the header file ($1=hh),
|
||||||
# sometimes in the cc file.
|
# sometimes in the cc file.
|
||||||
m4_define([b4_yytranslate_define],
|
m4_define([b4_yytranslate_define],
|
||||||
[ b4_inline([$1])b4_parser_class[::token_number_type
|
[ b4_inline([$1])b4_parser_class[::symbol_kind_type
|
||||||
]b4_parser_class[::yytranslate_ (int t)
|
]b4_parser_class[::yytranslate_ (int t)
|
||||||
{
|
{
|
||||||
]b4_api_token_raw_if(
|
]b4_api_token_raw_if(
|
||||||
[[ return static_cast<token_number_type> (t);]],
|
[[ return static_cast<symbol_kind_type> (t);]],
|
||||||
[[ // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to
|
[[ // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to
|
||||||
// TOKEN-NUM as returned by yylex.
|
// TOKEN-NUM as returned by yylex.
|
||||||
static
|
static
|
||||||
const token_number_type
|
const ]b4_int_type_for([b4_translate])[
|
||||||
translate_table[] =
|
translate_table[] =
|
||||||
{
|
{
|
||||||
]b4_translate[
|
]b4_translate[
|
||||||
@@ -526,11 +562,11 @@ m4_define([b4_yytranslate_define],
|
|||||||
const int user_token_number_max_ = ]b4_user_token_number_max[;
|
const int user_token_number_max_ = ]b4_user_token_number_max[;
|
||||||
|
|
||||||
if (t <= 0)
|
if (t <= 0)
|
||||||
return yyeof_;
|
return symbol_kind::]b4_symbol_prefix[YYEOF;
|
||||||
else if (t <= user_token_number_max_)
|
else if (t <= user_token_number_max_)
|
||||||
return translate_table[t];
|
return YY_CAST (symbol_kind_type, translate_table[t]);
|
||||||
else
|
else
|
||||||
return yy_undef_token_;]])[
|
return symbol_kind::]b4_symbol_prefix[YYUNDEF;]])[
|
||||||
}
|
}
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
|||||||
+103
-70
@@ -101,6 +101,7 @@ m4_define_default([b4_prefix], [b4_api_prefix])
|
|||||||
b4_percent_define_default([[api.value.union.name]],
|
b4_percent_define_default([[api.value.union.name]],
|
||||||
[b4_api_PREFIX[][STYPE]])
|
[b4_api_PREFIX[][STYPE]])
|
||||||
|
|
||||||
|
b4_percent_define_default([[api.symbol.prefix]], [[YYSYMBOL_]])
|
||||||
|
|
||||||
## ------------------------ ##
|
## ------------------------ ##
|
||||||
## Pure/impure interfaces. ##
|
## Pure/impure interfaces. ##
|
||||||
@@ -129,6 +130,13 @@ m4_define([b4_user_args],
|
|||||||
[m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])])
|
[m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_user_formals
|
||||||
|
# ---------------
|
||||||
|
# The possible parse-params formal arguments preceded by a comma.
|
||||||
|
m4_define([b4_user_formals],
|
||||||
|
[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])])
|
||||||
|
|
||||||
|
|
||||||
# b4_parse_param
|
# b4_parse_param
|
||||||
# --------------
|
# --------------
|
||||||
# If defined, b4_parse_param arrives double quoted, but below we prefer
|
# If defined, b4_parse_param arrives double quoted, but below we prefer
|
||||||
@@ -418,9 +426,22 @@ static const b4_int_type_for([$2]) yy$1[[]] =
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
## ------------------------- ##
|
## ------------- ##
|
||||||
## Assigning token numbers. ##
|
## Token kinds. ##
|
||||||
## ------------------------- ##
|
## ------------- ##
|
||||||
|
|
||||||
|
# Because C enums are not scoped, because tokens are exposed in the
|
||||||
|
# header, and because these tokens are common to all the parsers, we
|
||||||
|
# need to make sure their names don't collide: use the api.prefix.
|
||||||
|
# YYEOF is special, since the user may give it a different name.
|
||||||
|
m4_define([b4_symbol(-2, id)], [b4_api_PREFIX[][EMPTY]])
|
||||||
|
m4_define([b4_symbol(-2, tag)], [[No symbol.]])
|
||||||
|
|
||||||
|
m4_if(b4_symbol(0, id), [YYEOF],
|
||||||
|
[m4_define([b4_symbol(0, id)], [b4_api_PREFIX[][EOF]])])
|
||||||
|
m4_define([b4_symbol(1, id)], [b4_api_PREFIX[][ERRCODE]])
|
||||||
|
m4_define([b4_symbol(2, id)], [b4_api_PREFIX[][UNDEF]])
|
||||||
|
|
||||||
|
|
||||||
# b4_token_define(TOKEN-NUM)
|
# b4_token_define(TOKEN-NUM)
|
||||||
# --------------------------
|
# --------------------------
|
||||||
@@ -432,7 +453,7 @@ m4_define([b4_token_define],
|
|||||||
# ----------------
|
# ----------------
|
||||||
# Output the definition of the tokens.
|
# Output the definition of the tokens.
|
||||||
m4_define([b4_token_defines],
|
m4_define([b4_token_defines],
|
||||||
[b4_any_token_visible_if([/* Tokens. */
|
[b4_any_token_visible_if([/* Token kinds. */
|
||||||
m4_join([
|
m4_join([
|
||||||
], b4_symbol_map([b4_token_define]))
|
], b4_symbol_map([b4_token_define]))
|
||||||
])])
|
])])
|
||||||
@@ -442,34 +463,81 @@ m4_join([
|
|||||||
# ------------------------
|
# ------------------------
|
||||||
# Output the definition of this token as an enum.
|
# Output the definition of this token as an enum.
|
||||||
m4_define([b4_token_enum],
|
m4_define([b4_token_enum],
|
||||||
[b4_token_format([%s = %s], [$1])])
|
[b4_token_visible_if([$1],
|
||||||
|
[m4_format([ %-30s %s],
|
||||||
|
m4_format([[%s = %s%s%s]],
|
||||||
|
b4_symbol([$1], [id]),
|
||||||
|
b4_symbol([$1], b4_api_token_raw_if([[number]], [[user_number]])),
|
||||||
|
m4_if([$1], b4_last_enum_token, [], [[,]])),
|
||||||
|
[b4_symbol_tag_comment([$1])])])])
|
||||||
|
|
||||||
|
|
||||||
# b4_token_enums
|
# b4_token_enums
|
||||||
# --------------
|
# --------------
|
||||||
# Output the definition of the tokens (if there are) as enums.
|
# The definition of the token kinds.
|
||||||
m4_define([b4_token_enums],
|
m4_define([b4_token_enums],
|
||||||
[b4_any_token_visible_if([[/* Token type. */
|
[b4_any_token_visible_if([[/* Token kinds. */
|
||||||
#ifndef ]b4_api_PREFIX[TOKENTYPE
|
#ifndef ]b4_api_PREFIX[TOKENTYPE
|
||||||
# define ]b4_api_PREFIX[TOKENTYPE
|
# define ]b4_api_PREFIX[TOKENTYPE
|
||||||
enum ]b4_api_prefix[tokentype
|
enum ]b4_api_prefix[tokentype
|
||||||
{
|
{
|
||||||
]m4_join([,
|
]b4_symbol([-2], [id])[ = -2,
|
||||||
],
|
]b4_symbol_foreach([b4_token_enum])dnl
|
||||||
b4_symbol_map([b4_token_enum]))[
|
[ };
|
||||||
};
|
typedef enum ]b4_api_prefix[tokentype ]b4_api_prefix[token_kind_t;
|
||||||
#endif
|
#endif
|
||||||
]])])
|
]])])
|
||||||
|
|
||||||
|
|
||||||
# b4_token_enums_defines
|
# b4_token_enums_defines
|
||||||
# ----------------------
|
# ----------------------
|
||||||
# Output the definition of the tokens (if there are any) as enums and,
|
# The definition of the tokens (if there are any) as enums and,
|
||||||
# if POSIX Yacc is enabled, as #defines.
|
# if POSIX Yacc is enabled, as #defines.
|
||||||
m4_define([b4_token_enums_defines],
|
m4_define([b4_token_enums_defines],
|
||||||
[b4_token_enums[]b4_yacc_if([b4_token_defines])])
|
[b4_token_enums[]b4_yacc_if([b4_token_defines])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_symbol_translate(STRING)
|
||||||
|
# ---------------------------
|
||||||
|
# Used by "bison" in the array of symbol names to mark those that
|
||||||
|
# require translation.
|
||||||
|
m4_define([b4_symbol_translate],
|
||||||
|
[[N_($1)]])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## -------------- ##
|
||||||
|
## Symbol kinds. ##
|
||||||
|
## -------------- ##
|
||||||
|
|
||||||
|
# b4_symbol_enum(SYMBOL-NUM)
|
||||||
|
# --------------------------
|
||||||
|
# Output the definition of this symbol as an enum.
|
||||||
|
m4_define([b4_symbol_enum],
|
||||||
|
[m4_format([ %-40s %s],
|
||||||
|
m4_format([[%s = %s%s%s]],
|
||||||
|
b4_symbol([$1], [kind]),
|
||||||
|
[$1],
|
||||||
|
m4_if([$1], b4_last_symbol, [], [[,]])),
|
||||||
|
[b4_symbol_tag_comment([$1])])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_declare_symbol_enum
|
||||||
|
# ----------------------
|
||||||
|
# The definition of the symbol internal numbers as an enum.
|
||||||
|
# Defining YYEMPTY here is important: it forces the compiler
|
||||||
|
# to use a signed type, which matters for yytoken.
|
||||||
|
m4_define([b4_declare_symbol_enum],
|
||||||
|
[[/* Symbol kind. */
|
||||||
|
enum yysymbol_kind_t
|
||||||
|
{
|
||||||
|
]b4_symbol_kind([-2])[ = -2,
|
||||||
|
]b4_symbol_foreach([b4_symbol_enum])dnl
|
||||||
|
[};
|
||||||
|
typedef enum yysymbol_kind_t yysymbol_kind_t;
|
||||||
|
]])])
|
||||||
|
|
||||||
|
|
||||||
## ----------------- ##
|
## ----------------- ##
|
||||||
## Semantic Values. ##
|
## Semantic Values. ##
|
||||||
## ----------------- ##
|
## ----------------- ##
|
||||||
@@ -493,15 +561,6 @@ m4_define([b4_symbol_value],
|
|||||||
## ---------------------- ##
|
## ---------------------- ##
|
||||||
|
|
||||||
|
|
||||||
# b4_function_define(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
|
|
||||||
# -----------------------------------------------------------
|
|
||||||
# Declare the function NAME in C.
|
|
||||||
m4_define([b4_function_define],
|
|
||||||
[$2
|
|
||||||
$1 (b4_formals(m4_shift2($@)))[]dnl
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
# b4_formals([DECL1, NAME1], ...)
|
# b4_formals([DECL1, NAME1], ...)
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
# The formal arguments of a C function definition.
|
# The formal arguments of a C function definition.
|
||||||
@@ -515,21 +574,6 @@ m4_define([b4_formal],
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
## ----------------------- ##
|
|
||||||
## Declaring C functions. ##
|
|
||||||
## ----------------------- ##
|
|
||||||
|
|
||||||
|
|
||||||
# b4_function_declare(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
|
|
||||||
# ------------------------------------------------------------
|
|
||||||
# Declare the function NAME.
|
|
||||||
m4_define([b4_function_declare],
|
|
||||||
[$2 $1 (b4_formals(m4_shift2($@)));[]dnl
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## --------------------- ##
|
## --------------------- ##
|
||||||
## Calling C functions. ##
|
## Calling C functions. ##
|
||||||
## --------------------- ##
|
## --------------------- ##
|
||||||
@@ -593,18 +637,15 @@ m4_define_default([b4_yydestruct_define],
|
|||||||
| Release the memory associated to this symbol. |
|
| Release the memory associated to this symbol. |
|
||||||
`-----------------------------------------------*/
|
`-----------------------------------------------*/
|
||||||
|
|
||||||
]b4_function_define([yydestruct],
|
static void
|
||||||
[static void],
|
yydestruct (const char *yymsg,
|
||||||
[[const char *yymsg], [yymsg]],
|
yysymbol_kind_t yykind, YYSTYPE *yyvaluep]b4_locations_if(dnl
|
||||||
[[int yytype], [yytype]],
|
[[, YYLTYPE *yylocationp]])[]b4_user_formals[)
|
||||||
[[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
|
|
||||||
b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
|
|
||||||
m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
|
||||||
{
|
{
|
||||||
]b4_parse_param_use([yyvaluep], [yylocationp])dnl
|
]b4_parse_param_use([yyvaluep], [yylocationp])dnl
|
||||||
[ if (!yymsg)
|
[ if (!yymsg)
|
||||||
yymsg = "Deleting";
|
yymsg = "Deleting";
|
||||||
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
|
YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
|
||||||
|
|
||||||
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
|
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
|
||||||
]b4_symbol_actions([destructor])[
|
]b4_symbol_actions([destructor])[
|
||||||
@@ -622,13 +663,10 @@ m4_define_default([b4_yy_symbol_print_define],
|
|||||||
| Print this symbol's value on YYO. |
|
| Print this symbol's value on YYO. |
|
||||||
`-----------------------------------*/
|
`-----------------------------------*/
|
||||||
|
|
||||||
]b4_function_define([yy_symbol_value_print],
|
static void
|
||||||
[static void],
|
yy_symbol_value_print (FILE *yyo,
|
||||||
[[FILE *yyo], [yyo]],
|
yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep]b4_locations_if(dnl
|
||||||
[[int yytype], [yytype]],
|
[[, YYLTYPE const * const yylocationp]])[]b4_user_formals[)
|
||||||
[[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
|
|
||||||
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
|
|
||||||
m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
|
||||||
{
|
{
|
||||||
FILE *yyoutput = yyo;
|
FILE *yyoutput = yyo;
|
||||||
]b4_parse_param_use([yyoutput], [yylocationp])dnl
|
]b4_parse_param_use([yyoutput], [yylocationp])dnl
|
||||||
@@ -637,8 +675,8 @@ m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
|||||||
dnl glr.c does not feature yytoknum.
|
dnl glr.c does not feature yytoknum.
|
||||||
m4_if(b4_skeleton, ["yacc.c"],
|
m4_if(b4_skeleton, ["yacc.c"],
|
||||||
[[# ifdef YYPRINT
|
[[# ifdef YYPRINT
|
||||||
if (yytype < YYNTOKENS)
|
if (yykind < YYNTOKENS)
|
||||||
YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
|
YYPRINT (yyo, yytoknum[yykind], *yyvaluep);
|
||||||
# endif
|
# endif
|
||||||
]])dnl
|
]])dnl
|
||||||
b4_percent_code_get([[pre-printer]])dnl
|
b4_percent_code_get([[pre-printer]])dnl
|
||||||
@@ -653,21 +691,18 @@ b4_percent_code_get([[post-printer]])dnl
|
|||||||
| Print this symbol on YYO. |
|
| Print this symbol on YYO. |
|
||||||
`---------------------------*/
|
`---------------------------*/
|
||||||
|
|
||||||
]b4_function_define([yy_symbol_print],
|
static void
|
||||||
[static void],
|
yy_symbol_print (FILE *yyo,
|
||||||
[[FILE *yyo], [yyo]],
|
yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep]b4_locations_if(dnl
|
||||||
[[int yytype], [yytype]],
|
[[, YYLTYPE const * const yylocationp]])[]b4_user_formals[)
|
||||||
[[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
|
|
||||||
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
|
|
||||||
m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
|
||||||
{
|
{
|
||||||
YYFPRINTF (yyo, "%s %s (",
|
YYFPRINTF (yyo, "%s %s (",
|
||||||
yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
|
yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
|
||||||
|
|
||||||
]b4_locations_if([ YY_LOCATION_PRINT (yyo, *yylocationp);
|
]b4_locations_if([ YY_LOCATION_PRINT (yyo, *yylocationp);
|
||||||
YYFPRINTF (yyo, ": ");
|
YYFPRINTF (yyo, ": ");
|
||||||
])dnl
|
])dnl
|
||||||
[ yy_symbol_value_print (yyo, yytype, yyvaluep]dnl
|
[ yy_symbol_value_print (yyo, yykind, yyvaluep]dnl
|
||||||
b4_locations_if([, yylocationp])[]b4_user_args[);
|
b4_locations_if([, yylocationp])[]b4_user_args[);
|
||||||
YYFPRINTF (yyo, ")");
|
YYFPRINTF (yyo, ")");
|
||||||
}]dnl
|
}]dnl
|
||||||
@@ -693,11 +728,11 @@ m4_define([b4_symbol_type_register],
|
|||||||
[m4_define([b4_symbol($1, type_tag)],
|
[m4_define([b4_symbol($1, type_tag)],
|
||||||
[b4_symbol_if([$1], [has_id],
|
[b4_symbol_if([$1], [has_id],
|
||||||
[b4_symbol([$1], [id])],
|
[b4_symbol([$1], [id])],
|
||||||
[yytype_[]b4_symbol([$1], [number])])])dnl
|
[yykind_[]b4_symbol([$1], [number])])])dnl
|
||||||
m4_append([b4_union_members],
|
m4_append([b4_union_members],
|
||||||
m4_expand([
|
m4_expand([m4_format([ %-40s %s],
|
||||||
b4_symbol_tag_comment([$1])dnl
|
m4_expand([b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);]),
|
||||||
b4_symbol([$1], [type]) b4_symbol([$1], [type_tag]);]))
|
[b4_symbol_tag_comment([$1])])]))
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
@@ -936,10 +971,8 @@ m4_define([b4_yy_location_print_define],
|
|||||||
/* Print *YYLOCP on YYO. Private, do not rely on its existence. */
|
/* Print *YYLOCP on YYO. Private, do not rely on its existence. */
|
||||||
|
|
||||||
YY_ATTRIBUTE_UNUSED
|
YY_ATTRIBUTE_UNUSED
|
||||||
]b4_function_define([yy_location_print_],
|
static int
|
||||||
[static int],
|
yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp)
|
||||||
[[FILE *yyo], [yyo]],
|
|
||||||
[[YYLTYPE const * const yylocp], [yylocp]])[
|
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
|
int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
|
||||||
|
|||||||
+45
-11
@@ -148,9 +148,9 @@ private static immutable b4_int_type_for([$2])[[]] yy$1_ =
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
## ------------------------- ##
|
## ------------- ##
|
||||||
## Assigning token numbers. ##
|
## Token kinds. ##
|
||||||
## ------------------------- ##
|
## ------------- ##
|
||||||
|
|
||||||
# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
|
# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
|
||||||
# ---------------------------------------
|
# ---------------------------------------
|
||||||
@@ -159,19 +159,53 @@ m4_define([b4_token_enum],
|
|||||||
[b4_token_format([ %s = %s,
|
[b4_token_format([ %s = %s,
|
||||||
], [$1])])
|
], [$1])])
|
||||||
|
|
||||||
# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
|
# b4_token_enums
|
||||||
# -----------------------------------------------------
|
# --------------
|
||||||
# Output the definition of the tokens as enums.
|
# Output the definition of the tokens as enums.
|
||||||
m4_define([b4_token_enums],
|
m4_define([b4_token_enums],
|
||||||
[/* Tokens. */
|
[/* Token kinds. */
|
||||||
public enum YYTokenType {
|
public enum TokenKind {
|
||||||
|
]b4_symbol_kind([-2])[ = -2,
|
||||||
/** Token returned by the scanner to signal the end of its input. */
|
b4_symbol_foreach([b4_token_enum])dnl
|
||||||
EOF = 0,
|
|
||||||
b4_symbol_foreach([b4_token_enum])
|
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## -------------- ##
|
||||||
|
## Symbol kinds. ##
|
||||||
|
## -------------- ##
|
||||||
|
|
||||||
|
b4_percent_define_default([[api.symbol.prefix]], [[S_]])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_symbol_enum(SYMBOL-NUM)
|
||||||
|
# --------------------------
|
||||||
|
# Output the definition of this symbol as an enum.
|
||||||
|
m4_define([b4_symbol_enum],
|
||||||
|
[m4_format([ %-30s %s],
|
||||||
|
m4_format([[%s = %s,]],
|
||||||
|
b4_symbol([$1], [kind]),
|
||||||
|
[$1]),
|
||||||
|
[b4_symbol_tag_comment([$1])])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_declare_symbol_enum
|
||||||
|
# ----------------------
|
||||||
|
# The definition of the symbol internal numbers as an enum.
|
||||||
|
# Defining YYEMPTY here is important: it forces the compiler
|
||||||
|
# to use a signed type, which matters for yytoken.
|
||||||
|
m4_define([b4_declare_symbol_enum],
|
||||||
|
[[ /* Symbol kinds. */
|
||||||
|
public enum SymbolKind
|
||||||
|
{
|
||||||
|
]b4_symbol_kind([-2])[ = -2, /* No symbol. */
|
||||||
|
]b4_symbol_foreach([b4_symbol_enum])dnl
|
||||||
|
[ };
|
||||||
|
]])])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# b4-case(ID, CODE)
|
# b4-case(ID, CODE)
|
||||||
# -----------------
|
# -----------------
|
||||||
m4_define([b4_case], [ case $1:
|
m4_define([b4_case], [ case $1:
|
||||||
|
|||||||
+387
-302
File diff suppressed because it is too large
Load Diff
+52
-54
@@ -66,30 +66,29 @@ m4_defn([b4_parse_param]))],
|
|||||||
[[b4_namespace_ref::b4_parser_class[& yyparser], [[yyparser]]]])
|
[[b4_namespace_ref::b4_parser_class[& yyparser], [[yyparser]]]])
|
||||||
])
|
])
|
||||||
|
|
||||||
|
# b4_declare_symbol_enum
|
||||||
|
# ----------------------
|
||||||
|
m4_append([b4_declare_symbol_enum],
|
||||||
|
[[typedef symbol_kind_type yysymbol_kind_t;
|
||||||
|
]])
|
||||||
|
|
||||||
|
|
||||||
# b4_yy_symbol_print_define
|
# b4_yy_symbol_print_define
|
||||||
# -------------------------
|
# -------------------------
|
||||||
# Bypass the default implementation to generate the "yy_symbol_print"
|
# Bypass the default implementation to generate the "yy_symbol_print"
|
||||||
# and "yy_symbol_value_print" functions.
|
# and "yy_symbol_value_print" functions.
|
||||||
m4_define([b4_yy_symbol_print_define],
|
m4_define([b4_yy_symbol_print_define],
|
||||||
[[
|
[[/*--------------------.
|
||||||
/*--------------------.
|
|
||||||
| Print this symbol. |
|
| Print this symbol. |
|
||||||
`--------------------*/
|
`--------------------*/
|
||||||
|
|
||||||
]b4_function_define([yy_symbol_print],
|
static void
|
||||||
[static void],
|
yy_symbol_print (FILE *, ]b4_namespace_ref::b4_parser_class[::symbol_kind_type yytoken,
|
||||||
[[FILE *], []],
|
const ]b4_namespace_ref::b4_parser_class[::semantic_type *yyvaluep]b4_locations_if([[,
|
||||||
[[int yytype], [yytype]],
|
const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp]])[]b4_user_formals[)
|
||||||
[[const ]b4_namespace_ref::b4_parser_class[::semantic_type *yyvaluep],
|
|
||||||
[yyvaluep]][]dnl
|
|
||||||
b4_locations_if([,
|
|
||||||
[[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp],
|
|
||||||
[yylocationp]]]),
|
|
||||||
b4_parse_param)[
|
|
||||||
{
|
{
|
||||||
]b4_parse_param_use[]dnl
|
]b4_parse_param_use[]dnl
|
||||||
[ yyparser.yy_symbol_print_ (yytype, yyvaluep]b4_locations_if([, yylocationp])[);
|
[ yyparser.yy_symbol_print_ (yytoken, yyvaluep]b4_locations_if([, yylocationp])[);
|
||||||
}
|
}
|
||||||
]])[
|
]])[
|
||||||
|
|
||||||
@@ -101,45 +100,30 @@ m4_defn([b4_initial_action])]))])[
|
|||||||
# Hijack the post prologue to declare yyerror.
|
# Hijack the post prologue to declare yyerror.
|
||||||
]m4_append([b4_post_prologue],
|
]m4_append([b4_post_prologue],
|
||||||
[b4_syncline([@oline@], [@ofile@])dnl
|
[b4_syncline([@oline@], [@ofile@])dnl
|
||||||
b4_function_declare([yyerror],
|
[static void
|
||||||
[static void],b4_locations_if([
|
yyerror (]b4_locations_if([[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp,
|
||||||
[[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp],
|
]])[]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param),
|
||||||
[yylocationp]],])
|
])[const char* msg);]])[
|
||||||
b4_parse_param,
|
|
||||||
[[const char* msg], [msg]])])[
|
|
||||||
|
|
||||||
|
]b4_percent_define_flag_if([[global_tokens_and_yystype]], [],
|
||||||
#undef yynerrs
|
[m4_define([b4_pre_epilogue],
|
||||||
#undef yychar
|
[[/* The user is using the C++ token kind, not the C one. */
|
||||||
#undef yylval]b4_locations_if([
|
#undef ]b4_symbol(0, [id])
|
||||||
#undef yylloc])
|
])])[
|
||||||
|
|
||||||
m4_if(b4_prefix, [yy], [],
|
|
||||||
[[/* Substitute the variable and function names. */
|
|
||||||
#define yyparse ]b4_prefix[parse
|
|
||||||
#define yylex ]b4_prefix[lex
|
|
||||||
#define yyerror ]b4_prefix[error
|
|
||||||
#define yydebug ]b4_prefix[debug]]b4_pure_if([], [[
|
|
||||||
#define yylval ]b4_prefix[lval
|
|
||||||
#define yychar ]b4_prefix[char
|
|
||||||
#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
|
|
||||||
#define yylloc ]b4_prefix[lloc]])]))
|
|
||||||
|
|
||||||
# Hijack the epilogue to define implementations (yyerror, parser member
|
# Hijack the epilogue to define implementations (yyerror, parser member
|
||||||
# functions etc.).
|
# functions etc.).
|
||||||
m4_append([b4_epilogue],
|
]m4_append([b4_epilogue],
|
||||||
[b4_syncline([@oline@], [@ofile@])dnl
|
[b4_syncline([@oline@], [@ofile@])dnl
|
||||||
[
|
[
|
||||||
/*------------------.
|
/*------------------.
|
||||||
| Report an error. |
|
| Report an error. |
|
||||||
`------------------*/
|
`------------------*/
|
||||||
|
|
||||||
]b4_function_define([yyerror],
|
static void
|
||||||
[static void],b4_locations_if([
|
yyerror (]b4_locations_if([[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp,
|
||||||
[[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp],
|
]])[]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param),
|
||||||
[yylocationp]],])
|
])[const char* msg)
|
||||||
b4_parse_param,
|
|
||||||
[[const char* msg], [msg]])[
|
|
||||||
{
|
{
|
||||||
]b4_parse_param_use[]dnl
|
]b4_parse_param_use[]dnl
|
||||||
[ yyparser.error (]b4_locations_if([[*yylocationp, ]])[msg);
|
[ yyparser.error (]b4_locations_if([[*yylocationp, ]])[msg);
|
||||||
@@ -181,7 +165,7 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
|
|||||||
`--------------------*/
|
`--------------------*/
|
||||||
|
|
||||||
void
|
void
|
||||||
]b4_parser_class[::yy_symbol_value_print_ (int yytype,
|
]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind,
|
||||||
const semantic_type* yyvaluep]b4_locations_if([[,
|
const semantic_type* yyvaluep]b4_locations_if([[,
|
||||||
const location_type* yylocationp]])[)
|
const location_type* yylocationp]])[)
|
||||||
{]b4_locations_if([[
|
{]b4_locations_if([[
|
||||||
@@ -195,14 +179,14 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
]b4_parser_class[::yy_symbol_print_ (int yytype,
|
]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind,
|
||||||
const semantic_type* yyvaluep]b4_locations_if([[,
|
const semantic_type* yyvaluep]b4_locations_if([[,
|
||||||
const location_type* yylocationp]])[)
|
const location_type* yylocationp]])[)
|
||||||
{
|
{
|
||||||
*yycdebug_ << (yytype < YYNTOKENS ? "token" : "nterm")
|
*yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm")
|
||||||
<< ' ' << yytname[yytype] << " ("]b4_locations_if([[
|
<< ' ' << yytname[yykind] << " ("]b4_locations_if([[
|
||||||
<< *yylocationp << ": "]])[;
|
<< *yylocationp << ": "]])[;
|
||||||
yy_symbol_value_print_ (yytype, yyvaluep]b4_locations_if([[, yylocationp]])[);
|
yy_symbol_value_print_ (yykind, yyvaluep]b4_locations_if([[, yylocationp]])[);
|
||||||
*yycdebug_ << ')';
|
*yycdebug_ << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,17 +312,17 @@ b4_percent_code_get([[requires]])[
|
|||||||
# if ]b4_api_PREFIX[DEBUG
|
# if ]b4_api_PREFIX[DEBUG
|
||||||
public:
|
public:
|
||||||
/// \brief Report a symbol value on the debug stream.
|
/// \brief Report a symbol value on the debug stream.
|
||||||
/// \param yytype The token type.
|
/// \param yykind The symbol kind.
|
||||||
/// \param yyvaluep Its semantic value.]b4_locations_if([[
|
/// \param yyvaluep Its semantic value.]b4_locations_if([[
|
||||||
/// \param yylocationp Its location.]])[
|
/// \param yylocationp Its location.]])[
|
||||||
virtual void yy_symbol_value_print_ (int yytype,
|
virtual void yy_symbol_value_print_ (symbol_kind_type yykind,
|
||||||
const semantic_type* yyvaluep]b4_locations_if([[,
|
const semantic_type* yyvaluep]b4_locations_if([[,
|
||||||
const location_type* yylocationp]])[);
|
const location_type* yylocationp]])[);
|
||||||
/// \brief Report a symbol on the debug stream.
|
/// \brief Report a symbol on the debug stream.
|
||||||
/// \param yytype The token type.
|
/// \param yykind The symbol kind.
|
||||||
/// \param yyvaluep Its semantic value.]b4_locations_if([[
|
/// \param yyvaluep Its semantic value.]b4_locations_if([[
|
||||||
/// \param yylocationp Its location.]])[
|
/// \param yylocationp Its location.]])[
|
||||||
virtual void yy_symbol_print_ (int yytype,
|
virtual void yy_symbol_print_ (symbol_kind_type yykind,
|
||||||
const semantic_type* yyvaluep]b4_locations_if([[,
|
const semantic_type* yyvaluep]b4_locations_if([[,
|
||||||
const location_type* yylocationp]])[);
|
const location_type* yylocationp]])[);
|
||||||
private:
|
private:
|
||||||
@@ -351,8 +335,16 @@ b4_percent_code_get([[requires]])[
|
|||||||
|
|
||||||
]dnl Redirections for glr.c.
|
]dnl Redirections for glr.c.
|
||||||
b4_percent_define_flag_if([[global_tokens_and_yystype]],
|
b4_percent_define_flag_if([[global_tokens_and_yystype]],
|
||||||
[b4_token_defines])
|
[b4_token_defines
|
||||||
[
|
])[
|
||||||
|
]b4_namespace_close[
|
||||||
|
|
||||||
|
]dnl Map the name used in c.m4 to the one used in c++.m4.
|
||||||
|
[#undef ]b4_symbol(-2, [id])[
|
||||||
|
#define ]b4_symbol(-2, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(-2, [id])[
|
||||||
|
#undef ]b4_symbol(0, [id])[
|
||||||
|
#define ]b4_symbol(0, [id])[ ]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(0, [id])[
|
||||||
|
|
||||||
#ifndef ]b4_api_PREFIX[STYPE
|
#ifndef ]b4_api_PREFIX[STYPE
|
||||||
# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::semantic_type
|
# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::semantic_type
|
||||||
#endif
|
#endif
|
||||||
@@ -360,7 +352,13 @@ b4_percent_define_flag_if([[global_tokens_and_yystype]],
|
|||||||
# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class[::location_type
|
# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class[::location_type
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
]b4_namespace_close[
|
]m4_define([b4_declare_symbol_enum],
|
||||||
|
[[typedef ]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
|
||||||
|
#define ]b4_symbol_prefix[YYEMPTY ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYEMPTY
|
||||||
|
#define ]b4_symbol_prefix[YYERROR ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYERROR
|
||||||
|
#define ]b4_symbol_prefix[YYEOF ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYEOF
|
||||||
|
#define ]b4_symbol_prefix[YYUNDEF ]b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol_prefix[YYUNDEF
|
||||||
|
]])[
|
||||||
]b4_percent_code_get([[provides]])[
|
]b4_percent_code_get([[provides]])[
|
||||||
]m4_popdef([b4_parse_param])dnl
|
]m4_popdef([b4_parse_param])dnl
|
||||||
])
|
])
|
||||||
|
|||||||
+130
-6
@@ -106,10 +106,13 @@ m4_define([b4_null], [null])
|
|||||||
|
|
||||||
# b4_typed_parser_table_define(TYPE, NAME, DATA, COMMENT)
|
# b4_typed_parser_table_define(TYPE, NAME, DATA, COMMENT)
|
||||||
# -------------------------------------------------------
|
# -------------------------------------------------------
|
||||||
|
# We use intermediate functions (e.g., yypact_init) to work around the
|
||||||
|
# 64KB limit for JVM methods. See
|
||||||
|
# https://lists.gnu.org/r/help-bison/2008-11/msg00004.html.
|
||||||
m4_define([b4_typed_parser_table_define],
|
m4_define([b4_typed_parser_table_define],
|
||||||
[m4_ifval([$4], [b4_comment([$4])
|
[m4_ifval([$4], [b4_comment([$4])
|
||||||
])dnl
|
])dnl
|
||||||
[private static final ]$1[ yy$2_[] = yy$2_init();
|
[private static final ]$1[[] yy$2_ = yy$2_init();
|
||||||
private static final ]$1[[] yy$2_init()
|
private static final ]$1[[] yy$2_init()
|
||||||
{
|
{
|
||||||
return new ]$1[[]
|
return new ]$1[[]
|
||||||
@@ -125,9 +128,10 @@ m4_define([b4_integral_parser_table_define],
|
|||||||
[b4_typed_parser_table_define([b4_int_type_for([$2])], [$1], [$2], [$3])])
|
[b4_typed_parser_table_define([b4_int_type_for([$2])], [$1], [$2], [$3])])
|
||||||
|
|
||||||
|
|
||||||
## ------------------------- ##
|
## ------------- ##
|
||||||
## Assigning token numbers. ##
|
## Token kinds. ##
|
||||||
## ------------------------- ##
|
## ------------- ##
|
||||||
|
|
||||||
|
|
||||||
# b4_token_enum(TOKEN-NUM)
|
# b4_token_enum(TOKEN-NUM)
|
||||||
# ------------------------
|
# ------------------------
|
||||||
@@ -141,10 +145,112 @@ m4_define([b4_token_enum],
|
|||||||
# --------------
|
# --------------
|
||||||
# Output the definition of the tokens (if there are) as enums.
|
# Output the definition of the tokens (if there are) as enums.
|
||||||
m4_define([b4_token_enums],
|
m4_define([b4_token_enums],
|
||||||
[b4_any_token_visible_if([/* Tokens. */
|
[b4_any_token_visible_if([ /* Token kinds. */
|
||||||
b4_symbol_foreach([b4_token_enum])])])
|
b4_symbol_foreach([b4_token_enum])])])
|
||||||
|
|
||||||
# b4-case(ID, CODE)
|
|
||||||
|
|
||||||
|
## -------------- ##
|
||||||
|
## Symbol kinds. ##
|
||||||
|
## -------------- ##
|
||||||
|
|
||||||
|
# b4_symbol_enum(SYMBOL-NUM)
|
||||||
|
# --------------------------
|
||||||
|
# Output the definition of this symbol as an enum.
|
||||||
|
m4_define([b4_symbol_enum],
|
||||||
|
[m4_format([ %-30s %s],
|
||||||
|
m4_format([[%s(%s)%s]],
|
||||||
|
b4_symbol([$1], [kind]),
|
||||||
|
[$1],
|
||||||
|
m4_if([$1], b4_last_symbol, [[;]], [[,]])),
|
||||||
|
[b4_symbol_tag_comment([$1])])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_declare_symbol_enum
|
||||||
|
# ----------------------
|
||||||
|
# The definition of the symbol internal numbers as an enum.
|
||||||
|
m4_define([b4_declare_symbol_enum],
|
||||||
|
[[ public enum SymbolKind
|
||||||
|
{
|
||||||
|
]b4_symbol_foreach([b4_symbol_enum])[
|
||||||
|
|
||||||
|
private final int yycode_;
|
||||||
|
|
||||||
|
SymbolKind (int n) {
|
||||||
|
this.yycode_ = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final SymbolKind[] values_ = {
|
||||||
|
]m4_map_args_sep([b4_symbol_kind(], [)], [,
|
||||||
|
], b4_symbol_numbers)[
|
||||||
|
};
|
||||||
|
|
||||||
|
static final SymbolKind get(int code) {
|
||||||
|
return values_[code];
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int getCode() {
|
||||||
|
return this.yycode_;
|
||||||
|
}
|
||||||
|
|
||||||
|
]b4_parse_error_bmatch(
|
||||||
|
[simple\|verbose],
|
||||||
|
[[ /* Return YYSTR after stripping away unnecessary quotes and
|
||||||
|
backslashes, so that it's suitable for yyerror. The heuristic is
|
||||||
|
that double-quoting is unnecessary unless the string contains an
|
||||||
|
apostrophe, a comma, or backslash (other than backslash-backslash).
|
||||||
|
YYSTR is taken from yytname. */
|
||||||
|
private static String yytnamerr_(String yystr)
|
||||||
|
{
|
||||||
|
if (yystr.charAt (0) == '"')
|
||||||
|
{
|
||||||
|
StringBuffer yyr = new StringBuffer();
|
||||||
|
strip_quotes: for (int i = 1; i < yystr.length(); i++)
|
||||||
|
switch (yystr.charAt(i))
|
||||||
|
{
|
||||||
|
case '\'':
|
||||||
|
case ',':
|
||||||
|
break strip_quotes;
|
||||||
|
|
||||||
|
case '\\':
|
||||||
|
if (yystr.charAt(++i) != '\\')
|
||||||
|
break strip_quotes;
|
||||||
|
/* Fall through. */
|
||||||
|
default:
|
||||||
|
yyr.append(yystr.charAt(i));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '"':
|
||||||
|
return yyr.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return yystr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
|
||||||
|
First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */
|
||||||
|
]b4_typed_parser_table_define([String], [tname], [b4_tname])[
|
||||||
|
|
||||||
|
/* The user-facing name of this symbol. */
|
||||||
|
public final String getName() {
|
||||||
|
return yytnamerr_(yytname_[yycode_]);
|
||||||
|
}
|
||||||
|
]],
|
||||||
|
[custom\|detailed],
|
||||||
|
[[ /* YYNAMES_[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
|
||||||
|
First, the terminals, then, starting at \a YYNTOKENS_, nonterminals. */
|
||||||
|
]b4_typed_parser_table_define([String], [names], [b4_symbol_names])[
|
||||||
|
|
||||||
|
/* The user-facing name of this symbol. */
|
||||||
|
public final String getName() {
|
||||||
|
return yynames_[yycode_];
|
||||||
|
}]])[
|
||||||
|
};
|
||||||
|
]])])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# b4_case(ID, CODE)
|
||||||
# -----------------
|
# -----------------
|
||||||
# We need to fool Java's stupid unreachable code detection.
|
# We need to fool Java's stupid unreachable code detection.
|
||||||
m4_define([b4_case],
|
m4_define([b4_case],
|
||||||
@@ -154,6 +260,7 @@ m4_define([b4_case],
|
|||||||
break;
|
break;
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
# b4_predicate_case(LABEL, CONDITIONS)
|
# b4_predicate_case(LABEL, CONDITIONS)
|
||||||
# ------------------------------------
|
# ------------------------------------
|
||||||
m4_define([b4_predicate_case],
|
m4_define([b4_predicate_case],
|
||||||
@@ -185,6 +292,7 @@ b4_percent_define_check_kind([[throws]], [code], [deprecated])
|
|||||||
|
|
||||||
m4_define([b4_yystype], [b4_percent_define_get([[api.value.type]])])
|
m4_define([b4_yystype], [b4_percent_define_get([[api.value.type]])])
|
||||||
b4_percent_define_default([[api.value.type]], [[Object]])
|
b4_percent_define_default([[api.value.type]], [[Object]])
|
||||||
|
b4_percent_define_default([[api.symbol.prefix]], [[S_]])
|
||||||
|
|
||||||
# b4_api_prefix, b4_api_PREFIX
|
# b4_api_prefix, b4_api_PREFIX
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
@@ -224,6 +332,22 @@ m4_define([b4_position_type], [b4_percent_define_get([[api.position.type]])])
|
|||||||
## ----------------- ##
|
## ----------------- ##
|
||||||
|
|
||||||
|
|
||||||
|
# b4_symbol_translate(STRING)
|
||||||
|
# ---------------------------
|
||||||
|
# Used by "bison" in the array of symbol names to mark those that
|
||||||
|
# require translation.
|
||||||
|
m4_define([b4_symbol_translate],
|
||||||
|
[[i18n($1)]])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_trans(STRING)
|
||||||
|
# ----------------
|
||||||
|
# Translate a string if i18n is enabled. Avoid collision with b4_translate.
|
||||||
|
m4_define([b4_trans],
|
||||||
|
[m4_if(b4_has_translations, 0, [$1], [i18n($1)])])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG])
|
# b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG])
|
||||||
# ----------------------------------------------
|
# ----------------------------------------------
|
||||||
# See README.
|
# See README.
|
||||||
|
|||||||
+247
-143
@@ -30,6 +30,15 @@ m4_define([b4_lac_flag],
|
|||||||
[none], [[0]], [[1]])])
|
[none], [[0]], [[1]])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_tname_if(TNAME-NEEDED, TNAME-NOT-NEEDED)
|
||||||
|
# -------------------------------------------
|
||||||
|
m4_define([b4_tname_if],
|
||||||
|
[m4_case(b4_percent_define_get([[parse.error]]),
|
||||||
|
[verbose], [$1],
|
||||||
|
[b4_token_table_if([$1],
|
||||||
|
[$2])])])
|
||||||
|
|
||||||
|
|
||||||
# b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT)
|
# b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT)
|
||||||
# --------------------------------------------------------------
|
# --------------------------------------------------------------
|
||||||
# Declare "parser::yy<TABLE-NAME>_" whose contents is CONTENT.
|
# Declare "parser::yy<TABLE-NAME>_" whose contents is CONTENT.
|
||||||
@@ -226,7 +235,25 @@ m4_define([b4_shared_declarations],
|
|||||||
void error (const syntax_error& err);
|
void error (const syntax_error& err);
|
||||||
|
|
||||||
]b4_token_constructor_define[
|
]b4_token_constructor_define[
|
||||||
|
]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
|
||||||
|
class context
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
context (const ]b4_parser_class[& yyparser, const symbol_type& yyla);
|
||||||
|
const symbol_type& lookahead () const { return yyla_; }
|
||||||
|
symbol_kind_type token () const { return yyla_.kind (); }]b4_locations_if([[
|
||||||
|
const location_type& location () const { return yyla_.location; }
|
||||||
|
]])[
|
||||||
|
/// Put in YYARG at most YYARGN of the expected tokens, and return the
|
||||||
|
/// number of tokens stored in YYARG. If YYARG is null, return the
|
||||||
|
/// number of expected tokens (guaranteed to be less than YYNTOKENS).
|
||||||
|
int expected_tokens (symbol_kind_type yyarg[], int yyargn) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const ]b4_parser_class[& yyparser_;
|
||||||
|
const symbol_type& yyla_;
|
||||||
|
};
|
||||||
|
]])[
|
||||||
private:
|
private:
|
||||||
/// This class is not copyable.
|
/// This class is not copyable.
|
||||||
]b4_parser_class[ (const ]b4_parser_class[&);
|
]b4_parser_class[ (const ]b4_parser_class[&);
|
||||||
@@ -234,10 +261,10 @@ m4_define([b4_shared_declarations],
|
|||||||
|
|
||||||
/// Check the lookahead yytoken.
|
/// Check the lookahead yytoken.
|
||||||
/// \returns true iff the token will be eventually shifted.
|
/// \returns true iff the token will be eventually shifted.
|
||||||
bool yy_lac_check_ (int yytoken) const;
|
bool yy_lac_check_ (symbol_kind_type yytoken) const;
|
||||||
/// Establish the initial context if no initial context currently exists.
|
/// Establish the initial context if no initial context currently exists.
|
||||||
/// \returns true iff the token will be eventually shifted.
|
/// \returns true iff the token will be eventually shifted.
|
||||||
bool yy_lac_establish_ (int yytoken);
|
bool yy_lac_establish_ (symbol_kind_type yytoken);
|
||||||
/// Discard any previous initial lookahead context because of event.
|
/// Discard any previous initial lookahead context because of event.
|
||||||
/// \param event the event which caused the lookahead to be discarded.
|
/// \param event the event which caused the lookahead to be discarded.
|
||||||
/// Only used for debbuging output.
|
/// Only used for debbuging output.
|
||||||
@@ -245,13 +272,19 @@ m4_define([b4_shared_declarations],
|
|||||||
|
|
||||||
/// Stored state numbers (used for stacks).
|
/// Stored state numbers (used for stacks).
|
||||||
typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ state_type;
|
typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ state_type;
|
||||||
|
]b4_parse_error_bmatch(
|
||||||
|
[custom], [[
|
||||||
|
/// Report a syntax error
|
||||||
|
/// \param yyctx the context in which the error occurred.
|
||||||
|
void report_syntax_error (const context& yyctx) const;]],
|
||||||
|
[detailed\|verbose], [[
|
||||||
|
/// The arguments of the error message.
|
||||||
|
int yy_syntax_error_arguments_ (const context& yyctx,
|
||||||
|
symbol_kind_type yyarg[], int yyargn) const;
|
||||||
|
|
||||||
/// Generate an error message.
|
/// Generate an error message.
|
||||||
/// \param yystate the state where the error occurred.
|
/// \param yyctx the context in which the error occurred.
|
||||||
/// \param yyla the lookahead token.
|
virtual std::string yysyntax_error_ (const context& yyctx) const;]])[
|
||||||
virtual std::string yysyntax_error_ (state_type yystate,
|
|
||||||
const symbol_type& yyla) const;
|
|
||||||
|
|
||||||
/// Compute post-reduction state.
|
/// Compute post-reduction state.
|
||||||
/// \param yystate the current state
|
/// \param yystate the current state
|
||||||
/// \param yysym the nonterminal to push on the stack
|
/// \param yysym the nonterminal to push on the stack
|
||||||
@@ -268,21 +301,33 @@ m4_define([b4_shared_declarations],
|
|||||||
static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
|
static const ]b4_int_type(b4_pact_ninf, b4_pact_ninf)[ yypact_ninf_;
|
||||||
static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
|
static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
|
||||||
|
|
||||||
/// Convert a scanner token number \a t to a symbol number.
|
/// Convert a scanner token kind \a t to a symbol kind.
|
||||||
/// In theory \a t should be a token_type, but character literals
|
/// In theory \a t should be a token_kind_type, but character literals
|
||||||
/// are valid, yet not members of the token_type enum.
|
/// are valid, yet not members of the token_type enum.
|
||||||
static token_number_type yytranslate_ (int t);
|
static symbol_kind_type yytranslate_ (int t);
|
||||||
|
]b4_parse_error_bmatch([custom\|detailed], [[
|
||||||
|
/// The user-facing name of the symbol whose (internal) number is
|
||||||
|
/// YYSYMBOL. No bounds checking.
|
||||||
|
static const char *symbol_name (symbol_kind_type yysymbol);
|
||||||
|
]])[
|
||||||
|
|
||||||
// Tables.
|
// Tables.
|
||||||
]b4_parser_tables_declare[]b4_error_verbose_if([
|
]b4_parser_tables_declare[
|
||||||
|
]b4_parse_error_case([verbose], [[
|
||||||
/// Convert the symbol name \a n to a form suitable for a diagnostic.
|
/// Convert the symbol name \a n to a form suitable for a diagnostic.
|
||||||
static std::string yytnamerr_ (const char *n);])[
|
static std::string yytnamerr_ (const char *n);
|
||||||
|
|
||||||
]b4_token_table_if([], [[#if ]b4_api_PREFIX[DEBUG]])[
|
|
||||||
/// For a symbol, its name in clear.
|
/// For a symbol, its name in clear.
|
||||||
static const char* const yytname_[];
|
static const char* const yytname_[];
|
||||||
]b4_token_table_if([[#if ]b4_api_PREFIX[DEBUG]])[
|
]],
|
||||||
|
[b4_token_table_if([], [[
|
||||||
|
#if ]b4_api_PREFIX[DEBUG
|
||||||
|
/// For a symbol, its name in clear.
|
||||||
|
static const char* const yytname_[];
|
||||||
|
#endif
|
||||||
|
]])])[
|
||||||
|
|
||||||
|
#if ]b4_api_PREFIX[DEBUG
|
||||||
]b4_integral_parser_table_declare([rline], [b4_rline],
|
]b4_integral_parser_table_declare([rline], [b4_rline],
|
||||||
[[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
|
[[YYRLINE[YYN] -- Source line where rule number YYN was defined.]])[
|
||||||
/// Report on the debug stream that the rule \a r is going to be reduced.
|
/// Report on the debug stream that the rule \a r is going to be reduced.
|
||||||
@@ -295,7 +340,7 @@ m4_define([b4_shared_declarations],
|
|||||||
/// Debug stream.
|
/// Debug stream.
|
||||||
std::ostream* yycdebug_;
|
std::ostream* yycdebug_;
|
||||||
|
|
||||||
/// \brief Display a symbol type, value and location.
|
/// \brief Display a symbol kind, value and location.
|
||||||
/// \param yyo The output stream.
|
/// \param yyo The output stream.
|
||||||
/// \param yysym The symbol.
|
/// \param yysym The symbol.
|
||||||
template <typename Base>
|
template <typename Base>
|
||||||
@@ -316,7 +361,7 @@ m4_define([b4_shared_declarations],
|
|||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
by_state () YY_NOEXCEPT;
|
by_state () YY_NOEXCEPT;
|
||||||
|
|
||||||
/// The symbol type as needed by the constructor.
|
/// The symbol kind as needed by the constructor.
|
||||||
typedef state_type kind_type;
|
typedef state_type kind_type;
|
||||||
|
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
@@ -328,12 +373,12 @@ m4_define([b4_shared_declarations],
|
|||||||
/// Record that this symbol is empty.
|
/// Record that this symbol is empty.
|
||||||
void clear () YY_NOEXCEPT;
|
void clear () YY_NOEXCEPT;
|
||||||
|
|
||||||
/// Steal the symbol type from \a that.
|
/// Steal the symbol kind from \a that.
|
||||||
void move (by_state& that);
|
void move (by_state& that);
|
||||||
|
|
||||||
/// The (internal) type number (corresponding to \a state).
|
/// The symbol kind (corresponding to \a state).
|
||||||
/// \a empty_symbol when empty.
|
/// \a ]b4_symbol(-2, kind)[ when empty.
|
||||||
symbol_number_type type_get () const YY_NOEXCEPT;
|
symbol_kind_type kind () const YY_NOEXCEPT;
|
||||||
|
|
||||||
/// The state number used to denote an empty symbol.
|
/// The state number used to denote an empty symbol.
|
||||||
/// We use the initial state, as it does not have a value.
|
/// We use the initial state, as it does not have a value.
|
||||||
@@ -401,18 +446,12 @@ m4_define([b4_shared_declarations],
|
|||||||
/// Pop \a n symbols from the stack.
|
/// Pop \a n symbols from the stack.
|
||||||
void yypop_ (int n = 1);
|
void yypop_ (int n = 1);
|
||||||
|
|
||||||
/// Some specific tokens.
|
|
||||||
static const token_number_type yy_error_token_ = 1;
|
|
||||||
static const token_number_type yy_undef_token_ = ]b4_undef_token_number[;
|
|
||||||
|
|
||||||
/// Constants.
|
/// Constants.
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
yyeof_ = 0,
|
|
||||||
yylast_ = ]b4_last[, ///< Last index in yytable_.
|
yylast_ = ]b4_last[, ///< Last index in yytable_.
|
||||||
yynnts_ = ]b4_nterms_number[, ///< Number of nonterminal symbols.
|
yynnts_ = ]b4_nterms_number[, ///< Number of nonterminal symbols.
|
||||||
yyfinal_ = ]b4_final_state_number[, ///< Termination state number.
|
yyfinal_ = ]b4_final_state_number[ ///< Termination state number.
|
||||||
yyntokens_ = ]b4_tokens_number[ ///< Number of tokens.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
]b4_parse_param_vars[
|
]b4_parse_param_vars[
|
||||||
@@ -543,7 +582,29 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
#define YYERROR goto yyerrorlab
|
#define YYERROR goto yyerrorlab
|
||||||
#define YYRECOVERING() (!!yyerrstatus_)
|
#define YYRECOVERING() (!!yyerrstatus_)
|
||||||
|
|
||||||
]b4_namespace_open[]b4_error_verbose_if([[
|
]b4_namespace_open[]b4_parse_error_bmatch([custom\|detailed], [[
|
||||||
|
/* The user-facing name of the symbol whose (internal) number is
|
||||||
|
YYSYMBOL. No bounds checking. */
|
||||||
|
const char *
|
||||||
|
]b4_parser_class[::symbol_name (symbol_kind_type yysymbol)
|
||||||
|
{
|
||||||
|
static const char *const yy_sname[] =
|
||||||
|
{
|
||||||
|
]b4_symbol_names[
|
||||||
|
};]m4_ifdef([b4_translatable], [[
|
||||||
|
/* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YYTNAME[SYMBOL-NUM] is
|
||||||
|
internationalizable. */
|
||||||
|
static ]b4_int_type_for([b4_translatable])[ yytranslatable[] =
|
||||||
|
{
|
||||||
|
]b4_translatable[
|
||||||
|
};
|
||||||
|
return (yysymbol < YYNTOKENS && yytranslatable[yysymbol]
|
||||||
|
? _(yy_sname[yysymbol])
|
||||||
|
: yy_sname[yysymbol]);]], [[
|
||||||
|
return yy_sname[yysymbol];]])[
|
||||||
|
}
|
||||||
|
]])
|
||||||
|
b4_parse_error_case([verbose], [[
|
||||||
|
|
||||||
/* Return YYSTR after stripping away unnecessary quotes and
|
/* Return YYSTR after stripping away unnecessary quotes and
|
||||||
backslashes, so that it's suitable for yyerror. The heuristic is
|
backslashes, so that it's suitable for yyerror. The heuristic is
|
||||||
@@ -604,7 +665,7 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
/*---------------.
|
/*---------------.
|
||||||
| Symbol types. |
|
| symbol kinds. |
|
||||||
`---------------*/
|
`---------------*/
|
||||||
|
|
||||||
]b4_token_ctor_if([], [b4_public_types_define([cc])])[
|
]b4_token_ctor_if([], [b4_public_types_define([cc])])[
|
||||||
@@ -635,13 +696,13 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
: state (s)
|
: state (s)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
]b4_parser_class[::symbol_number_type
|
]b4_parser_class[::symbol_kind_type
|
||||||
]b4_parser_class[::by_state::type_get () const YY_NOEXCEPT
|
]b4_parser_class[::by_state::kind () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
if (state == empty_state)
|
if (state == empty_state)
|
||||||
return empty_symbol;
|
return symbol_kind::]b4_symbol(-2, kind)[;
|
||||||
else
|
else
|
||||||
return yystos_[+state];
|
return YY_CAST (symbol_kind_type, yystos_[+state]);
|
||||||
}
|
}
|
||||||
|
|
||||||
]b4_parser_class[::stack_symbol_type::stack_symbol_type ()
|
]b4_parser_class[::stack_symbol_type::stack_symbol_type ()
|
||||||
@@ -650,7 +711,7 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
]b4_parser_class[::stack_symbol_type::stack_symbol_type (YY_RVREF (stack_symbol_type) that)
|
]b4_parser_class[::stack_symbol_type::stack_symbol_type (YY_RVREF (stack_symbol_type) that)
|
||||||
: super_type (YY_MOVE (that.state)]b4_variant_if([], [, YY_MOVE (that.value)])b4_locations_if([, YY_MOVE (that.location)])[)
|
: super_type (YY_MOVE (that.state)]b4_variant_if([], [, YY_MOVE (that.value)])b4_locations_if([, YY_MOVE (that.location)])[)
|
||||||
{]b4_variant_if([
|
{]b4_variant_if([
|
||||||
b4_symbol_variant([that.type_get ()],
|
b4_symbol_variant([that.kind ()],
|
||||||
[value], [YY_MOVE_OR_COPY], [YY_MOVE (that.value)])])[
|
[value], [YY_MOVE_OR_COPY], [YY_MOVE (that.value)])])[
|
||||||
#if 201103L <= YY_CPLUSPLUS
|
#if 201103L <= YY_CPLUSPLUS
|
||||||
// that is emptied.
|
// that is emptied.
|
||||||
@@ -661,10 +722,10 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
]b4_parser_class[::stack_symbol_type::stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) that)
|
]b4_parser_class[::stack_symbol_type::stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) that)
|
||||||
: super_type (s]b4_variant_if([], [, YY_MOVE (that.value)])[]b4_locations_if([, YY_MOVE (that.location)])[)
|
: super_type (s]b4_variant_if([], [, YY_MOVE (that.value)])[]b4_locations_if([, YY_MOVE (that.location)])[)
|
||||||
{]b4_variant_if([
|
{]b4_variant_if([
|
||||||
b4_symbol_variant([that.type_get ()],
|
b4_symbol_variant([that.kind ()],
|
||||||
[value], [move], [YY_MOVE (that.value)])])[
|
[value], [move], [YY_MOVE (that.value)])])[
|
||||||
// that is emptied.
|
// that is emptied.
|
||||||
that.type = empty_symbol;
|
that.type = symbol_kind::]b4_symbol(-2, kind)[;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if YY_CPLUSPLUS < 201103L
|
#if YY_CPLUSPLUS < 201103L
|
||||||
@@ -672,7 +733,7 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
]b4_parser_class[::stack_symbol_type::operator= (const stack_symbol_type& that)
|
]b4_parser_class[::stack_symbol_type::operator= (const stack_symbol_type& that)
|
||||||
{
|
{
|
||||||
state = that.state;
|
state = that.state;
|
||||||
]b4_variant_if([b4_symbol_variant([that.type_get ()],
|
]b4_variant_if([b4_symbol_variant([that.kind ()],
|
||||||
[value], [copy], [that.value])],
|
[value], [copy], [that.value])],
|
||||||
[[value = that.value;]])[]b4_locations_if([
|
[[value = that.value;]])[]b4_locations_if([
|
||||||
location = that.location;])[
|
location = that.location;])[
|
||||||
@@ -683,7 +744,7 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
]b4_parser_class[::stack_symbol_type::operator= (stack_symbol_type& that)
|
]b4_parser_class[::stack_symbol_type::operator= (stack_symbol_type& that)
|
||||||
{
|
{
|
||||||
state = that.state;
|
state = that.state;
|
||||||
]b4_variant_if([b4_symbol_variant([that.type_get ()],
|
]b4_variant_if([b4_symbol_variant([that.kind ()],
|
||||||
[value], [move], [that.value])],
|
[value], [move], [that.value])],
|
||||||
[[value = that.value;]])[]b4_locations_if([
|
[[value = that.value;]])[]b4_locations_if([
|
||||||
location = that.location;])[
|
location = that.location;])[
|
||||||
@@ -701,7 +762,7 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
YY_SYMBOL_PRINT (yymsg, yysym);]b4_variant_if([], [
|
YY_SYMBOL_PRINT (yymsg, yysym);]b4_variant_if([], [
|
||||||
|
|
||||||
// User destructor.
|
// User destructor.
|
||||||
b4_symbol_actions([destructor], [yysym.type_get ()])])[
|
b4_symbol_actions([destructor], [yysym.kind ()])])[
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ]b4_api_PREFIX[DEBUG
|
#if ]b4_api_PREFIX[DEBUG
|
||||||
@@ -712,15 +773,15 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
{
|
{
|
||||||
std::ostream& yyoutput = yyo;
|
std::ostream& yyoutput = yyo;
|
||||||
YYUSE (yyoutput);
|
YYUSE (yyoutput);
|
||||||
symbol_number_type yytype = yysym.type_get ();
|
symbol_kind_type yykind = yysym.kind ();
|
||||||
#if defined __GNUC__ && ! defined __clang__ && ! defined __ICC && __GNUC__ * 100 + __GNUC_MINOR__ <= 408
|
#if defined __GNUC__ && ! defined __clang__ && ! defined __ICC && __GNUC__ * 100 + __GNUC_MINOR__ <= 408
|
||||||
// Avoid a (spurious) G++ 4.8 warning about "array subscript is
|
// Avoid a (spurious) G++ 4.8 warning about "array subscript is
|
||||||
// below array bounds".
|
// below array bounds".
|
||||||
if (yysym.empty ())
|
if (yysym.empty ())
|
||||||
std::abort ();
|
std::abort ();
|
||||||
#endif
|
#endif
|
||||||
yyo << (yytype < yyntokens_ ? "token" : "nterm")
|
yyo << (yykind < YYNTOKENS ? "token" : "nterm")
|
||||||
<< ' ' << yytname_[yytype] << " ("]b4_locations_if([
|
<< ' ' << yytname_[yykind] << " ("]b4_locations_if([
|
||||||
<< yysym.location << ": "])[;
|
<< yysym.location << ": "])[;
|
||||||
]b4_symbol_actions([printer])[
|
]b4_symbol_actions([printer])[
|
||||||
yyo << ')';
|
yyo << ')';
|
||||||
@@ -782,11 +843,11 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
]b4_parser_class[::state_type
|
]b4_parser_class[::state_type
|
||||||
]b4_parser_class[::yy_lr_goto_state_ (state_type yystate, int yysym)
|
]b4_parser_class[::yy_lr_goto_state_ (state_type yystate, int yysym)
|
||||||
{
|
{
|
||||||
int yyr = yypgoto_[yysym - yyntokens_] + yystate;
|
int yyr = yypgoto_[yysym - YYNTOKENS] + yystate;
|
||||||
if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate)
|
if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate)
|
||||||
return yytable_[yyr];
|
return yytable_[yyr];
|
||||||
else
|
else
|
||||||
return yydefgoto_[yysym - yyntokens_];
|
return yydefgoto_[yysym - YYNTOKENS];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -854,6 +915,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
`-----------------------------------------------*/
|
`-----------------------------------------------*/
|
||||||
yynewstate:
|
yynewstate:
|
||||||
YYCDEBUG << "Entering state " << int (yystack_[0].state) << '\n';
|
YYCDEBUG << "Entering state " << int (yystack_[0].state) << '\n';
|
||||||
|
YY_STACK_PRINT ();
|
||||||
|
|
||||||
// Accept?
|
// Accept?
|
||||||
if (yystack_[0].state == yyfinal_)
|
if (yystack_[0].state == yyfinal_)
|
||||||
@@ -874,7 +936,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
// Read a lookahead token.
|
// Read a lookahead token.
|
||||||
if (yyla.empty ())
|
if (yyla.empty ())
|
||||||
{
|
{
|
||||||
YYCDEBUG << "Reading a token: ";
|
YYCDEBUG << "Reading a token\n";
|
||||||
#if YY_EXCEPTIONS
|
#if YY_EXCEPTIONS
|
||||||
try
|
try
|
||||||
#endif // YY_EXCEPTIONS
|
#endif // YY_EXCEPTIONS
|
||||||
@@ -896,10 +958,10 @@ b4_dollar_popdef])[]dnl
|
|||||||
|
|
||||||
/* If the proper action on seeing token YYLA.TYPE is to reduce or
|
/* If the proper action on seeing token YYLA.TYPE is to reduce or
|
||||||
to detect an error, take that action. */
|
to detect an error, take that action. */
|
||||||
yyn += yyla.type_get ();
|
yyn += yyla.kind ();
|
||||||
if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ())
|
if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.kind ())
|
||||||
{]b4_lac_if([[
|
{]b4_lac_if([[
|
||||||
if (!yy_lac_establish_ (yyla.type_get ()))
|
if (!yy_lac_establish_ (yyla.kind ()))
|
||||||
goto yyerrlab;]])[
|
goto yyerrlab;]])[
|
||||||
goto yydefault;
|
goto yydefault;
|
||||||
}
|
}
|
||||||
@@ -910,7 +972,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
{
|
{
|
||||||
if (yy_table_value_is_error_ (yyn))
|
if (yy_table_value_is_error_ (yyn))
|
||||||
goto yyerrlab;]b4_lac_if([[
|
goto yyerrlab;]b4_lac_if([[
|
||||||
if (!yy_lac_establish_ (yyla.type_get ()))
|
if (!yy_lac_establish_ (yyla.kind ()))
|
||||||
goto yyerrlab;
|
goto yyerrlab;
|
||||||
]])[
|
]])[
|
||||||
yyn = -yyn;
|
yyn = -yyn;
|
||||||
@@ -992,7 +1054,6 @@ b4_dollar_popdef])[]dnl
|
|||||||
YY_SYMBOL_PRINT ("-> $$ =", yylhs);
|
YY_SYMBOL_PRINT ("-> $$ =", yylhs);
|
||||||
yypop_ (yylen);
|
yypop_ (yylen);
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
YY_STACK_PRINT ();
|
|
||||||
|
|
||||||
// Shift the result of the reduction.
|
// Shift the result of the reduction.
|
||||||
yypush_ (YY_NULLPTR, YY_MOVE (yylhs));
|
yypush_ (YY_NULLPTR, YY_MOVE (yylhs));
|
||||||
@@ -1007,9 +1068,17 @@ b4_dollar_popdef])[]dnl
|
|||||||
// If not already recovering from an error, report this error.
|
// If not already recovering from an error, report this error.
|
||||||
if (!yyerrstatus_)
|
if (!yyerrstatus_)
|
||||||
{
|
{
|
||||||
++yynerrs_;
|
++yynerrs_;]b4_parse_error_case(
|
||||||
error (]b4_join(b4_locations_if([yyla.location]),
|
[simple], [[
|
||||||
[[yysyntax_error_ (yystack_[0].state, yyla)]])[);
|
std::string msg = YY_("syntax error");
|
||||||
|
error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]],
|
||||||
|
[custom], [[
|
||||||
|
context yyctx (*this, yyla);
|
||||||
|
report_syntax_error (yyctx);]],
|
||||||
|
[[
|
||||||
|
context yyctx (*this, yyla);
|
||||||
|
std::string msg = yysyntax_error_ (yyctx);
|
||||||
|
error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]])[
|
||||||
}
|
}
|
||||||
|
|
||||||
]b4_locations_if([[
|
]b4_locations_if([[
|
||||||
@@ -1020,7 +1089,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
error, discard it. */
|
error, discard it. */
|
||||||
|
|
||||||
// Return failure if at end of input.
|
// Return failure if at end of input.
|
||||||
if (yyla.type_get () == yyeof_)
|
if (yyla.kind () == symbol_kind::]b4_symbol_prefix[YYEOF)
|
||||||
YYABORT;
|
YYABORT;
|
||||||
else if (!yyla.empty ())
|
else if (!yyla.empty ())
|
||||||
{
|
{
|
||||||
@@ -1046,6 +1115,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
this YYERROR. */
|
this YYERROR. */
|
||||||
yypop_ (yylen);
|
yypop_ (yylen);
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
|
YY_STACK_PRINT ();
|
||||||
goto yyerrlab1;
|
goto yyerrlab1;
|
||||||
|
|
||||||
|
|
||||||
@@ -1054,31 +1124,33 @@ b4_dollar_popdef])[]dnl
|
|||||||
`-------------------------------------------------------------*/
|
`-------------------------------------------------------------*/
|
||||||
yyerrlab1:
|
yyerrlab1:
|
||||||
yyerrstatus_ = 3; // Each real token shifted decrements this.
|
yyerrstatus_ = 3; // Each real token shifted decrements this.
|
||||||
|
// Pop stack until we find a state that shifts the error token.
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
yyn = yypact_[+yystack_[0].state];
|
||||||
|
if (!yy_pact_value_is_default_ (yyn))
|
||||||
|
{
|
||||||
|
yyn += symbol_kind::]b4_symbol_prefix[YYERROR;
|
||||||
|
if (0 <= yyn && yyn <= yylast_
|
||||||
|
&& yycheck_[yyn] == symbol_kind::]b4_symbol_prefix[YYERROR)
|
||||||
|
{
|
||||||
|
yyn = yytable_[yyn];
|
||||||
|
if (0 < yyn)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pop the current state because it cannot handle the error token.
|
||||||
|
if (yystack_.size () == 1)
|
||||||
|
YYABORT;
|
||||||
|
]b4_locations_if([[
|
||||||
|
yyerror_range[1].location = yystack_[0].location;]])[
|
||||||
|
yy_destroy_ ("Error: popping", yystack_[0]);
|
||||||
|
yypop_ ();
|
||||||
|
YY_STACK_PRINT ();
|
||||||
|
}
|
||||||
{
|
{
|
||||||
stack_symbol_type error_token;
|
stack_symbol_type error_token;
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
yyn = yypact_[+yystack_[0].state];
|
|
||||||
if (!yy_pact_value_is_default_ (yyn))
|
|
||||||
{
|
|
||||||
yyn += yy_error_token_;
|
|
||||||
if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yy_error_token_)
|
|
||||||
{
|
|
||||||
yyn = yytable_[yyn];
|
|
||||||
if (0 < yyn)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pop the current state because it cannot handle the error token.
|
|
||||||
if (yystack_.size () == 1)
|
|
||||||
YYABORT;
|
|
||||||
]b4_locations_if([[
|
|
||||||
yyerror_range[1].location = yystack_[0].location;]])[
|
|
||||||
yy_destroy_ ("Error: popping", yystack_[0]);
|
|
||||||
yypop_ ();
|
|
||||||
YY_STACK_PRINT ();
|
|
||||||
}
|
|
||||||
]b4_locations_if([[
|
]b4_locations_if([[
|
||||||
yyerror_range[2].location = yyla.location;
|
yyerror_range[2].location = yyla.location;
|
||||||
YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);]])[
|
YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);]])[
|
||||||
@@ -1117,6 +1189,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
/* Do not reclaim the symbols of the rule whose action triggered
|
/* Do not reclaim the symbols of the rule whose action triggered
|
||||||
this YYABORT or YYACCEPT. */
|
this YYABORT or YYACCEPT. */
|
||||||
yypop_ (yylen);
|
yypop_ (yylen);
|
||||||
|
YY_STACK_PRINT ();
|
||||||
while (1 < yystack_.size ())
|
while (1 < yystack_.size ())
|
||||||
{
|
{
|
||||||
yy_destroy_ ("Cleanup: popping", yystack_[0]);
|
yy_destroy_ ("Cleanup: popping", yystack_[0]);
|
||||||
@@ -1149,10 +1222,71 @@ b4_dollar_popdef])[]dnl
|
|||||||
{
|
{
|
||||||
error (]b4_join(b4_locations_if([yyexc.location]),
|
error (]b4_join(b4_locations_if([yyexc.location]),
|
||||||
[[yyexc.what ()]])[);
|
[[yyexc.what ()]])[);
|
||||||
}]b4_lac_if([[
|
}]b4_parse_error_bmatch([custom\|detailed\|verbose], [[
|
||||||
|
|
||||||
|
// ]b4_parser_class[::context.
|
||||||
|
]b4_parser_class[::context::context (const ]b4_parser_class[& yyparser, const symbol_type& yyla)
|
||||||
|
: yyparser_ (yyparser)
|
||||||
|
, yyla_ (yyla)
|
||||||
|
{}
|
||||||
|
|
||||||
|
int
|
||||||
|
]b4_parser_class[::context::expected_tokens (symbol_kind_type yyarg[], int yyargn) const
|
||||||
|
{
|
||||||
|
// Actual number of expected tokens
|
||||||
|
int yycount = 0;
|
||||||
|
]b4_lac_if([[
|
||||||
|
#if ]b4_api_PREFIX[DEBUG
|
||||||
|
// Execute LAC once. We don't care if it is successful, we
|
||||||
|
// only do it for the sake of debugging output.
|
||||||
|
if (!yyparser_.yy_lac_established_)
|
||||||
|
yyparser_.yy_lac_check_ (yyla_.kind ());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (int yyx = 0; yyx < YYNTOKENS; ++yyx)
|
||||||
|
{
|
||||||
|
symbol_kind_type yysym = YY_CAST (symbol_kind_type, yyx);
|
||||||
|
if (yysym != symbol_kind::]b4_symbol_prefix[YYERROR
|
||||||
|
&& yysym != symbol_kind::]b4_symbol_prefix[YYUNDEF
|
||||||
|
&& yyparser_.yy_lac_check_ (yysym))
|
||||||
|
{
|
||||||
|
if (!yyarg)
|
||||||
|
++yycount;
|
||||||
|
else if (yycount == yyargn)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
yyarg[yycount++] = yysym;
|
||||||
|
}
|
||||||
|
}]], [[
|
||||||
|
int yyn = yypact_[+yyparser_.yystack_[0].state];
|
||||||
|
if (!yy_pact_value_is_default_ (yyn))
|
||||||
|
{
|
||||||
|
/* Start YYX at -YYN if negative to avoid negative indexes in
|
||||||
|
YYCHECK. In other words, skip the first -YYN actions for
|
||||||
|
this state because they are default actions. */
|
||||||
|
int yyxbegin = yyn < 0 ? -yyn : 0;
|
||||||
|
// Stay within bounds of both yycheck and yytname.
|
||||||
|
int yychecklim = yylast_ - yyn + 1;
|
||||||
|
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
|
||||||
|
for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
|
||||||
|
if (yycheck_[yyx + yyn] == yyx && yyx != symbol_kind::]b4_symbol_prefix[YYERROR
|
||||||
|
&& !yy_table_value_is_error_ (yytable_[yyx + yyn]))
|
||||||
|
{
|
||||||
|
if (!yyarg)
|
||||||
|
++yycount;
|
||||||
|
else if (yycount == yyargn)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
yyarg[yycount++] = YY_CAST (symbol_kind_type, yyx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]])[
|
||||||
|
return yycount;
|
||||||
|
}
|
||||||
|
|
||||||
|
]])b4_lac_if([[
|
||||||
bool
|
bool
|
||||||
]b4_parser_class[::yy_lac_check_ (int yytoken) const
|
]b4_parser_class[::yy_lac_check_ (symbol_kind_type yytoken) const
|
||||||
{
|
{
|
||||||
// Logically, the yylac_stack's lifetime is confined to this function.
|
// Logically, the yylac_stack's lifetime is confined to this function.
|
||||||
// Clear it, to get rid of potential left-overs from previous call.
|
// Clear it, to get rid of potential left-overs from previous call.
|
||||||
@@ -1230,7 +1364,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
|
|
||||||
// Establish the initial context if no initial context currently exists.
|
// Establish the initial context if no initial context currently exists.
|
||||||
bool
|
bool
|
||||||
]b4_parser_class[::yy_lac_establish_ (int yytoken)
|
]b4_parser_class[::yy_lac_establish_ (symbol_kind_type yytoken)
|
||||||
{
|
{
|
||||||
/* Establish the initial context for the current lookahead if no initial
|
/* Establish the initial context for the current lookahead if no initial
|
||||||
context is currently established.
|
context is currently established.
|
||||||
@@ -1288,22 +1422,12 @@ b4_dollar_popdef])[]dnl
|
|||||||
<< evt << '\n';
|
<< evt << '\n';
|
||||||
yy_lac_established_ = false;
|
yy_lac_established_ = false;
|
||||||
}
|
}
|
||||||
}]])[
|
}]])b4_parse_error_bmatch([detailed\|verbose], [[
|
||||||
|
|
||||||
// Generate an error message.
|
|
||||||
std::string
|
|
||||||
]b4_parser_class[::yysyntax_error_ (]dnl
|
|
||||||
b4_error_verbose_if([state_type yystate, const symbol_type& yyla],
|
|
||||||
[state_type, const symbol_type&])[) const
|
|
||||||
{]b4_error_verbose_if([[
|
|
||||||
// Number of reported tokens (one for the "unexpected", one per
|
|
||||||
// "expected").
|
|
||||||
std::ptrdiff_t yycount = 0;
|
|
||||||
// Its maximum.
|
|
||||||
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
|
|
||||||
// Arguments of yyformat.
|
|
||||||
char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
|
|
||||||
|
|
||||||
|
int
|
||||||
|
]b4_parser_class[::yy_syntax_error_arguments_ (const context& yyctx,
|
||||||
|
symbol_kind_type yyarg[], int yyargn) const
|
||||||
|
{
|
||||||
/* There are many possibilities here to consider:
|
/* There are many possibilities here to consider:
|
||||||
- If this state is a consistent state with a default action, then
|
- If this state is a consistent state with a default action, then
|
||||||
the only way this function was invoked is if the default action
|
the only way this function was invoked is if the default action
|
||||||
@@ -1334,46 +1458,26 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla],
|
|||||||
one exception: it will still contain any token that will not be
|
one exception: it will still contain any token that will not be
|
||||||
accepted due to an error action in a later state.]])[
|
accepted due to an error action in a later state.]])[
|
||||||
*/
|
*/
|
||||||
if (!yyla.empty ())
|
|
||||||
|
if (!yyctx.lookahead ().empty ())
|
||||||
{
|
{
|
||||||
symbol_number_type yytoken = yyla.type_get ();
|
if (yyarg)
|
||||||
yyarg[yycount++] = yytname_[yytoken];]b4_lac_if([[
|
yyarg[0] = yyctx.token ();
|
||||||
|
int yyn = yyctx.expected_tokens (yyarg ? yyarg + 1 : yyarg, yyargn - 1);
|
||||||
#if ]b4_api_PREFIX[DEBUG
|
return yyn + 1;
|
||||||
// Execute LAC once. We don't care if it is successful, we
|
|
||||||
// only do it for the sake of debugging output.
|
|
||||||
if (!yy_lac_established_)
|
|
||||||
yy_lac_check_ (yytoken);
|
|
||||||
#endif]])[
|
|
||||||
|
|
||||||
int yyn = yypact_[+yystate];
|
|
||||||
if (!yy_pact_value_is_default_ (yyn))
|
|
||||||
{]b4_lac_if([[
|
|
||||||
for (int yyx = 0; yyx < yyntokens_; ++yyx)
|
|
||||||
if (yyx != yy_error_token_ && yyx != yy_undef_token_
|
|
||||||
&& yy_lac_check_ (yyx))
|
|
||||||
{]], [[
|
|
||||||
/* Start YYX at -YYN if negative to avoid negative indexes in
|
|
||||||
YYCHECK. In other words, skip the first -YYN actions for
|
|
||||||
this state because they are default actions. */
|
|
||||||
int yyxbegin = yyn < 0 ? -yyn : 0;
|
|
||||||
// Stay within bounds of both yycheck and yytname.
|
|
||||||
int yychecklim = yylast_ - yyn + 1;
|
|
||||||
int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
|
|
||||||
for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
|
|
||||||
if (yycheck_[yyx + yyn] == yyx && yyx != yy_error_token_
|
|
||||||
&& !yy_table_value_is_error_ (yytable_[yyx + yyn]))
|
|
||||||
{]])[
|
|
||||||
if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
|
|
||||||
{
|
|
||||||
yycount = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
yyarg[yycount++] = yytname_[yyx];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate an error message.
|
||||||
|
std::string
|
||||||
|
]b4_parser_class[::yysyntax_error_ (const context& yyctx) const
|
||||||
|
{
|
||||||
|
// Its maximum.
|
||||||
|
enum { YYARGS_MAX = 5 };
|
||||||
|
// Arguments of yyformat.
|
||||||
|
symbol_kind_type yyarg[YYARGS_MAX];
|
||||||
|
int yycount = yy_syntax_error_arguments_ (yyctx, yyarg, YYARGS_MAX);
|
||||||
|
|
||||||
char const* yyformat = YY_NULLPTR;
|
char const* yyformat = YY_NULLPTR;
|
||||||
switch (yycount)
|
switch (yycount)
|
||||||
@@ -1398,14 +1502,15 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla],
|
|||||||
for (char const* yyp = yyformat; *yyp; ++yyp)
|
for (char const* yyp = yyformat; *yyp; ++yyp)
|
||||||
if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
|
if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
|
||||||
{
|
{
|
||||||
yyres += yytnamerr_ (yyarg[yyi++]);
|
yyres += ]b4_parse_error_case([verbose],
|
||||||
|
[[yytnamerr_ (yytname_[yyarg[yyi++]])]],
|
||||||
|
[[symbol_name (yyarg[yyi++])]])[;
|
||||||
++yyp;
|
++yyp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
yyres += *yyp;
|
yyres += *yyp;
|
||||||
return yyres;]], [[
|
return yyres;
|
||||||
return YY_("syntax error");]])[
|
}]])[
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class::yypact_ninf_ = b4_pact_ninf[;
|
const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class::yypact_ninf_ = b4_pact_ninf[;
|
||||||
@@ -1414,19 +1519,19 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla],
|
|||||||
|
|
||||||
]b4_parser_tables_define[
|
]b4_parser_tables_define[
|
||||||
|
|
||||||
]b4_token_table_if([], [[#if ]b4_api_PREFIX[DEBUG]])[
|
]b4_tname_if([], [[#if ]b4_api_PREFIX[DEBUG]])[
|
||||||
// YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
|
// YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
|
||||||
// First, the terminals, then, starting at \a yyntokens_, nonterminals.
|
// First, the terminals, then, starting at \a YYNTOKENS, nonterminals.
|
||||||
const char*
|
const char*
|
||||||
const ]b4_parser_class[::yytname_[] =
|
const ]b4_parser_class[::yytname_[] =
|
||||||
{
|
{
|
||||||
]b4_tname[
|
]b4_tname[
|
||||||
};
|
};
|
||||||
|
]b4_tname_if([], [[#endif]])[
|
||||||
|
|
||||||
]b4_token_table_if([[#if ]b4_api_PREFIX[DEBUG]])[
|
#if ]b4_api_PREFIX[DEBUG][
|
||||||
]b4_integral_parser_table_define([rline], [b4_rline])[
|
]b4_integral_parser_table_define([rline], [b4_rline])[
|
||||||
|
|
||||||
// Print the state stack on the debug stream.
|
|
||||||
void
|
void
|
||||||
]b4_parser_class[::yystack_print_ ()
|
]b4_parser_class[::yystack_print_ ()
|
||||||
{
|
{
|
||||||
@@ -1439,7 +1544,6 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla],
|
|||||||
*yycdebug_ << '\n';
|
*yycdebug_ << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report on the debug stream that the rule \a yyrule is going to be reduced.
|
|
||||||
void
|
void
|
||||||
]b4_parser_class[::yy_reduce_print_ (int yyrule)
|
]b4_parser_class[::yy_reduce_print_ (int yyrule)
|
||||||
{
|
{
|
||||||
|
|||||||
+68
-56
@@ -182,11 +182,13 @@ b4_user_union_members
|
|||||||
};],
|
};],
|
||||||
[m4_if(b4_tag_seen_flag, 0,
|
[m4_if(b4_tag_seen_flag, 0,
|
||||||
[[private alias int YYSemanticType;]])])[
|
[[private alias int YYSemanticType;]])])[
|
||||||
]b4_token_enums(b4_tokens)[
|
]b4_token_enums[
|
||||||
]b4_parser_class_declaration[
|
]b4_parser_class_declaration[
|
||||||
{
|
{
|
||||||
]b4_identification[
|
]b4_identification[
|
||||||
|
|
||||||
|
]b4_declare_symbol_enum[
|
||||||
|
|
||||||
]b4_locations_if([[
|
]b4_locations_if([[
|
||||||
private final ]b4_location_type[ yylloc_from_stack (ref YYStack rhs, int n)
|
private final ]b4_location_type[ yylloc_from_stack (ref YYStack rhs, int n)
|
||||||
{
|
{
|
||||||
@@ -261,6 +263,11 @@ b4_user_union_members
|
|||||||
public final void setDebugLevel(int level) { yydebug = level; }
|
public final void setDebugLevel(int level) { yydebug = level; }
|
||||||
|
|
||||||
protected final void yycdebug (string s) {
|
protected final void yycdebug (string s) {
|
||||||
|
if (0 < yydebug)
|
||||||
|
yyDebugStream.write (s);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void yycdebugln (string s) {
|
||||||
if (0 < yydebug)
|
if (0 < yydebug)
|
||||||
yyDebugStream.writeln (s);
|
yyDebugStream.writeln (s);
|
||||||
}
|
}
|
||||||
@@ -335,7 +342,8 @@ b4_user_union_members
|
|||||||
}
|
}
|
||||||
|
|
||||||
]b4_parse_trace_if([[
|
]b4_parse_trace_if([[
|
||||||
yy_symbol_print ("-> $$ =", yyr1_[yyn], yyval]b4_locations_if([, yyloc])[);]])[
|
import std.conv : to;
|
||||||
|
yy_symbol_print ("-> $$ =", to!SymbolKind (yyr1_[yyn]), yyval]b4_locations_if([, yyloc])[);]])[
|
||||||
|
|
||||||
yystack.pop (yylen);
|
yystack.pop (yylen);
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
@@ -393,21 +401,21 @@ b4_user_union_members
|
|||||||
| Print this symbol on YYOUTPUT. |
|
| Print this symbol on YYOUTPUT. |
|
||||||
`--------------------------------*/
|
`--------------------------------*/
|
||||||
|
|
||||||
private final void yy_symbol_print (string s, int yytype,
|
private final void yy_symbol_print (string s, SymbolKind yykind,
|
||||||
ref ]b4_yystype[ yyvaluep]dnl
|
ref ]b4_yystype[ yyvaluep]dnl
|
||||||
b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
|
b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
|
||||||
{
|
{
|
||||||
if (0 < yydebug)
|
if (0 < yydebug)
|
||||||
{
|
{
|
||||||
string message = s ~ (yytype < yyntokens_ ? " token " : " nterm ")
|
string message = s ~ (yykind < yyntokens_ ? " token " : " nterm ")
|
||||||
~ yytname_[yytype] ~ " ("]b4_locations_if([
|
~ yytname_[yykind] ~ " ("]b4_locations_if([
|
||||||
~ yylocationp.toString() ~ ": "])[;
|
~ yylocationp.toString() ~ ": "])[;
|
||||||
static if (__traits(compiles, message ~= yyvaluep.toString ()))
|
static if (__traits(compiles, message ~= yyvaluep.toString ()))
|
||||||
message ~= yyvaluep.toString ();
|
message ~= yyvaluep.toString ();
|
||||||
else
|
else
|
||||||
message ~= format ("%s", &yyvaluep);
|
message ~= format ("%s", &yyvaluep);
|
||||||
message ~= ")";
|
message ~= ")";
|
||||||
yycdebug (message);
|
yycdebugln (message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]])[
|
]])[
|
||||||
@@ -421,8 +429,8 @@ b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
|
|||||||
public bool parse ()
|
public bool parse ()
|
||||||
{
|
{
|
||||||
/// Lookahead and lookahead in internal form.
|
/// Lookahead and lookahead in internal form.
|
||||||
int yychar = yyempty_;
|
int yychar = TokenKind.YYEMPTY;
|
||||||
int yytoken = 0;
|
SymbolKind yytoken = SymbolKind.]b4_symbol(-2, kind)[;
|
||||||
|
|
||||||
/* State. */
|
/* State. */
|
||||||
int yyn = 0;
|
int yyn = 0;
|
||||||
@@ -445,9 +453,9 @@ b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
|
|||||||
/// Semantic value of the lookahead.
|
/// Semantic value of the lookahead.
|
||||||
]b4_yystype[ yylval;
|
]b4_yystype[ yylval;
|
||||||
|
|
||||||
int yyresult;]b4_parse_trace_if([[
|
bool yyresult;]b4_parse_trace_if([[
|
||||||
|
|
||||||
yycdebug ("Starting parse\n");]])[
|
yycdebugln ("Starting parse");]])[
|
||||||
yyerrstatus_ = 0;
|
yyerrstatus_ = 0;
|
||||||
|
|
||||||
]m4_ifdef([b4_initial_action], [
|
]m4_ifdef([b4_initial_action], [
|
||||||
@@ -468,7 +476,7 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
/* New state. Unlike in the C/C++ skeletons, the state is already
|
/* New state. Unlike in the C/C++ skeletons, the state is already
|
||||||
pushed when we come here. */
|
pushed when we come here. */
|
||||||
case YYNEWSTATE:]b4_parse_trace_if([[
|
case YYNEWSTATE:]b4_parse_trace_if([[
|
||||||
yycdebug (format("Entering state %d\n", yystate));
|
yycdebugln (format("Entering state %d", yystate));
|
||||||
if (0 < yydebug)
|
if (0 < yydebug)
|
||||||
yystack.print (yyDebugStream);]])[
|
yystack.print (yyDebugStream);]])[
|
||||||
|
|
||||||
@@ -485,9 +493,9 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Read a lookahead token. */
|
/* Read a lookahead token. */
|
||||||
if (yychar == yyempty_)
|
if (yychar == TokenKind.YYEMPTY)
|
||||||
{]b4_parse_trace_if([[
|
{]b4_parse_trace_if([[
|
||||||
yycdebug ("Reading a token: ");]])[
|
yycdebugln ("Reading a token");]])[
|
||||||
yychar = yylex ();]b4_locations_if([[
|
yychar = yylex ();]b4_locations_if([[
|
||||||
static if (yy_location_is_class) {
|
static if (yy_location_is_class) {
|
||||||
yylloc = new ]b4_location_type[(yylexer.startPos, yylexer.endPos);
|
yylloc = new ]b4_location_type[(yylexer.startPos, yylexer.endPos);
|
||||||
@@ -499,8 +507,7 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
|
|
||||||
/* Convert token to internal form. */
|
/* Convert token to internal form. */
|
||||||
yytoken = yytranslate_ (yychar);]b4_parse_trace_if([[
|
yytoken = yytranslate_ (yychar);]b4_parse_trace_if([[
|
||||||
yy_symbol_print ("Next token is",
|
yy_symbol_print ("Next token is", yytoken, yylval]b4_locations_if([, yylloc])[);]])[
|
||||||
yytoken, yylval]b4_locations_if([, yylloc])[);]])[
|
|
||||||
|
|
||||||
/* If the proper action on seeing token YYTOKEN is to reduce or to
|
/* If the proper action on seeing token YYTOKEN is to reduce or to
|
||||||
detect an error, take that action. */
|
detect an error, take that action. */
|
||||||
@@ -522,11 +529,10 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Shift the lookahead token. */]b4_parse_trace_if([[
|
/* Shift the lookahead token. */]b4_parse_trace_if([[
|
||||||
yy_symbol_print ("Shifting", yytoken,
|
yy_symbol_print ("Shifting", yytoken, yylval]b4_locations_if([, yylloc])[);]])[
|
||||||
yylval]b4_locations_if([, yylloc])[);]])[
|
|
||||||
|
|
||||||
/* Discard the token being shifted. */
|
/* Discard the token being shifted. */
|
||||||
yychar = yyempty_;
|
yychar = TokenKind.YYEMPTY;
|
||||||
|
|
||||||
/* Count tokens shifted since error; after three, turn off error
|
/* Count tokens shifted since error; after three, turn off error
|
||||||
* status. */
|
* status. */
|
||||||
@@ -559,16 +565,16 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
yystate = yystack.stateAt (0);
|
yystate = yystack.stateAt (0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*------------------------------------.
|
/*--------------------------------------.
|
||||||
| yyerrlab -- here on detecting error |
|
| yyerrlab -- here on detecting error. |
|
||||||
`------------------------------------*/
|
`--------------------------------------*/
|
||||||
case YYERRLAB:
|
case YYERRLAB:
|
||||||
/* If not already recovering from an error, report this error. */
|
/* If not already recovering from an error, report this error. */
|
||||||
if (yyerrstatus_ == 0)
|
if (yyerrstatus_ == 0)
|
||||||
{
|
{
|
||||||
++yynerrs_;
|
++yynerrs_;
|
||||||
if (yychar == yyempty_)
|
if (yychar == TokenKind.YYEMPTY)
|
||||||
yytoken = yyempty_;
|
yytoken = SymbolKind.]b4_symbol(-2, kind)[;
|
||||||
yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken));
|
yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -578,14 +584,14 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
/* If just tried and failed to reuse lookahead token after an
|
/* If just tried and failed to reuse lookahead token after an
|
||||||
* error, discard it. */
|
* error, discard it. */
|
||||||
|
|
||||||
if (yychar <= YYTokenType.EOF)
|
if (yychar <= TokenKind.]b4_symbol(0, [id])[)
|
||||||
{
|
{
|
||||||
/* Return failure if at end of input. */
|
/* Return failure if at end of input. */
|
||||||
if (yychar == YYTokenType.EOF)
|
if (yychar == TokenKind.]b4_symbol(0, [id])[)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
yychar = yyempty_;
|
yychar = TokenKind.YYEMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Else will try to reuse lookahead token after shifting the error
|
/* Else will try to reuse lookahead token after shifting the error
|
||||||
@@ -612,13 +618,14 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
case YYERRLAB1:
|
case YYERRLAB1:
|
||||||
yyerrstatus_ = 3; /* Each real token shifted decrements this. */
|
yyerrstatus_ = 3; /* Each real token shifted decrements this. */
|
||||||
|
|
||||||
|
// Pop stack until we find a state that shifts the error token.
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
yyn = yypact_[yystate];
|
yyn = yypact_[yystate];
|
||||||
if (!yy_pact_value_is_default_ (yyn))
|
if (!yy_pact_value_is_default_ (yyn))
|
||||||
{
|
{
|
||||||
yyn += yy_error_token_;
|
yyn += SymbolKind.]b4_symbol_prefix[YYERROR;
|
||||||
if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yy_error_token_)
|
if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == SymbolKind.]b4_symbol_prefix[YYERROR)
|
||||||
{
|
{
|
||||||
yyn = yytable_[yyn];
|
yyn = yytable_[yyn];
|
||||||
if (0 < yyn)
|
if (0 < yyn)
|
||||||
@@ -645,9 +652,8 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
yystack.pop (2);])[
|
yystack.pop (2);])[
|
||||||
|
|
||||||
/* Shift the error token. */]b4_parse_trace_if([[
|
/* Shift the error token. */]b4_parse_trace_if([[
|
||||||
yy_symbol_print ("Shifting", yystos_[yyn],
|
import std.conv : to;
|
||||||
yylval]b4_locations_if([, yyloc])[);]])[
|
yy_symbol_print ("Shifting", to!SymbolKind (yystos_[yyn]), yylval]b4_locations_if([, yyloc])[);]])[
|
||||||
|
|
||||||
yystate = yyn;
|
yystate = yyn;
|
||||||
yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
|
yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
|
||||||
label = YYNEWSTATE;
|
label = YYNEWSTATE;
|
||||||
@@ -655,17 +661,26 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
|
|
||||||
/* Accept. */
|
/* Accept. */
|
||||||
case YYACCEPT:
|
case YYACCEPT:
|
||||||
return true;
|
yyresult = true;
|
||||||
|
label = YYRETURN;
|
||||||
|
break;
|
||||||
|
|
||||||
/* Abort. */
|
/* Abort. */
|
||||||
case YYABORT:
|
case YYABORT:
|
||||||
return false;
|
yyresult = false;
|
||||||
|
label = YYRETURN;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case YYRETURN:]b4_parse_trace_if([[
|
||||||
|
if (0 < yydebug)
|
||||||
|
yystack.print (yyDebugStream);]])[
|
||||||
|
return yyresult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate an error message.
|
// Generate an error message.
|
||||||
private final string yysyntax_error (int yystate, int tok)
|
private final string yysyntax_error (int yystate, SymbolKind tok)
|
||||||
{]b4_error_verbose_if([[
|
{]b4_parse_error_case([verbose], [[
|
||||||
/* There are many possibilities here to consider:
|
/* There are many possibilities here to consider:
|
||||||
- Assume YYFAIL is not used. It's too flawed to consider.
|
- Assume YYFAIL is not used. It's too flawed to consider.
|
||||||
See
|
See
|
||||||
@@ -697,7 +712,7 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
will still contain any token that will not be accepted due
|
will still contain any token that will not be accepted due
|
||||||
to an error action in a later state.
|
to an error action in a later state.
|
||||||
*/
|
*/
|
||||||
if (tok != yyempty_)
|
if (tok != SymbolKind.]b4_symbol(-2, kind)[)
|
||||||
{
|
{
|
||||||
// FIXME: This method of building the message is not compatible
|
// FIXME: This method of building the message is not compatible
|
||||||
// with internationalization.
|
// with internationalization.
|
||||||
@@ -716,14 +731,14 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
|
int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int x = yyxbegin; x < yyxend; ++x)
|
for (int x = yyxbegin; x < yyxend; ++x)
|
||||||
if (yycheck_[x + yyn] == x && x != yy_error_token_
|
if (yycheck_[x + yyn] == x && x != SymbolKind.]b4_symbol_prefix[YYERROR
|
||||||
&& !yy_table_value_is_error_ (yytable_[x + yyn]))
|
&& !yy_table_value_is_error_ (yytable_[x + yyn]))
|
||||||
++count;
|
++count;
|
||||||
if (count < 5)
|
if (count < 5)
|
||||||
{
|
{
|
||||||
count = 0;
|
count = 0;
|
||||||
for (int x = yyxbegin; x < yyxend; ++x)
|
for (int x = yyxbegin; x < yyxend; ++x)
|
||||||
if (yycheck_[x + yyn] == x && x != yy_error_token_
|
if (yycheck_[x + yyn] == x && x != SymbolKind.]b4_symbol_prefix[YYERROR
|
||||||
&& !yy_table_value_is_error_ (yytable_[x + yyn]))
|
&& !yy_table_value_is_error_ (yytable_[x + yyn]))
|
||||||
{
|
{
|
||||||
res ~= count++ == 0 ? ", expecting " : " or ";
|
res ~= count++ == 0 ? ", expecting " : " or ";
|
||||||
@@ -788,47 +803,45 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
int yylno = yyrline_[yyrule];
|
int yylno = yyrline_[yyrule];
|
||||||
int yynrhs = yyr2_[yyrule];
|
int yynrhs = yyr2_[yyrule];
|
||||||
/* Print the symbols being reduced, and their result. */
|
/* Print the symbols being reduced, and their result. */
|
||||||
yycdebug (format("Reducing stack by rule %d (line %d), ",
|
yycdebugln (format("Reducing stack by rule %d (line %d):",
|
||||||
yyrule - 1, yylno));
|
yyrule - 1, yylno));
|
||||||
|
|
||||||
/* The symbols being reduced. */
|
/* The symbols being reduced. */
|
||||||
|
import std.conv : to;
|
||||||
for (int yyi = 0; yyi < yynrhs; yyi++)
|
for (int yyi = 0; yyi < yynrhs; yyi++)
|
||||||
yy_symbol_print (format(" $%d =", yyi + 1),
|
yy_symbol_print (format(" $%d =", yyi + 1),
|
||||||
yystos_[yystack.stateAt(yynrhs - (yyi + 1))],
|
to!SymbolKind (yystos_[yystack.stateAt(yynrhs - (yyi + 1))]),
|
||||||
]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([,
|
]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([,
|
||||||
b4_rhs_location(yynrhs, yyi + 1)])[);
|
b4_rhs_location(yynrhs, yyi + 1)])[);
|
||||||
}
|
}
|
||||||
]])[
|
]])[
|
||||||
|
|
||||||
private static token_number_type yytranslate_ (int t)
|
private static SymbolKind yytranslate_ (int t)
|
||||||
{
|
{
|
||||||
]b4_api_token_raw_if(
|
]b4_api_token_raw_if(
|
||||||
[[ import std.conv : to;
|
[[ import std.conv : to;
|
||||||
return to!byte (t);]],
|
return to!SymbolKind (t);]],
|
||||||
[[ /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
|
[[ /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
|
||||||
immutable token_number_type[] translate_table =
|
immutable ]b4_int_type_for([b4_translate])[[] translate_table =
|
||||||
@{
|
@{
|
||||||
]b4_translate[
|
]b4_translate[
|
||||||
@};
|
@};
|
||||||
|
|
||||||
immutable int user_token_number_max_ = ]b4_user_token_number_max[;
|
immutable int user_token_number_max_ = ]b4_user_token_number_max[;
|
||||||
immutable token_number_type undef_token_ = ]b4_undef_token_number[;
|
|
||||||
|
|
||||||
if (t <= 0)
|
if (t <= 0)
|
||||||
return YYTokenType.EOF;
|
return SymbolKind.]b4_symbol_prefix[YYEOF;
|
||||||
else if (t <= user_token_number_max_)
|
else if (t <= user_token_number_max_)
|
||||||
return translate_table[t];
|
{
|
||||||
|
import std.conv : to;
|
||||||
|
return to!SymbolKind (translate_table[t]);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return undef_token_;]])[
|
return SymbolKind.]b4_symbol_prefix[YYUNDEF;]])[
|
||||||
}
|
}
|
||||||
|
|
||||||
alias ]b4_int_type_for([b4_translate])[ token_number_type;
|
|
||||||
|
|
||||||
private static immutable token_number_type yy_error_token_ = 1;
|
|
||||||
|
|
||||||
private static immutable int yylast_ = ]b4_last[;
|
private static immutable int yylast_ = ]b4_last[;
|
||||||
private static immutable int yynnts_ = ]b4_nterms_number[;
|
private static immutable int yynnts_ = ]b4_nterms_number[;
|
||||||
private static immutable int yyempty_ = -2;
|
|
||||||
private static immutable int yyfinal_ = ]b4_final_state_number[;
|
private static immutable int yyfinal_ = ]b4_final_state_number[;
|
||||||
private static immutable int yyntokens_ = ]b4_tokens_number[;
|
private static immutable int yyntokens_ = ]b4_tokens_number[;
|
||||||
|
|
||||||
@@ -887,9 +900,8 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
stream.writeln ();
|
stream.writeln ();
|
||||||
}]])[
|
}]])[
|
||||||
}
|
}
|
||||||
|
|
||||||
/* User implementation code. */
|
|
||||||
]b4_percent_code_get[
|
]b4_percent_code_get[
|
||||||
}
|
}
|
||||||
]b4_epilogue[]dnl
|
]b4_percent_code_get([[epilogue]])[]dnl
|
||||||
|
b4_epilogue[]dnl
|
||||||
b4_output_end
|
b4_output_end
|
||||||
|
|||||||
+243
-191
@@ -49,13 +49,13 @@ b4_use_push_for_pull_if([
|
|||||||
b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])],
|
b4_push_if([m4_define([b4_use_push_for_pull_flag], [[0]])],
|
||||||
[m4_define([b4_push_flag], [[1]])])])
|
[m4_define([b4_push_flag], [[1]])])])
|
||||||
|
|
||||||
# Define a macro to encapsulate the parse state variables.
|
# Define a macro to encapsulate the parse state variables. This
|
||||||
# This allows them to be defined either in parse() when doing
|
# allows them to be defined either in parse() when doing pull parsing,
|
||||||
# pull parsing, or as class instance variable when doing push parsing.
|
# or as class instance variable when doing push parsing.
|
||||||
m4_define([b4_define_state],[[
|
m4_define([b4_define_state],[[
|
||||||
/* Lookahead and lookahead in internal form. */
|
/* Lookahead and lookahead in internal form. */
|
||||||
int yychar = yyempty_;
|
int yychar = YYEMPTY_;
|
||||||
int yytoken = 0;
|
SymbolKind yytoken = null;
|
||||||
|
|
||||||
/* State. */
|
/* State. */
|
||||||
int yyn = 0;
|
int yyn = 0;
|
||||||
@@ -64,8 +64,7 @@ m4_define([b4_define_state],[[
|
|||||||
YYStack yystack = new YYStack ();
|
YYStack yystack = new YYStack ();
|
||||||
int label = YYNEWSTATE;
|
int label = YYNEWSTATE;
|
||||||
|
|
||||||
/* Error handling. */
|
]b4_locations_if([[
|
||||||
int yynerrs_ = 0;]b4_locations_if([[
|
|
||||||
/* The location where the error started. */
|
/* The location where the error started. */
|
||||||
]b4_location_type[ yyerrloc = null;
|
]b4_location_type[ yyerrloc = null;
|
||||||
|
|
||||||
@@ -83,6 +82,7 @@ m4_define([b4_define_state],[[
|
|||||||
]])[
|
]])[
|
||||||
]b4_user_pre_prologue[
|
]b4_user_pre_prologue[
|
||||||
]b4_user_post_prologue[
|
]b4_user_post_prologue[
|
||||||
|
import java.text.MessageFormat;
|
||||||
]b4_percent_code_get([[imports]])[
|
]b4_percent_code_get([[imports]])[
|
||||||
/**
|
/**
|
||||||
* A Bison parser, automatically generated from <tt>]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[</tt>.
|
* A Bison parser, automatically generated from <tt>]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[</tt>.
|
||||||
@@ -91,8 +91,10 @@ m4_define([b4_define_state],[[
|
|||||||
*/
|
*/
|
||||||
]b4_parser_class_declaration[
|
]b4_parser_class_declaration[
|
||||||
{
|
{
|
||||||
]b4_identification[
|
]b4_identification[
|
||||||
]b4_error_verbose_if([[
|
][
|
||||||
|
]b4_parse_error_bmatch(
|
||||||
|
[detailed\|verbose], [[
|
||||||
/**
|
/**
|
||||||
* True if verbose error messages are enabled.
|
* True if verbose error messages are enabled.
|
||||||
*/
|
*/
|
||||||
@@ -109,9 +111,9 @@ m4_define([b4_define_state],[[
|
|||||||
*/
|
*/
|
||||||
public final void setErrorVerbose(boolean verbose)
|
public final void setErrorVerbose(boolean verbose)
|
||||||
{ yyErrorVerbose = verbose; }
|
{ yyErrorVerbose = verbose; }
|
||||||
]])
|
]])[
|
||||||
|
|
||||||
b4_locations_if([[
|
]b4_locations_if([[
|
||||||
/**
|
/**
|
||||||
* A class defining a pair of positions. Positions, defined by the
|
* A class defining a pair of positions. Positions, defined by the
|
||||||
* <code>]b4_position_type[</code> class, denote a point in the input.
|
* <code>]b4_position_type[</code> class, denote a point in the input.
|
||||||
@@ -161,9 +163,6 @@ b4_locations_if([[
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
]])[
|
|
||||||
|
|
||||||
]b4_locations_if([[
|
|
||||||
private ]b4_location_type[ yylloc (YYStack rhs, int n)
|
private ]b4_location_type[ yylloc (YYStack rhs, int n)
|
||||||
{
|
{
|
||||||
if (0 < n)
|
if (0 < n)
|
||||||
@@ -172,17 +171,19 @@ b4_locations_if([[
|
|||||||
return new ]b4_location_type[ (rhs.locationAt (0).end);
|
return new ]b4_location_type[ (rhs.locationAt (0).end);
|
||||||
}]])[
|
}]])[
|
||||||
|
|
||||||
|
]b4_declare_symbol_enum[
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Communication interface between the scanner and the Bison-generated
|
* Communication interface between the scanner and the Bison-generated
|
||||||
* parser <tt>]b4_parser_class[</tt>.
|
* parser <tt>]b4_parser_class[</tt>.
|
||||||
*/
|
*/
|
||||||
public interface Lexer {
|
public interface Lexer {
|
||||||
/** Token returned by the scanner to signal the end of its input. */
|
|
||||||
public static final int EOF = 0;
|
|
||||||
|
|
||||||
]b4_token_enums[
|
]b4_token_enums[
|
||||||
|
/** Deprecated, use b4_symbol(0, id) instead. */
|
||||||
|
public static final int EOF = ]b4_symbol(0, id)[;
|
||||||
|
|
||||||
]b4_locations_if([[/**
|
]b4_locations_if([[
|
||||||
|
/**
|
||||||
* Method to retrieve the beginning position of the last scanned token.
|
* Method to retrieve the beginning position of the last scanned token.
|
||||||
* @@return the position at which the last scanned token starts.
|
* @@return the position at which the last scanned token starts.
|
||||||
*/
|
*/
|
||||||
@@ -217,6 +218,14 @@ b4_locations_if([[
|
|||||||
* @@param msg The string for the error message.
|
* @@param msg The string for the error message.
|
||||||
*/
|
*/
|
||||||
void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String msg);
|
void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String msg);
|
||||||
|
|
||||||
|
]b4_parse_error_bmatch(
|
||||||
|
[custom], [[
|
||||||
|
/**
|
||||||
|
* Build and emit a syntax error message.
|
||||||
|
*/
|
||||||
|
void reportSyntaxError (][Context yyctx);
|
||||||
|
]])[
|
||||||
}
|
}
|
||||||
|
|
||||||
]b4_lexer_if([[
|
]b4_lexer_if([[
|
||||||
@@ -239,7 +248,7 @@ b4_locations_if([[
|
|||||||
public ]b4_parser_class (b4_parse_param_decl([b4_lex_param_decl])[)]b4_maybe_throws([b4_init_throws])[
|
public ]b4_parser_class (b4_parse_param_decl([b4_lex_param_decl])[)]b4_maybe_throws([b4_init_throws])[
|
||||||
{
|
{
|
||||||
]b4_percent_code_get([[init]])[
|
]b4_percent_code_get([[init]])[
|
||||||
this.yylexer = new YYLexer(]b4_lex_param_call[);
|
this.yylexer = new YYLexer (]b4_lex_param_call[);
|
||||||
]b4_parse_param_cons[
|
]b4_parse_param_cons[
|
||||||
}
|
}
|
||||||
]])[
|
]])[
|
||||||
@@ -267,7 +276,7 @@ b4_locations_if([[
|
|||||||
* Set the <tt>PrintStream</tt> on which the debug output is printed.
|
* Set the <tt>PrintStream</tt> on which the debug output is printed.
|
||||||
* @@param s The stream that is used for debugging output.
|
* @@param s The stream that is used for debugging output.
|
||||||
*/
|
*/
|
||||||
public final void setDebugStream(java.io.PrintStream s) { yyDebugStream = s; }
|
public final void setDebugStream (java.io.PrintStream s) { yyDebugStream = s; }
|
||||||
|
|
||||||
private int yydebug = 0;
|
private int yydebug = 0;
|
||||||
|
|
||||||
@@ -275,16 +284,23 @@ b4_locations_if([[
|
|||||||
* Answer the verbosity of the debugging output; 0 means that all kinds of
|
* Answer the verbosity of the debugging output; 0 means that all kinds of
|
||||||
* output from the parser are suppressed.
|
* output from the parser are suppressed.
|
||||||
*/
|
*/
|
||||||
public final int getDebugLevel() { return yydebug; }
|
public final int getDebugLevel () { return yydebug; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the verbosity of the debugging output; 0 means that all kinds of
|
* Set the verbosity of the debugging output; 0 means that all kinds of
|
||||||
* output from the parser are suppressed.
|
* output from the parser are suppressed.
|
||||||
* @@param level The verbosity level for debugging output.
|
* @@param level The verbosity level for debugging output.
|
||||||
*/
|
*/
|
||||||
public final void setDebugLevel(int level) { yydebug = level; }
|
public final void setDebugLevel (int level) { yydebug = level; }
|
||||||
]])[
|
]])[
|
||||||
|
|
||||||
|
private int yynerrs = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of syntax errors so far.
|
||||||
|
*/
|
||||||
|
public final int getNumberOfErrors () { return yynerrs; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print an error message via the lexer.
|
* Print an error message via the lexer.
|
||||||
*]b4_locations_if([[ Use a <code>null</code> location.]])[
|
*]b4_locations_if([[ Use a <code>null</code> location.]])[
|
||||||
@@ -328,8 +344,7 @@ b4_locations_if([[
|
|||||||
public int size = 16;
|
public int size = 16;
|
||||||
public int height = -1;
|
public int height = -1;
|
||||||
|
|
||||||
public final void push (int state, ]b4_yystype[ value]dnl
|
public final void push (int state, ]b4_yystype[ value]b4_locations_if([, ]b4_location_type[ loc])[) {
|
||||||
b4_locations_if([, ]b4_location_type[ loc])[) {
|
|
||||||
height++;
|
height++;
|
||||||
if (size == height)
|
if (size == height)
|
||||||
{
|
{
|
||||||
@@ -373,8 +388,8 @@ b4_locations_if([[
|
|||||||
public final ]b4_location_type[ locationAt (int i) {
|
public final ]b4_location_type[ locationAt (int i) {
|
||||||
return locStack[height - i];
|
return locStack[height - i];
|
||||||
}
|
}
|
||||||
|
]])[
|
||||||
]])[public final ]b4_yystype[ valueAt (int i) {
|
public final ]b4_yystype[ valueAt (int i) {
|
||||||
return valueStack[height - i];
|
return valueStack[height - i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -446,11 +461,11 @@ b4_locations_if([[
|
|||||||
*/
|
*/
|
||||||
private int yyLRGotoState (int yystate, int yysym)
|
private int yyLRGotoState (int yystate, int yysym)
|
||||||
{
|
{
|
||||||
int yyr = yypgoto_[yysym - yyntokens_] + yystate;
|
int yyr = yypgoto_[yysym - YYNTOKENS_] + yystate;
|
||||||
if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate)
|
if (0 <= yyr && yyr <= YYLAST_ && yycheck_[yyr] == yystate)
|
||||||
return yytable_[yyr];
|
return yytable_[yyr];
|
||||||
else
|
else
|
||||||
return yydefgoto_[yysym - yyntokens_];
|
return yydefgoto_[yysym - YYNTOKENS_];
|
||||||
}
|
}
|
||||||
|
|
||||||
private int yyaction (int yyn, YYStack yystack, int yylen)]b4_maybe_throws([b4_throws])[
|
private int yyaction (int yyn, YYStack yystack, int yylen)]b4_maybe_throws([b4_throws])[
|
||||||
@@ -472,66 +487,29 @@ b4_locations_if([[
|
|||||||
default: break;
|
default: break;
|
||||||
}]b4_parse_trace_if([[
|
}]b4_parse_trace_if([[
|
||||||
|
|
||||||
yySymbolPrint ("-> $$ =", yyr1_[yyn], yyval]b4_locations_if([, yyloc])[);]])[
|
yySymbolPrint ("-> $$ =", SymbolKind.get (yyr1_[yyn]), yyval]b4_locations_if([, yyloc])[);]])[
|
||||||
|
|
||||||
yystack.pop (yylen);
|
yystack.pop (yylen);
|
||||||
yylen = 0;
|
yylen = 0;
|
||||||
|
|
||||||
/* Shift the result of the reduction. */
|
/* Shift the result of the reduction. */
|
||||||
int yystate = yyLRGotoState (yystack.stateAt (0), yyr1_[yyn]);
|
int yystate = yyLRGotoState (yystack.stateAt (0), yyr1_[yyn]);
|
||||||
yystack.push (yystate, yyval]b4_locations_if([, yyloc])[);
|
yystack.push (yystate, yyval]b4_locations_if([, yyloc])[);
|
||||||
return YYNEWSTATE;
|
return YYNEWSTATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
]b4_error_verbose_if([[
|
|
||||||
/* Return YYSTR after stripping away unnecessary quotes and
|
|
||||||
backslashes, so that it's suitable for yyerror. The heuristic is
|
|
||||||
that double-quoting is unnecessary unless the string contains an
|
|
||||||
apostrophe, a comma, or backslash (other than backslash-backslash).
|
|
||||||
YYSTR is taken from yytname. */
|
|
||||||
private final String yytnamerr_ (String yystr)
|
|
||||||
{
|
|
||||||
if (yystr.charAt (0) == '"')
|
|
||||||
{
|
|
||||||
StringBuffer yyr = new StringBuffer ();
|
|
||||||
strip_quotes: for (int i = 1; i < yystr.length (); i++)
|
|
||||||
switch (yystr.charAt (i))
|
|
||||||
{
|
|
||||||
case '\'':
|
|
||||||
case ',':
|
|
||||||
break strip_quotes;
|
|
||||||
|
|
||||||
case '\\':
|
|
||||||
if (yystr.charAt(++i) != '\\')
|
|
||||||
break strip_quotes;
|
|
||||||
/* Fall through. */
|
|
||||||
default:
|
|
||||||
yyr.append (yystr.charAt (i));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '"':
|
|
||||||
return yyr.toString ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (yystr.equals ("$end"))
|
|
||||||
return "end of input";
|
|
||||||
|
|
||||||
return yystr;
|
|
||||||
}
|
|
||||||
]])[
|
|
||||||
]b4_parse_trace_if([[
|
]b4_parse_trace_if([[
|
||||||
/*--------------------------------.
|
/*--------------------------------.
|
||||||
| Print this symbol on YYOUTPUT. |
|
| Print this symbol on YYOUTPUT. |
|
||||||
`--------------------------------*/
|
`--------------------------------*/
|
||||||
|
|
||||||
private void yySymbolPrint (String s, int yytype,
|
private void yySymbolPrint(String s, SymbolKind yykind,
|
||||||
]b4_yystype[ yyvaluep]dnl
|
]b4_yystype[ yyvalue]b4_locations_if([, ]b4_location_type[ yylocation])[)
|
||||||
b4_locations_if([, Object yylocationp])[)
|
|
||||||
{
|
{
|
||||||
yycdebug (s + (yytype < yyntokens_ ? " token " : " nterm ")
|
yycdebug (s
|
||||||
+ yytname_[yytype] + " ("]b4_locations_if([
|
+ (yykind.getCode() < YYNTOKENS_ ? " token " : " nterm ")
|
||||||
+ yylocationp + ": "])[
|
+ yykind.getName() + " ("]b4_locations_if([
|
||||||
+ (yyvaluep == null ? "(null)" : yyvaluep.toString ()) + ")");
|
+ yylocation + ": "])[
|
||||||
|
+ (yyvalue == null ? "(null)" : yyvalue.toString()) + ")");
|
||||||
}]])[
|
}]])[
|
||||||
|
|
||||||
]b4_push_if([],[[
|
]b4_push_if([],[[
|
||||||
@@ -559,8 +537,9 @@ b4_locations_if([[
|
|||||||
]b4_location_type[ yyloc;]])[
|
]b4_location_type[ yyloc;]])[
|
||||||
]b4_push_if([],[[
|
]b4_push_if([],[[
|
||||||
]b4_define_state[]b4_parse_trace_if([[
|
]b4_define_state[]b4_parse_trace_if([[
|
||||||
yycdebug ("Starting parse\n");]])[
|
yycdebug ("Starting parse");]])[
|
||||||
yyerrstatus_ = 0;
|
yyerrstatus_ = 0;
|
||||||
|
yynerrs = 0;
|
||||||
|
|
||||||
/* Initialize the stack. */
|
/* Initialize the stack. */
|
||||||
yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
|
yystack.push (yystate, yylval]b4_locations_if([, yylloc])[);
|
||||||
@@ -579,7 +558,7 @@ b4_dollar_pushdef([yylval], [], [], [yylloc])dnl
|
|||||||
b4_user_initial_action
|
b4_user_initial_action
|
||||||
b4_dollar_popdef[]dnl
|
b4_dollar_popdef[]dnl
|
||||||
])[]b4_parse_trace_if([[
|
])[]b4_parse_trace_if([[
|
||||||
yycdebug ("Starting parse\n");]])[
|
yycdebug ("Starting parse");]])[
|
||||||
yyerrstatus_ = 0;
|
yyerrstatus_ = 0;
|
||||||
} else
|
} else
|
||||||
label = YYGETTOKEN;
|
label = YYGETTOKEN;
|
||||||
@@ -592,12 +571,12 @@ b4_dollar_popdef[]dnl
|
|||||||
/* New state. Unlike in the C/C++ skeletons, the state is already
|
/* New state. Unlike in the C/C++ skeletons, the state is already
|
||||||
pushed when we come here. */
|
pushed when we come here. */
|
||||||
case YYNEWSTATE:]b4_parse_trace_if([[
|
case YYNEWSTATE:]b4_parse_trace_if([[
|
||||||
yycdebug ("Entering state " + yystate + "\n");
|
yycdebug ("Entering state " + yystate);
|
||||||
if (0 < yydebug)
|
if (0 < yydebug)
|
||||||
yystack.print (yyDebugStream);]])[
|
yystack.print (yyDebugStream);]])[
|
||||||
|
|
||||||
/* Accept? */
|
/* Accept? */
|
||||||
if (yystate == yyfinal_)
|
if (yystate == YYFINAL_)
|
||||||
]b4_push_if([{label = YYACCEPT; break;}],
|
]b4_push_if([{label = YYACCEPT; break;}],
|
||||||
[return true;])[
|
[return true;])[
|
||||||
|
|
||||||
@@ -612,17 +591,17 @@ b4_dollar_popdef[]dnl
|
|||||||
|
|
||||||
case YYGETTOKEN:])[
|
case YYGETTOKEN:])[
|
||||||
/* Read a lookahead token. */
|
/* Read a lookahead token. */
|
||||||
if (yychar == yyempty_)
|
if (yychar == YYEMPTY_)
|
||||||
{
|
{
|
||||||
]b4_push_if([[
|
]b4_push_if([[
|
||||||
if (!push_token_consumed)
|
if (!push_token_consumed)
|
||||||
return YYPUSH_MORE;]b4_parse_trace_if([[
|
return YYPUSH_MORE;]b4_parse_trace_if([[
|
||||||
yycdebug ("Reading a token: ");]])[
|
yycdebug ("Reading a token");]])[
|
||||||
yychar = yylextoken;
|
yychar = yylextoken;
|
||||||
yylval = yylexval;]b4_locations_if([
|
yylval = yylexval;]b4_locations_if([
|
||||||
yylloc = yylexloc;])[
|
yylloc = yylexloc;])[
|
||||||
push_token_consumed = false;]], [b4_parse_trace_if([[
|
push_token_consumed = false;]], [b4_parse_trace_if([[
|
||||||
yycdebug ("Reading a token: ");]])[
|
yycdebug ("Reading a token");]])[
|
||||||
yychar = yylexer.yylex ();
|
yychar = yylexer.yylex ();
|
||||||
yylval = yylexer.getLVal ();]b4_locations_if([
|
yylval = yylexer.getLVal ();]b4_locations_if([
|
||||||
yylloc = new b4_location_type (yylexer.getStartPos (),
|
yylloc = new b4_location_type (yylexer.getStartPos (),
|
||||||
@@ -637,8 +616,8 @@ b4_dollar_popdef[]dnl
|
|||||||
|
|
||||||
/* If the proper action on seeing token YYTOKEN is to reduce or to
|
/* If the proper action on seeing token YYTOKEN is to reduce or to
|
||||||
detect an error, take that action. */
|
detect an error, take that action. */
|
||||||
yyn += yytoken;
|
yyn += yytoken.getCode ();
|
||||||
if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken)
|
if (yyn < 0 || YYLAST_ < yyn || yycheck_[yyn] != yytoken.getCode ())
|
||||||
label = YYDEFAULT;
|
label = YYDEFAULT;
|
||||||
|
|
||||||
/* <= 0 means reduce or error. */
|
/* <= 0 means reduce or error. */
|
||||||
@@ -660,7 +639,7 @@ b4_dollar_popdef[]dnl
|
|||||||
yylval]b4_locations_if([, yylloc])[);
|
yylval]b4_locations_if([, yylloc])[);
|
||||||
]])[
|
]])[
|
||||||
/* Discard the token being shifted. */
|
/* Discard the token being shifted. */
|
||||||
yychar = yyempty_;
|
yychar = YYEMPTY_;
|
||||||
|
|
||||||
/* Count tokens shifted since error; after three, turn off error
|
/* Count tokens shifted since error; after three, turn off error
|
||||||
status. */
|
status. */
|
||||||
@@ -700,10 +679,10 @@ b4_dollar_popdef[]dnl
|
|||||||
/* If not already recovering from an error, report this error. */
|
/* If not already recovering from an error, report this error. */
|
||||||
if (yyerrstatus_ == 0)
|
if (yyerrstatus_ == 0)
|
||||||
{
|
{
|
||||||
++yynerrs_;
|
++yynerrs;
|
||||||
if (yychar == yyempty_)
|
if (yychar == YYEMPTY_)
|
||||||
yytoken = yyempty_;
|
yytoken = null;
|
||||||
yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken));
|
yyreportSyntaxError (new Context (yystack, yytoken]b4_locations_if([[, yylloc]])[));
|
||||||
}
|
}
|
||||||
|
|
||||||
]b4_locations_if([[
|
]b4_locations_if([[
|
||||||
@@ -713,14 +692,14 @@ b4_dollar_popdef[]dnl
|
|||||||
/* If just tried and failed to reuse lookahead token after an
|
/* If just tried and failed to reuse lookahead token after an
|
||||||
error, discard it. */
|
error, discard it. */
|
||||||
|
|
||||||
if (yychar <= Lexer.EOF)
|
if (yychar <= Lexer.]b4_symbol(0, id)[)
|
||||||
{
|
{
|
||||||
/* Return failure if at end of input. */
|
/* Return failure if at end of input. */
|
||||||
if (yychar == Lexer.EOF)
|
if (yychar == Lexer.]b4_symbol(0, id)[)
|
||||||
]b4_push_if([{label = YYABORT; break;}], [return false;])[
|
]b4_push_if([{label = YYABORT; break;}], [return false;])[
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
yychar = yyempty_;
|
yychar = YYEMPTY_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Else will try to reuse lookahead token after shifting the error
|
/* Else will try to reuse lookahead token after shifting the error
|
||||||
@@ -747,13 +726,15 @@ b4_dollar_popdef[]dnl
|
|||||||
case YYERRLAB1:
|
case YYERRLAB1:
|
||||||
yyerrstatus_ = 3; /* Each real token shifted decrements this. */
|
yyerrstatus_ = 3; /* Each real token shifted decrements this. */
|
||||||
|
|
||||||
|
// Pop stack until we find a state that shifts the error token.
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
yyn = yypact_[yystate];
|
yyn = yypact_[yystate];
|
||||||
if (!yyPactValueIsDefault (yyn))
|
if (!yyPactValueIsDefault (yyn))
|
||||||
{
|
{
|
||||||
yyn += yy_error_token_;
|
yyn += SymbolKind.]b4_symbol_prefix[YYERROR.getCode ();
|
||||||
if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yy_error_token_)
|
if (0 <= yyn && yyn <= YYLAST_
|
||||||
|
&& yycheck_[yyn] == SymbolKind.]b4_symbol_prefix[YYERROR.getCode ())
|
||||||
{
|
{
|
||||||
yyn = yytable_[yyn];
|
yyn = yytable_[yyn];
|
||||||
if (0 < yyn)
|
if (0 < yyn)
|
||||||
@@ -775,8 +756,8 @@ b4_dollar_popdef[]dnl
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (label == YYABORT)
|
if (label == YYABORT)
|
||||||
/* Leave the switch. */
|
/* Leave the switch. */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
]b4_locations_if([[
|
]b4_locations_if([[
|
||||||
/* Muck with the stack to setup for yylloc. */
|
/* Muck with the stack to setup for yylloc. */
|
||||||
@@ -786,7 +767,7 @@ b4_dollar_popdef[]dnl
|
|||||||
yystack.pop (2);]])[
|
yystack.pop (2);]])[
|
||||||
|
|
||||||
/* Shift the error token. */]b4_parse_trace_if([[
|
/* Shift the error token. */]b4_parse_trace_if([[
|
||||||
yySymbolPrint ("Shifting", yystos_[yyn],
|
yySymbolPrint ("Shifting", SymbolKind.get (yystos_[yyn]),
|
||||||
yylval]b4_locations_if([, yyloc])[);]])[
|
yylval]b4_locations_if([, yyloc])[);]])[
|
||||||
|
|
||||||
yystate = yyn;
|
yystate = yyn;
|
||||||
@@ -811,11 +792,11 @@ b4_dollar_popdef[]dnl
|
|||||||
/**
|
/**
|
||||||
* (Re-)Initialize the state of the push parser.
|
* (Re-)Initialize the state of the push parser.
|
||||||
*/
|
*/
|
||||||
public void push_parse_initialize()
|
public void push_parse_initialize ()
|
||||||
{
|
{
|
||||||
/* Lookahead and lookahead in internal form. */
|
/* Lookahead and lookahead in internal form. */
|
||||||
this.yychar = yyempty_;
|
this.yychar = YYEMPTY_;
|
||||||
this.yytoken = 0;
|
this.yytoken = null;
|
||||||
|
|
||||||
/* State. */
|
/* State. */
|
||||||
this.yyn = 0;
|
this.yyn = 0;
|
||||||
@@ -825,7 +806,7 @@ b4_dollar_popdef[]dnl
|
|||||||
this.label = YYNEWSTATE;
|
this.label = YYNEWSTATE;
|
||||||
|
|
||||||
/* Error handling. */
|
/* Error handling. */
|
||||||
this.yynerrs_ = 0;]b4_locations_if([[
|
this.yynerrs = 0;]b4_locations_if([[
|
||||||
/* The location where the error started. */
|
/* The location where the error started. */
|
||||||
this.yyerrloc = null;
|
this.yyerrloc = null;
|
||||||
this.yylloc = new ]b4_location_type[ (null, null);]])[
|
this.yylloc = new ]b4_location_type[ (null, null);]])[
|
||||||
@@ -881,77 +862,159 @@ b4_dollar_popdef[]dnl
|
|||||||
}
|
}
|
||||||
]])[
|
]])[
|
||||||
|
|
||||||
// Generate an error message.
|
/**
|
||||||
private String yysyntax_error (int yystate, int tok)
|
* Information needed to get the list of expected tokens and to forge
|
||||||
{]b4_error_verbose_if([[
|
* a syntax error diagnostic.
|
||||||
|
*/
|
||||||
|
public static final class Context
|
||||||
|
{
|
||||||
|
Context (YYStack stack, SymbolKind token]b4_locations_if([[, ]b4_location_type[ loc]])[)
|
||||||
|
{
|
||||||
|
yystack = stack;
|
||||||
|
yytoken = token;]b4_locations_if([[
|
||||||
|
yylocation = loc;]])[
|
||||||
|
}
|
||||||
|
|
||||||
|
private YYStack yystack;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The symbol kind of the lookahead token.
|
||||||
|
*/
|
||||||
|
public final SymbolKind getToken ()
|
||||||
|
{
|
||||||
|
return yytoken;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SymbolKind yytoken;]b4_locations_if([[
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The location of the lookahead.
|
||||||
|
*/
|
||||||
|
public final ]b4_location_type[ getLocation ()
|
||||||
|
{
|
||||||
|
return yylocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ]b4_location_type[ yylocation;]])[
|
||||||
|
static final int NTOKENS = ]b4_parser_class[.YYNTOKENS_;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put in YYARG at most YYARGN of the expected tokens given the
|
||||||
|
* current YYCTX, and return the number of tokens stored in YYARG. If
|
||||||
|
* YYARG is null, return the number of expected tokens (guaranteed to
|
||||||
|
* be less than YYNTOKENS).
|
||||||
|
*/
|
||||||
|
int getExpectedTokens (SymbolKind yyarg[], int yyargn)
|
||||||
|
{
|
||||||
|
return getExpectedTokens (yyarg, 0, yyargn);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getExpectedTokens (SymbolKind yyarg[], int yyoffset, int yyargn)
|
||||||
|
{
|
||||||
|
int yycount = yyoffset;
|
||||||
|
int yyn = yypact_[this.yystack.stateAt (0)];
|
||||||
|
if (!yyPactValueIsDefault (yyn))
|
||||||
|
{
|
||||||
|
/* Start YYX at -YYN if negative to avoid negative
|
||||||
|
indexes in YYCHECK. In other words, skip the first
|
||||||
|
-YYN actions for this state because they are default
|
||||||
|
actions. */
|
||||||
|
int yyxbegin = yyn < 0 ? -yyn : 0;
|
||||||
|
/* Stay within bounds of both yycheck and yytname. */
|
||||||
|
int yychecklim = YYLAST_ - yyn + 1;
|
||||||
|
int yyxend = yychecklim < NTOKENS ? yychecklim : NTOKENS;
|
||||||
|
for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
|
||||||
|
if (yycheck_[yyx + yyn] == yyx && yyx != SymbolKind.]b4_symbol_prefix[YYERROR.getCode ()
|
||||||
|
&& !yyTableValueIsError (yytable_[yyx + yyn]))
|
||||||
|
{
|
||||||
|
if (yyarg == null)
|
||||||
|
yycount += 1;
|
||||||
|
else if (yycount == yyargn)
|
||||||
|
return 0; // FIXME: this is incorrect.
|
||||||
|
else
|
||||||
|
yyarg[yycount++] = SymbolKind.get (yyx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return yycount - yyoffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
]b4_parse_error_bmatch(
|
||||||
|
[detailed\|verbose], [[
|
||||||
|
private int yysyntaxErrorArguments (Context yyctx, SymbolKind[] yyarg, int yyargn)
|
||||||
|
{
|
||||||
|
/* There are many possibilities here to consider:
|
||||||
|
- If this state is a consistent state with a default action,
|
||||||
|
then the only way this function was invoked is if the
|
||||||
|
default action is an error action. In that case, don't
|
||||||
|
check for expected tokens because there are none.
|
||||||
|
- The only way there can be no lookahead present (in tok) is
|
||||||
|
if this state is a consistent state with a default action.
|
||||||
|
Thus, detecting the absence of a lookahead is sufficient to
|
||||||
|
determine that there is no unexpected or expected token to
|
||||||
|
report. In that case, just report a simple "syntax error".
|
||||||
|
- Don't assume there isn't a lookahead just because this
|
||||||
|
state is a consistent state with a default action. There
|
||||||
|
might have been a previous inconsistent state, consistent
|
||||||
|
state with a non-default action, or user semantic action
|
||||||
|
that manipulated yychar. (However, yychar is currently out
|
||||||
|
of scope during semantic actions.)
|
||||||
|
- Of course, the expected token list depends on states to
|
||||||
|
have correct lookahead information, and it depends on the
|
||||||
|
parser not to perform extra reductions after fetching a
|
||||||
|
lookahead from the scanner and before detecting a syntax
|
||||||
|
error. Thus, state merging (from LALR or IELR) and default
|
||||||
|
reductions corrupt the expected token list. However, the
|
||||||
|
list is correct for canonical LR with one exception: it
|
||||||
|
will still contain any token that will not be accepted due
|
||||||
|
to an error action in a later state.
|
||||||
|
*/
|
||||||
|
int yycount = 0;
|
||||||
|
if (yyctx.getToken () != null)
|
||||||
|
{
|
||||||
|
if (yyarg != null)
|
||||||
|
yyarg[yycount] = yyctx.getToken ();
|
||||||
|
yycount += 1;
|
||||||
|
yycount += yyctx.getExpectedTokens (yyarg, 1, yyargn);
|
||||||
|
}
|
||||||
|
return yycount;
|
||||||
|
}
|
||||||
|
]])[
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report a syntax error.
|
||||||
|
*/
|
||||||
|
private void yyreportSyntaxError (Context yyctx)
|
||||||
|
{]b4_parse_error_bmatch(
|
||||||
|
[custom], [[
|
||||||
|
yylexer.reportSyntaxError (yyctx);]],
|
||||||
|
[detailed\|verbose], [[
|
||||||
if (yyErrorVerbose)
|
if (yyErrorVerbose)
|
||||||
{
|
{
|
||||||
/* There are many possibilities here to consider:
|
final int argmax = 5;
|
||||||
- If this state is a consistent state with a default action,
|
SymbolKind[] yyarg = new SymbolKind[argmax];
|
||||||
then the only way this function was invoked is if the
|
int yycount = yysyntaxErrorArguments (yyctx, yyarg, argmax);
|
||||||
default action is an error action. In that case, don't
|
String[] yystr = new String[yycount];
|
||||||
check for expected tokens because there are none.
|
for (int yyi = 0; yyi < yycount; ++yyi)
|
||||||
- The only way there can be no lookahead present (in tok) is
|
yystr[yyi] = yyarg[yyi].getName();
|
||||||
if this state is a consistent state with a default action.
|
String yyformat;
|
||||||
Thus, detecting the absence of a lookahead is sufficient to
|
switch (yycount)
|
||||||
determine that there is no unexpected or expected token to
|
|
||||||
report. In that case, just report a simple "syntax error".
|
|
||||||
- Don't assume there isn't a lookahead just because this
|
|
||||||
state is a consistent state with a default action. There
|
|
||||||
might have been a previous inconsistent state, consistent
|
|
||||||
state with a non-default action, or user semantic action
|
|
||||||
that manipulated yychar. (However, yychar is currently out
|
|
||||||
of scope during semantic actions.)
|
|
||||||
- Of course, the expected token list depends on states to
|
|
||||||
have correct lookahead information, and it depends on the
|
|
||||||
parser not to perform extra reductions after fetching a
|
|
||||||
lookahead from the scanner and before detecting a syntax
|
|
||||||
error. Thus, state merging (from LALR or IELR) and default
|
|
||||||
reductions corrupt the expected token list. However, the
|
|
||||||
list is correct for canonical LR with one exception: it
|
|
||||||
will still contain any token that will not be accepted due
|
|
||||||
to an error action in a later state.
|
|
||||||
*/
|
|
||||||
if (tok != yyempty_)
|
|
||||||
{
|
{
|
||||||
/* FIXME: This method of building the message is not compatible
|
default:
|
||||||
with internationalization. */
|
case 0: yyformat = ]b4_trans(["syntax error"])[; break;
|
||||||
StringBuffer res =
|
case 1: yyformat = ]b4_trans(["syntax error, unexpected {0}"])[; break;
|
||||||
new StringBuffer ("syntax error, unexpected ");
|
case 2: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1}"])[; break;
|
||||||
res.append (yytnamerr_ (yytname_[tok]));
|
case 3: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2}"])[; break;
|
||||||
int yyn = yypact_[yystate];
|
case 4: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2} or {3}"])[; break;
|
||||||
if (!yyPactValueIsDefault (yyn))
|
case 5: yyformat = ]b4_trans(["syntax error, unexpected {0}, expecting {1} or {2} or {3} or {4}"])[; break;
|
||||||
{
|
|
||||||
/* Start YYX at -YYN if negative to avoid negative
|
|
||||||
indexes in YYCHECK. In other words, skip the first
|
|
||||||
-YYN actions for this state because they are default
|
|
||||||
actions. */
|
|
||||||
int yyxbegin = yyn < 0 ? -yyn : 0;
|
|
||||||
/* Stay within bounds of both yycheck and yytname. */
|
|
||||||
int yychecklim = yylast_ - yyn + 1;
|
|
||||||
int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
|
|
||||||
int count = 0;
|
|
||||||
for (int x = yyxbegin; x < yyxend; ++x)
|
|
||||||
if (yycheck_[x + yyn] == x && x != yy_error_token_
|
|
||||||
&& !yyTableValueIsError (yytable_[x + yyn]))
|
|
||||||
++count;
|
|
||||||
if (count < 5)
|
|
||||||
{
|
|
||||||
count = 0;
|
|
||||||
for (int x = yyxbegin; x < yyxend; ++x)
|
|
||||||
if (yycheck_[x + yyn] == x && x != yy_error_token_
|
|
||||||
&& !yyTableValueIsError (yytable_[x + yyn]))
|
|
||||||
{
|
|
||||||
res.append (count++ == 0 ? ", expecting " : " or ");
|
|
||||||
res.append (yytnamerr_ (yytname_[x]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res.toString ();
|
|
||||||
}
|
}
|
||||||
|
yyerror (]b4_locations_if([[yyctx.yylocation, ]])[new MessageFormat (yyformat).format (yystr));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
]])[
|
yyerror (]b4_locations_if([[yyctx.yylocation, ]])["syntax error");]],
|
||||||
return "syntax error";
|
[simple], [[
|
||||||
|
yyerror (]b4_locations_if([[yyctx.yylocation, ]])["syntax error");]])[
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -976,11 +1039,7 @@ b4_dollar_popdef[]dnl
|
|||||||
private static final ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[;
|
private static final ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[;
|
||||||
private static final ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[;
|
private static final ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[;
|
||||||
|
|
||||||
]b4_parser_tables_define[
|
]b4_parser_tables_define[
|
||||||
|
|
||||||
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
|
|
||||||
First, the terminals, then, starting at \a yyntokens_, nonterminals. */
|
|
||||||
]b4_typed_parser_table_define([String], [tname], [b4_tname])[
|
|
||||||
|
|
||||||
]b4_parse_trace_if([[
|
]b4_parse_trace_if([[
|
||||||
]b4_integral_parser_table_define([rline], [b4_rline],
|
]b4_integral_parser_table_define([rline], [b4_rline],
|
||||||
@@ -997,50 +1056,43 @@ b4_dollar_popdef[]dnl
|
|||||||
int yynrhs = yyr2_[yyrule];
|
int yynrhs = yyr2_[yyrule];
|
||||||
/* Print the symbols being reduced, and their result. */
|
/* Print the symbols being reduced, and their result. */
|
||||||
yycdebug ("Reducing stack by rule " + (yyrule - 1)
|
yycdebug ("Reducing stack by rule " + (yyrule - 1)
|
||||||
+ " (line " + yylno + "), ");
|
+ " (line " + yylno + "):");
|
||||||
|
|
||||||
/* The symbols being reduced. */
|
/* The symbols being reduced. */
|
||||||
for (int yyi = 0; yyi < yynrhs; yyi++)
|
for (int yyi = 0; yyi < yynrhs; yyi++)
|
||||||
yySymbolPrint (" $" + (yyi + 1) + " =",
|
yySymbolPrint (" $" + (yyi + 1) + " =",
|
||||||
yystos_[yystack.stateAt(yynrhs - (yyi + 1))],
|
SymbolKind.get (yystos_[yystack.stateAt (yynrhs - (yyi + 1))]),
|
||||||
]b4_rhs_data(yynrhs, yyi + 1)b4_locations_if([,
|
]b4_rhs_data(yynrhs, yyi + 1)b4_locations_if([,
|
||||||
b4_rhs_location(yynrhs, yyi + 1)])[);
|
b4_rhs_location(yynrhs, yyi + 1)])[);
|
||||||
}]])[
|
}]])[
|
||||||
|
|
||||||
/* YYTRANSLATE_(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
|
/* YYTRANSLATE_(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
|
||||||
as returned by yylex, with out-of-bounds checking. */
|
as returned by yylex, with out-of-bounds checking. */
|
||||||
private static final ]b4_int_type_for([b4_translate])[ yytranslate_ (int t)
|
private static final SymbolKind yytranslate_ (int t)
|
||||||
]b4_api_token_raw_if(dnl
|
]b4_api_token_raw_if(dnl
|
||||||
[[ {
|
[[ {
|
||||||
return t;
|
return SymbolKind.get (t);
|
||||||
}
|
}
|
||||||
]],
|
]],
|
||||||
[[ {
|
[[ {
|
||||||
int user_token_number_max_ = ]b4_user_token_number_max[;
|
int user_token_number_max_ = ]b4_user_token_number_max[;
|
||||||
]b4_int_type_for([b4_translate])[ undef_token_ = ]b4_undef_token_number[;
|
|
||||||
|
|
||||||
if (t <= 0)
|
if (t <= 0)
|
||||||
return Lexer.EOF;
|
return SymbolKind.]b4_symbol_prefix[YYEOF;
|
||||||
else if (t <= user_token_number_max_)
|
else if (t <= user_token_number_max_)
|
||||||
return yytranslate_table_[t];
|
return SymbolKind.get (yytranslate_table_[t]);
|
||||||
else
|
else
|
||||||
return undef_token_;
|
return SymbolKind.]b4_symbol_prefix[YYUNDEF;
|
||||||
}
|
}
|
||||||
]b4_integral_parser_table_define([translate_table], [b4_translate])[
|
]b4_integral_parser_table_define([translate_table], [b4_translate])[
|
||||||
]])[
|
]])[
|
||||||
|
|
||||||
private static final ]b4_int_type_for([b4_translate])[ yy_error_token_ = 1;
|
private static final int YYLAST_ = ]b4_last[;
|
||||||
|
private static final int YYEMPTY_ = -2;
|
||||||
private static final int yylast_ = ]b4_last[;
|
private static final int YYFINAL_ = ]b4_final_state_number[;
|
||||||
private static final int yynnts_ = ]b4_nterms_number[;
|
private static final int YYNTOKENS_ = ]b4_tokens_number[;
|
||||||
private static final int yyempty_ = -2;
|
|
||||||
private static final int yyfinal_ = ]b4_final_state_number[;
|
|
||||||
private static final int yyntokens_ = ]b4_tokens_number[;
|
|
||||||
|
|
||||||
/* User implementation code. */
|
|
||||||
]b4_percent_code_get[]dnl
|
|
||||||
|
|
||||||
|
]b4_percent_code_get[
|
||||||
}
|
}
|
||||||
|
]b4_percent_code_get([[epilogue]])[]dnl
|
||||||
b4_epilogue[]dnl
|
b4_epilogue[]dnl
|
||||||
b4_output_end
|
b4_output_end
|
||||||
|
|||||||
+4
-10
@@ -32,8 +32,8 @@ m4_define([b4_stack_define],
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Hide our reversed order.
|
// Hide our reversed order.
|
||||||
typedef typename S::reverse_iterator iterator;
|
typedef typename S::iterator iterator;
|
||||||
typedef typename S::const_reverse_iterator const_iterator;
|
typedef typename S::const_iterator const_iterator;
|
||||||
typedef typename S::size_type size_type;
|
typedef typename S::size_type size_type;
|
||||||
typedef typename std::ptrdiff_t index_type;
|
typedef typename std::ptrdiff_t index_type;
|
||||||
|
|
||||||
@@ -91,24 +91,18 @@ m4_define([b4_stack_define],
|
|||||||
return index_type (seq_.size ());
|
return index_type (seq_.size ());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ptrdiff_t
|
|
||||||
ssize () const YY_NOEXCEPT
|
|
||||||
{
|
|
||||||
return std::ptrdiff_t (size ());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Iterator on top of the stack (going downwards).
|
/// Iterator on top of the stack (going downwards).
|
||||||
const_iterator
|
const_iterator
|
||||||
begin () const YY_NOEXCEPT
|
begin () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
return seq_.rbegin ();
|
return seq_.begin ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bottom of the stack.
|
/// Bottom of the stack.
|
||||||
const_iterator
|
const_iterator
|
||||||
end () const YY_NOEXCEPT
|
end () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
return seq_.rend ();
|
return seq_.end ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Present a slice of the top of a stack.
|
/// Present a slice of the top of a stack.
|
||||||
|
|||||||
+474
-320
File diff suppressed because it is too large
Load Diff
+1282
-787
File diff suppressed because it is too large
Load Diff
+47
-46
@@ -20,36 +20,36 @@ AM_MAKEINFOFLAGS = \
|
|||||||
--set-customization-variable=AVOID_MENU_REDUNDANCY=true \
|
--set-customization-variable=AVOID_MENU_REDUNDANCY=true \
|
||||||
--set-customization-variable=ICONS=true
|
--set-customization-variable=ICONS=true
|
||||||
|
|
||||||
info_TEXINFOS = doc/bison.texi
|
info_TEXINFOS = %D%/bison.texi
|
||||||
doc_bison_TEXINFOS = \
|
%C%_bison_TEXINFOS = \
|
||||||
$(CROSS_OPTIONS_TEXI) \
|
$(CROSS_OPTIONS_TEXI) \
|
||||||
doc/fdl.texi \
|
%D%/fdl.texi \
|
||||||
doc/gpl-3.0.texi \
|
%D%/gpl-3.0.texi \
|
||||||
doc/relocatable.texi
|
%D%/relocatable.texi
|
||||||
|
|
||||||
# Cannot express dependencies directly on file names because of Automake.
|
# Cannot express dependencies directly on file names because of Automake.
|
||||||
# Obfuscate with a variable.
|
# Obfuscate with a variable.
|
||||||
doc_bison = doc/bison
|
%C%_bison = %D%/bison
|
||||||
$(doc_bison).dvi: $(FIGS_GV:.gv=.eps)
|
$(%C%_bison).dvi: $(FIGS_GV:.gv=.eps)
|
||||||
$(doc_bison).info: $(FIGS_GV:.gv=.txt)
|
$(%C%_bison).info: $(FIGS_GV:.gv=.txt)
|
||||||
$(doc_bison).pdf: $(FIGS_GV:.gv=.pdf)
|
$(%C%_bison).pdf: $(FIGS_GV:.gv=.pdf)
|
||||||
$(doc_bison).html: $(FIGS_GV:.gv=.svg)
|
$(%C%_bison).html: $(FIGS_GV:.gv=.svg)
|
||||||
|
|
||||||
TEXI2DVI = texi2dvi --build-dir=doc/bison.t2d -I doc
|
TEXI2DVI = texi2dvi --build-dir=%D%/bison.t2d -I %D%
|
||||||
CLEANDIRS += doc/bison.t2d
|
CLEANDIRS += %D%/bison.t2d
|
||||||
|
|
||||||
MOSTLYCLEANFILES += $(top_srcdir)/doc/*.tmp
|
MOSTLYCLEANFILES += $(top_srcdir)/%D%/*.tmp
|
||||||
|
|
||||||
CROSS_OPTIONS_PL = $(top_srcdir)/build-aux/cross-options.pl
|
CROSS_OPTIONS_PL = $(top_srcdir)/build-aux/cross-options.pl
|
||||||
CROSS_OPTIONS_TEXI = $(top_srcdir)/doc/cross-options.texi
|
CROSS_OPTIONS_TEXI = $(top_srcdir)/%D%/cross-options.texi
|
||||||
$(CROSS_OPTIONS_TEXI): doc/bison.help $(CROSS_OPTIONS_PL)
|
$(CROSS_OPTIONS_TEXI): %D%/bison.help $(CROSS_OPTIONS_PL)
|
||||||
# Create $@~ which is the previous contents. Don't use 'mv' here so
|
# Create $@~ which is the previous contents. Don't use 'mv' here so
|
||||||
# that even if we are interrupted, the file is still available for
|
# that even if we are interrupted, the file is still available for
|
||||||
# diff in the next run. Note that $@ might not exist yet.
|
# diff in the next run. Note that $@ might not exist yet.
|
||||||
$(AM_V_GEN){ test ! -f $@ || cat $@; } >$@~
|
$(AM_V_GEN){ test ! -f $@ || cat $@; } >$@~
|
||||||
$(AM_V_at)test ! -f $@.tmp || rm -f $@.tmp
|
$(AM_V_at)test ! -f $@.tmp || rm -f $@.tmp
|
||||||
$(AM_V_at)$(PERL) $(CROSS_OPTIONS_PL) $(top_srcdir)/src/scan-gram.l \
|
$(AM_V_at)$(PERL) $(CROSS_OPTIONS_PL) $(top_srcdir)/src/scan-gram.l \
|
||||||
<$(top_srcdir)/doc/bison.help >$@.tmp
|
<$(top_srcdir)/%D%/bison.help >$@.tmp
|
||||||
$(AM_V_at)diff -u $@~ $@.tmp || true
|
$(AM_V_at)diff -u $@~ $@.tmp || true
|
||||||
$(AM_V_at)mv $@.tmp $@
|
$(AM_V_at)mv $@.tmp $@
|
||||||
MAINTAINERCLEANFILES = $(CROSS_OPTIONS_TEXI)
|
MAINTAINERCLEANFILES = $(CROSS_OPTIONS_TEXI)
|
||||||
@@ -57,34 +57,34 @@ MAINTAINERCLEANFILES = $(CROSS_OPTIONS_TEXI)
|
|||||||
|
|
||||||
# Fix Info's @code in @deftype
|
# Fix Info's @code in @deftype
|
||||||
# https://lists.gnu.org/archive/html/help-texinfo/2019-11/msg00004.html
|
# https://lists.gnu.org/archive/html/help-texinfo/2019-11/msg00004.html
|
||||||
all: $(srcdir)/$(doc_bison).info.bak
|
all: $(srcdir)/$(%C%_bison).info.bak
|
||||||
$(srcdir)/$(doc_bison).info.bak: $(srcdir)/$(doc_bison).info
|
$(srcdir)/$(%C%_bison).info.bak: $(srcdir)/$(%C%_bison).info
|
||||||
$(AM_V_GEN) $(PERL) -pi.bak -0777 \
|
$(AM_V_GEN) $(PERL) -pi.bak -0777 \
|
||||||
-e 's{(^ --.*\n(?: {10}.*\n)*)}' \
|
-e 's{(^ --.*\n(?: {10}.*\n)*)}' \
|
||||||
-e '{' \
|
-e '{' \
|
||||||
-e ' $$def = $$1;' \
|
-e ' $$def = $$1;' \
|
||||||
-e ' $$def =~ s/‘|’//g;' \
|
-e ' $$def =~ s/‘|’//g;' \
|
||||||
-e ' $$def;' \
|
-e ' $$def;' \
|
||||||
-e '}gem;' $(srcdir)/$(doc_bison).info
|
-e '}gem;' $(srcdir)/$(%C%_bison).info
|
||||||
@ touch $@
|
@ touch $@
|
||||||
EXTRA_DIST += $(srcdir)/$(doc_bison).info.bak
|
EXTRA_DIST += $(srcdir)/$(%C%_bison).info.bak
|
||||||
MAINTAINERCLEANFILES += $(srcdir)/$(doc_bison).info.bak
|
MAINTAINERCLEANFILES += $(srcdir)/$(%C%_bison).info.bak
|
||||||
|
|
||||||
|
|
||||||
## ---------- ##
|
## ---------- ##
|
||||||
## Ref card. ##
|
## Ref card. ##
|
||||||
## ---------- ##
|
## ---------- ##
|
||||||
|
|
||||||
EXTRA_DIST += doc/refcard.tex
|
EXTRA_DIST += %D%/refcard.tex
|
||||||
CLEANFILES += doc/refcard.pdf
|
CLEANFILES += %D%/refcard.pdf
|
||||||
|
|
||||||
doc/refcard.pdf: doc/refcard.tex
|
%D%/refcard.pdf: %D%/refcard.tex
|
||||||
$(AM_V_GEN) cd doc && pdftex $(abs_top_srcdir)/doc/refcard.tex
|
$(AM_V_GEN) cd %D% && pdftex $(abs_top_srcdir)/%D%/refcard.tex
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## ---------------- ##
|
## ---------------- ##
|
||||||
## doc/bison.help. ##
|
## %D%/bison.help. ##
|
||||||
## ---------------- ##
|
## ---------------- ##
|
||||||
|
|
||||||
# Some of our targets (cross-options.texi, bison.1) use "bison --help".
|
# Some of our targets (cross-options.texi, bison.1) use "bison --help".
|
||||||
@@ -106,18 +106,19 @@ doc/refcard.pdf: doc/refcard.tex
|
|||||||
# compilations of cross-options.texi and bison.1. At the cost of
|
# compilations of cross-options.texi and bison.1. At the cost of
|
||||||
# repeated builds of bison.help.
|
# repeated builds of bison.help.
|
||||||
|
|
||||||
EXTRA_DIST += $(top_srcdir)/doc/bison.help
|
EXTRA_DIST += $(top_srcdir)/%D%/bison.help
|
||||||
if ! CROSS_COMPILING
|
if ! CROSS_COMPILING
|
||||||
MAINTAINERCLEANFILES += $(top_srcdir)/doc/bison.help
|
MAINTAINERCLEANFILES += $(top_srcdir)/%D%/bison.help
|
||||||
$(top_srcdir)/doc/bison.help: src/bison$(EXEEXT)
|
$(top_srcdir)/%D%/bison.help: src/bison$(EXEEXT)
|
||||||
$(AM_V_GEN)LC_ALL=C tests/bison --version >doc/bison.help.tmp
|
$(AM_V_GEN)$(MKDIR_P) %D%
|
||||||
|
$(AM_V_at) LC_ALL=C tests/bison --version >%D%/bison.help.tmp
|
||||||
$(AM_V_at) LC_ALL=C tests/bison --help | \
|
$(AM_V_at) LC_ALL=C tests/bison --help | \
|
||||||
## Avoid depending on the path to Bison.
|
## Avoid depending on the path to Bison.
|
||||||
sed -e 's,^Usage: .*/bison \[OPTION\],Usage: bison [OPTION],g' \
|
sed -e 's,^Usage: .*/bison \[OPTION\],Usage: bison [OPTION],g' \
|
||||||
## Avoid variations in the output depending on whether we are
|
## Avoid variations in the output depending on whether we are
|
||||||
## on a glibc system.
|
## on a glibc system.
|
||||||
-e '/translation bugs/d' >>doc/bison.help.tmp
|
-e '/translation bugs/d' >>%D%/bison.help.tmp
|
||||||
$(AM_V_at)$(top_srcdir)/build-aux/move-if-change doc/bison.help.tmp $@
|
$(AM_V_at)$(top_srcdir)/build-aux/move-if-change %D%/bison.help.tmp $@
|
||||||
endif ! CROSS_COMPILING
|
endif ! CROSS_COMPILING
|
||||||
|
|
||||||
|
|
||||||
@@ -125,7 +126,7 @@ endif ! CROSS_COMPILING
|
|||||||
## Man Pages. ##
|
## Man Pages. ##
|
||||||
## ----------- ##
|
## ----------- ##
|
||||||
|
|
||||||
dist_man_MANS = $(top_srcdir)/doc/bison.1
|
dist_man_MANS = $(top_srcdir)/%D%/bison.1
|
||||||
|
|
||||||
EXTRA_DIST += $(dist_man_MANS:.1=.x)
|
EXTRA_DIST += $(dist_man_MANS:.1=.x)
|
||||||
MAINTAINERCLEANFILES += $(dist_man_MANS)
|
MAINTAINERCLEANFILES += $(dist_man_MANS)
|
||||||
@@ -136,12 +137,12 @@ remove_time_stamp = \
|
|||||||
|
|
||||||
# Depend on configure to get version number changes.
|
# Depend on configure to get version number changes.
|
||||||
if ! CROSS_COMPILING
|
if ! CROSS_COMPILING
|
||||||
MAN_DEPS = doc/bison.help doc/bison.x $(top_srcdir)/configure
|
MAN_DEPS = %D%/bison.help %D%/bison.x $(top_srcdir)/configure
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(top_srcdir)/doc/bison.1: $(MAN_DEPS)
|
$(top_srcdir)/%D%/bison.1: $(MAN_DEPS)
|
||||||
$(AM_V_GEN)$(HELP2MAN) \
|
$(AM_V_GEN)$(HELP2MAN) \
|
||||||
--include=$(top_srcdir)/doc/bison.x \
|
--include=$(top_srcdir)/%D%/bison.x \
|
||||||
--output=$@.tmp tests/bison
|
--output=$@.tmp tests/bison
|
||||||
$(AM_V_at)if $(remove_time_stamp) $@ >$@a.tmp 2>/dev/null && \
|
$(AM_V_at)if $(remove_time_stamp) $@ >$@a.tmp 2>/dev/null && \
|
||||||
$(remove_time_stamp) $@.tmp | cmp $@a.tmp - >/dev/null 2>&1; then \
|
$(remove_time_stamp) $@.tmp | cmp $@a.tmp - >/dev/null 2>&1; then \
|
||||||
@@ -152,7 +153,7 @@ $(top_srcdir)/doc/bison.1: $(MAN_DEPS)
|
|||||||
$(AM_V_at)rm -f $@*.tmp
|
$(AM_V_at)rm -f $@*.tmp
|
||||||
|
|
||||||
if ENABLE_YACC
|
if ENABLE_YACC
|
||||||
nodist_man_MANS = doc/yacc.1
|
nodist_man_MANS = %D%/yacc.1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
## ----------------------------- ##
|
## ----------------------------- ##
|
||||||
@@ -161,8 +162,8 @@ endif
|
|||||||
|
|
||||||
CLEANFILES += $(FIGS_GV:.gv=.eps) $(FIGS_GV:.gv=.pdf) $(FIGS_GV:.gv=.svg)
|
CLEANFILES += $(FIGS_GV:.gv=.eps) $(FIGS_GV:.gv=.pdf) $(FIGS_GV:.gv=.svg)
|
||||||
FIGS_GV = \
|
FIGS_GV = \
|
||||||
doc/figs/example.gv \
|
%D%/figs/example.gv \
|
||||||
doc/figs/example-reduce.gv doc/figs/example-shift.gv
|
%D%/figs/example-reduce.gv %D%/figs/example-shift.gv
|
||||||
EXTRA_DIST += \
|
EXTRA_DIST += \
|
||||||
$(FIGS_GV) $(FIGS_GV:.gv=.txt) \
|
$(FIGS_GV) $(FIGS_GV:.gv=.txt) \
|
||||||
$(FIGS_GV:.gv=.eps) $(FIGS_GV:.gv=.pdf) $(FIGS_GV:.gv=.svg)
|
$(FIGS_GV:.gv=.eps) $(FIGS_GV:.gv=.pdf) $(FIGS_GV:.gv=.svg)
|
||||||
@@ -193,8 +194,8 @@ DOXYGEN = doxygen
|
|||||||
|
|
||||||
doc: html
|
doc: html
|
||||||
|
|
||||||
html-local: doc/Doxyfile
|
html-local: %D%/Doxyfile
|
||||||
$(AM_V_GEN) $(DOXYGEN) doc/Doxyfile
|
$(AM_V_GEN) $(DOXYGEN) %D%/Doxyfile
|
||||||
|
|
||||||
edit = sed -e 's,@PACKAGE_NAME\@,$(PACKAGE_NAME),g' \
|
edit = sed -e 's,@PACKAGE_NAME\@,$(PACKAGE_NAME),g' \
|
||||||
-e 's,@PACKAGE_VERSION\@,$(PACKAGE_VERSION),g' \
|
-e 's,@PACKAGE_VERSION\@,$(PACKAGE_VERSION),g' \
|
||||||
@@ -202,11 +203,11 @@ edit = sed -e 's,@PACKAGE_NAME\@,$(PACKAGE_NAME),g' \
|
|||||||
-e 's,@top_builddir\@,$(top_builddir),g' \
|
-e 's,@top_builddir\@,$(top_builddir),g' \
|
||||||
-e 's,@top_srcdir\@,$(top_srcdir),g'
|
-e 's,@top_srcdir\@,$(top_srcdir),g'
|
||||||
|
|
||||||
EXTRA_DIST += doc/Doxyfile.in
|
EXTRA_DIST += %D%/Doxyfile.in
|
||||||
CLEANFILES += doc/Doxyfile
|
CLEANFILES += %D%/Doxyfile
|
||||||
# Sed is used to generate Doxyfile from Doxyfile.in instead of
|
# Sed is used to generate Doxyfile from Doxyfile.in instead of
|
||||||
# configure, because the former is way faster than the latter.
|
# configure, because the former is way faster than the latter.
|
||||||
doc/Doxyfile: $(top_srcdir)/doc/Doxyfile.in
|
%D%/Doxyfile: $(top_srcdir)/%D%/Doxyfile.in
|
||||||
$(AM_V_GEN) $(edit) $(top_srcdir)/doc/Doxyfile.in >doc/Doxyfile
|
$(AM_V_GEN) $(edit) $(top_srcdir)/%D%/Doxyfile.in >%D%/Doxyfile
|
||||||
|
|
||||||
CLEANDIRS += doc/html
|
CLEANDIRS += %D%/html
|
||||||
|
|||||||
+247
-172
File diff suppressed because one or more lines are too long
@@ -8,7 +8,7 @@ afterwards.
|
|||||||
## simple.yy - Simple example in C++14
|
## simple.yy - Simple example in C++14
|
||||||
A very simple example in C++, based on variants and symbol constructors.
|
A very simple example in C++, based on variants and symbol constructors.
|
||||||
Variants allow to use any C++ type as semantic value type, and symbol
|
Variants allow to use any C++ type as semantic value type, and symbol
|
||||||
constructors ensure consistency between declared token type and effective
|
constructors ensure consistency between declared token kind and effective
|
||||||
semantic value.
|
semantic value.
|
||||||
|
|
||||||
Run as `./simple`.
|
Run as `./simple`.
|
||||||
|
|||||||
@@ -44,11 +44,18 @@ EOF
|
|||||||
run 0 9
|
run 0 9
|
||||||
|
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1 +
|
||||||
|
EOF
|
||||||
|
run 1 'err: -:2.1: syntax error, unexpected end of file, expecting ( or identifier or number'
|
||||||
|
|
||||||
|
|
||||||
|
# LAC finds many more tokens.
|
||||||
cat >input <<EOF
|
cat >input <<EOF
|
||||||
a := 1
|
a := 1
|
||||||
d := a + b * c
|
d := a + b * c
|
||||||
EOF
|
EOF
|
||||||
run 1 'err: -:3.1: syntax error, unexpected end of file, expecting ( or identifier or number'
|
run 1 'err: -:3.1: syntax error, unexpected end of file'
|
||||||
|
|
||||||
|
|
||||||
cat >input <<EOF
|
cat >input <<EOF
|
||||||
|
|||||||
+30
-4
@@ -28,7 +28,8 @@ Extracted from the documentation: "Multi-Function Calculator: mfcalc".
|
|||||||
https://www.gnu.org/software/bison/manual/html_node/Multi_002dfunction-Calc.html
|
https://www.gnu.org/software/bison/manual/html_node/Multi_002dfunction-Calc.html
|
||||||
|
|
||||||
## lexcalc - calculator with Flex and Bison
|
## lexcalc - calculator with Flex and Bison
|
||||||
The calculator, redux. This time using a scanner generated by Flex.
|
The calculator with precedence directives and location tracking. It uses
|
||||||
|
Flex to generate the scanner.
|
||||||
|
|
||||||
## reccalc - recursive calculator with Flex and Bison
|
## reccalc - recursive calculator with Flex and Bison
|
||||||
The example builds on top of the previous one to provide a reentrant parser.
|
The example builds on top of the previous one to provide a reentrant parser.
|
||||||
@@ -37,6 +38,29 @@ recursively. To demonstrate this feature, expressions in parentheses are
|
|||||||
tokenized as strings, and then recursively parsed from the parser. So
|
tokenized as strings, and then recursively parsed from the parser. So
|
||||||
`(((1)+(2))*((3)+(4)))` uses eight parsers, with a depth of four.
|
`(((1)+(2))*((3)+(4)))` uses eight parsers, with a depth of four.
|
||||||
|
|
||||||
|
## pushcalc - calculator implemented with a push parser
|
||||||
|
All the previous examples are so called "pull parsers": the user invokes the
|
||||||
|
parser once, which repeatedly calls the scanner until the input is drained.
|
||||||
|
|
||||||
|
This example demonstrates the "push parsers": the user calls the scanner to
|
||||||
|
fetch the next token, passes it to the parser, and repeats the operation
|
||||||
|
until the input is drained.
|
||||||
|
|
||||||
|
This example is a straightforward conversion of the 'calc' example to the
|
||||||
|
push-parser model.
|
||||||
|
|
||||||
|
## bistromathic - all the bells and whistles
|
||||||
|
This example demonstrates best practices when using Bison.
|
||||||
|
- Its hand-written scanner tracks locations.
|
||||||
|
- Its interface is pure.
|
||||||
|
- Its interface is "incremental", well suited for interaction: it uses the
|
||||||
|
push-parser API to feed the parser with the incoming tokens.
|
||||||
|
- It features an interactive command line with completion based on the
|
||||||
|
parser state, based on `yyexpected_tokens`.
|
||||||
|
- It uses a custom syntax error with location, lookahead correction and
|
||||||
|
token internationalization.
|
||||||
|
- It supports debug traces with semantic values.
|
||||||
|
- It uses named references instead of the traditional $1, $2, etc.
|
||||||
|
|
||||||
<!---
|
<!---
|
||||||
|
|
||||||
@@ -56,6 +80,8 @@ Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
|
|||||||
Texts. A copy of the license is included in the "GNU Free
|
Texts. A copy of the license is included in the "GNU Free
|
||||||
Documentation License" file as part of this distribution.
|
Documentation License" file as part of this distribution.
|
||||||
|
|
||||||
# LocalWords: mfcalc calc parsers yy rpcalc lexcalc redux reccalc ispell
|
LocalWords: mfcalc calc parsers yy rpcalc lexcalc redux reccalc ispell
|
||||||
# LocalWords: reentrant tokenized american postfix
|
LocalWords: reentrant tokenized american postfix pushcalc bistromathic
|
||||||
--->
|
LocalWords: lookahead
|
||||||
|
|
||||||
|
-->
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# This Makefile is designed to be simple and readable. It does not
|
||||||
|
# aim at portability. It requires GNU Make.
|
||||||
|
|
||||||
|
BASE = bistromathic
|
||||||
|
BISON = bison
|
||||||
|
FLEX = flex
|
||||||
|
XSLTPROC = xsltproc
|
||||||
|
|
||||||
|
all: $(BASE)
|
||||||
|
|
||||||
|
%.c %.h %.xml %.gv: %.y
|
||||||
|
$(BISON) $(BISONFLAGS) --defines --xml --graph=$*.gv -o $*.c $<
|
||||||
|
|
||||||
|
%.c: %.l
|
||||||
|
$(FLEX) $(FLEXFLAGS) -o$*.c $<
|
||||||
|
|
||||||
|
scan.o: parse.h
|
||||||
|
$(BASE): parse.o scan.o
|
||||||
|
$(CC) $(CFLAGS) -o $@ $^
|
||||||
|
|
||||||
|
run: $(BASE)
|
||||||
|
@echo "Type bistromathic expressions. Quit with ctrl-d."
|
||||||
|
./$<
|
||||||
|
|
||||||
|
html: $(BASE).html
|
||||||
|
%.html: %.xml
|
||||||
|
$(XSLTPROC) $(XSLTPROCFLAGS) -o $@ $$($(BISON) --print-datadir)/xslt/xml2xhtml.xsl $<
|
||||||
|
|
||||||
|
CLEANFILES = \
|
||||||
|
$(BASE) *.o \
|
||||||
|
parse.[ch] parse.output parse.xml parse.html parse.gv \
|
||||||
|
scan.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(CLEANFILES)
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
# bistromathic - all the bells and whistles
|
||||||
|
This example demonstrates best practices when using Bison.
|
||||||
|
- Its hand-written scanner tracks locations.
|
||||||
|
- Its interface is pure.
|
||||||
|
- Its interface is "incremental", well suited for interaction: it uses the
|
||||||
|
push-parser API to feed the parser with the incoming tokens.
|
||||||
|
- It features an interactive command line with completion based on the
|
||||||
|
parser state, based on `yyexpected_tokens`.
|
||||||
|
- It uses a custom syntax error with location, lookahead correction and
|
||||||
|
token internationalization.
|
||||||
|
- It supports debug traces with semantic values.
|
||||||
|
- It uses named references instead of the traditional $1, $2, etc.
|
||||||
|
|
||||||
|
<!---
|
||||||
|
Local Variables:
|
||||||
|
fill-column: 76
|
||||||
|
ispell-dictionary: "american"
|
||||||
|
End:
|
||||||
|
|
||||||
|
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
|
|
||||||
|
Permission is granted to copy, distribute and/or modify this document
|
||||||
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||||||
|
any later version published by the Free Software Foundation; with no
|
||||||
|
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
|
||||||
|
Texts. A copy of the license is included in the "GNU Free
|
||||||
|
Documentation License" file as part of this distribution.
|
||||||
|
|
||||||
|
LocalWords: bistromathic yyexpected lookahead ispell american
|
||||||
|
LocalWords: MERCHANTABILITY
|
||||||
|
|
||||||
|
--->
|
||||||
Executable
+131
@@ -0,0 +1,131 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
# Copyright (C) 2020 Free Software Foundation, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# macOS' version of readline does not repeat stdin on stdout in
|
||||||
|
# non-interactive mode.
|
||||||
|
if ! echo '1-1' | prog | grep '1-1'; then
|
||||||
|
strip_prompt=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1+2*3
|
||||||
|
EOF
|
||||||
|
run 0 '> 1+2*3
|
||||||
|
7
|
||||||
|
> '
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
(1+2) * 3
|
||||||
|
EOF
|
||||||
|
run 0 '> (1+2) * 3
|
||||||
|
9
|
||||||
|
> '
|
||||||
|
run -noerr 0 '> (1+2) * 3
|
||||||
|
9
|
||||||
|
> ' -p
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
a = 256
|
||||||
|
sqrt (a)
|
||||||
|
EOF
|
||||||
|
run 0 '> a = 256
|
||||||
|
256
|
||||||
|
> sqrt (a)
|
||||||
|
16
|
||||||
|
> '
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
a = .16
|
||||||
|
b = 10 ^ 2
|
||||||
|
sqrt (a * b)
|
||||||
|
EOF
|
||||||
|
run 0 '> a = .16
|
||||||
|
0.16
|
||||||
|
> b = 10 ^ 2
|
||||||
|
100
|
||||||
|
> sqrt (a * b)
|
||||||
|
4
|
||||||
|
> '
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
*
|
||||||
|
EOF
|
||||||
|
run 0 '> *
|
||||||
|
> err: 1.1: syntax error: expected end of file or - or ( or exit or double precision number or function or variable before *'
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1 + 2 * * 3
|
||||||
|
EOF
|
||||||
|
run 0 '> 1 + 2 * * 3
|
||||||
|
> err: 1.9: syntax error: expected - or ( or double precision number or function or variable before *'
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
100%
|
||||||
|
EOF
|
||||||
|
run 0 '> 100%
|
||||||
|
100
|
||||||
|
> err: 1.4: error: invalid character'
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1 / 0
|
||||||
|
EOF
|
||||||
|
run 0 '> 1 / 0
|
||||||
|
> err: 1.1-5: error: division by zero'
|
||||||
|
|
||||||
|
|
||||||
|
## ------------ ##
|
||||||
|
## Completion. ##
|
||||||
|
## ------------ ##
|
||||||
|
|
||||||
|
# From now on, the differences between versions of GNU Readline are
|
||||||
|
# too painful to try to cope with.
|
||||||
|
if $strip_prompt; then
|
||||||
|
echo "SKIP: this is not the GNU Readline we expect"
|
||||||
|
if $exit; then
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check completion after an operator.
|
||||||
|
sed -e 's/\\t/ /g' >input <<EOF
|
||||||
|
(1+\t\t
|
||||||
|
EOF
|
||||||
|
run 0 '> (1+
|
||||||
|
( cos ln
|
||||||
|
- double precision number sin
|
||||||
|
atan exp sqrt
|
||||||
|
> (1+
|
||||||
|
> err: 1.4: syntax error: expected - or ( or double precision number or function or variable before end of file'
|
||||||
|
|
||||||
|
# Check the completion of a word.
|
||||||
|
sed -e 's/\\t/ /g' >input <<EOF
|
||||||
|
(at\t\t
|
||||||
|
EOF
|
||||||
|
run 0 '> (atan ( ''
|
||||||
|
> err: 1.9: syntax error: expected - or ( or double precision number or function or variable before end of file'
|
||||||
|
|
||||||
|
# Check the completion at the very beginning.
|
||||||
|
sed -e 's/\\t/ /g' >input <<EOF
|
||||||
|
e\t\t
|
||||||
|
EOF
|
||||||
|
run 0 '> e
|
||||||
|
end of file exit exp ''
|
||||||
|
> e
|
||||||
|
0
|
||||||
|
> err: '
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
## Copyright (C) 2020 Free Software Foundation, Inc.
|
||||||
|
##
|
||||||
|
## This program is free software: you can redistribute it and/or modify
|
||||||
|
## it under the terms of the GNU General Public License as published by
|
||||||
|
## the Free Software Foundation, either version 3 of the License, or
|
||||||
|
## (at your option) any later version.
|
||||||
|
##
|
||||||
|
## This program is distributed in the hope that it will be useful,
|
||||||
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
## GNU General Public License for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License
|
||||||
|
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
bistromathicdir = $(docdir)/%D%
|
||||||
|
|
||||||
|
## --------------- ##
|
||||||
|
## Bistromathics. ##
|
||||||
|
## --------------- ##
|
||||||
|
|
||||||
|
check_PROGRAMS += %D%/bistromathic
|
||||||
|
TESTS += %D%/bistromathic.test
|
||||||
|
EXTRA_DIST += %D%/bistromathic.test
|
||||||
|
nodist_%C%_bistromathic_SOURCES = %D%/parse.y %D%/parse.h
|
||||||
|
%D%/parse.c: $(dependencies)
|
||||||
|
|
||||||
|
# Don't use gnulib's system headers.
|
||||||
|
%C%_bistromathic_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
|
||||||
|
%C%_bistromathic_LDADD = -lm -lreadline
|
||||||
|
|
||||||
|
dist_bistromathic_DATA = %D%/parse.y %D%/Makefile %D%/README.md
|
||||||
|
CLEANFILES += %D%/parse.[ch] %D%/parse.output
|
||||||
|
CLEANDIRS += %D%/*.dSYM
|
||||||
@@ -0,0 +1,486 @@
|
|||||||
|
%require "3.6"
|
||||||
|
|
||||||
|
%code top {
|
||||||
|
#include <ctype.h> // isdigit
|
||||||
|
#include <math.h> // cos, sin, etc.
|
||||||
|
#include <stddef.h> // ptrdiff_t
|
||||||
|
#include <stdio.h> // printf
|
||||||
|
#include <stdlib.h> // calloc.
|
||||||
|
#include <string.h> // strcmp
|
||||||
|
|
||||||
|
#include <readline/readline.h>
|
||||||
|
#include <readline/history.h>
|
||||||
|
}
|
||||||
|
|
||||||
|
%code requires {
|
||||||
|
// Function type.
|
||||||
|
typedef double (func_t) (double);
|
||||||
|
|
||||||
|
// Data type for links in the chain of symbols.
|
||||||
|
typedef struct symrec symrec;
|
||||||
|
struct symrec
|
||||||
|
{
|
||||||
|
char *name; // name of symbol
|
||||||
|
int type; // type of symbol: either VAR or FUN
|
||||||
|
union
|
||||||
|
{
|
||||||
|
double var; // value of a VAR
|
||||||
|
func_t *fun; // value of a FUN
|
||||||
|
} value;
|
||||||
|
symrec *next; // link field
|
||||||
|
};
|
||||||
|
|
||||||
|
symrec *putsym (char const *name, int sym_type);
|
||||||
|
symrec *getsym (char const *name);
|
||||||
|
}
|
||||||
|
|
||||||
|
%code provides {
|
||||||
|
int yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc);
|
||||||
|
void yyerror (YYLTYPE *yylloc, char const *msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
%code {
|
||||||
|
#define N_
|
||||||
|
#define _
|
||||||
|
|
||||||
|
// Whether to quit.
|
||||||
|
int done = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't share global variables between the scanner and the parser.
|
||||||
|
%define api.pure full
|
||||||
|
|
||||||
|
// Generate a push parser.
|
||||||
|
%define api.push-pull push
|
||||||
|
|
||||||
|
// To avoid name clashes (e.g., with C's EOF) prefix token definitions
|
||||||
|
// with TOK_ (e.g., TOK_EOF).
|
||||||
|
%define api.token.prefix {TOK_}
|
||||||
|
|
||||||
|
// Customized syntax error messages (see yyreport_syntax_error).
|
||||||
|
%define parse.error custom
|
||||||
|
|
||||||
|
// with locations.
|
||||||
|
%locations
|
||||||
|
|
||||||
|
// and accurate list of expected tokens.
|
||||||
|
%define parse.lac full
|
||||||
|
|
||||||
|
// Generate the parser description file (calc.output).
|
||||||
|
%verbose
|
||||||
|
|
||||||
|
// Generate YYSTYPE from the types assigned to symbols.
|
||||||
|
%define api.value.type union
|
||||||
|
%token
|
||||||
|
PLUS "+"
|
||||||
|
MINUS "-"
|
||||||
|
STAR "*"
|
||||||
|
SLASH "/"
|
||||||
|
CARET "^"
|
||||||
|
LPAREN "("
|
||||||
|
RPAREN ")"
|
||||||
|
EQUAL "="
|
||||||
|
EXIT "exit"
|
||||||
|
<double>
|
||||||
|
NUM _("double precision number")
|
||||||
|
<symrec*>
|
||||||
|
FUN _("function")
|
||||||
|
VAR _("variable")
|
||||||
|
|
||||||
|
%nterm <double> exp
|
||||||
|
|
||||||
|
// Enable run-time traces (yydebug).
|
||||||
|
%define parse.trace
|
||||||
|
|
||||||
|
// Formatting semantic values in debug traces.
|
||||||
|
%printer { fprintf (yyo, "%s", $$->name); } VAR;
|
||||||
|
%printer { fprintf (yyo, "%s()", $$->name); } FUN;
|
||||||
|
%printer { fprintf (yyo, "%g", $$); } <double>;
|
||||||
|
|
||||||
|
|
||||||
|
// Precedence (from lowest to highest) and associativity.
|
||||||
|
%precedence "="
|
||||||
|
%left "+" "-"
|
||||||
|
%left "*" "/"
|
||||||
|
%precedence NEG // negation--unary minus
|
||||||
|
%right "^" // exponentiation
|
||||||
|
|
||||||
|
%% // The grammar follows.
|
||||||
|
input:
|
||||||
|
%empty
|
||||||
|
| exp { printf ("%.10g\n", $exp); }
|
||||||
|
| "exit" { done = 1; }
|
||||||
|
;
|
||||||
|
|
||||||
|
exp:
|
||||||
|
NUM
|
||||||
|
| VAR { $$ = $VAR->value.var; }
|
||||||
|
| VAR "=" exp { $$ = $3; $VAR->value.var = $3; }
|
||||||
|
| FUN "(" exp ")" { $$ = $FUN->value.fun ($3); }
|
||||||
|
| exp[l] "+" exp[r] { $$ = $l + $r; }
|
||||||
|
| exp[l] "-" exp[r] { $$ = $l - $r; }
|
||||||
|
| exp[l] "*" exp[r] { $$ = $l * $r; }
|
||||||
|
| exp[l] "/" exp[r]
|
||||||
|
{
|
||||||
|
if ($r == 0)
|
||||||
|
{
|
||||||
|
yyerror (&@$, "error: division by zero");
|
||||||
|
YYERROR;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$$ = $l / $r;
|
||||||
|
}
|
||||||
|
| "-" exp %prec NEG { $$ = -$2; }
|
||||||
|
| exp[l] "^" exp[r] { $$ = pow ($l, $r); }
|
||||||
|
| "(" exp ")" { $$ = $2; }
|
||||||
|
;
|
||||||
|
|
||||||
|
// End of grammar.
|
||||||
|
%%
|
||||||
|
|
||||||
|
/*------------.
|
||||||
|
| Functions. |
|
||||||
|
`------------*/
|
||||||
|
|
||||||
|
struct init
|
||||||
|
{
|
||||||
|
char const *name;
|
||||||
|
func_t *fun;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct init const funs[] =
|
||||||
|
{
|
||||||
|
{ "atan", atan },
|
||||||
|
{ "cos", cos },
|
||||||
|
{ "exp", exp },
|
||||||
|
{ "ln", log },
|
||||||
|
{ "sin", sin },
|
||||||
|
{ "sqrt", sqrt },
|
||||||
|
{ 0, 0 },
|
||||||
|
};
|
||||||
|
|
||||||
|
// The symbol table: a chain of 'struct symrec'.
|
||||||
|
static symrec *sym_table;
|
||||||
|
|
||||||
|
// Put functions in table.
|
||||||
|
static void
|
||||||
|
init_table (void)
|
||||||
|
{
|
||||||
|
for (int i = 0; funs[i].name; i++)
|
||||||
|
{
|
||||||
|
symrec *ptr = putsym (funs[i].name, TOK_FUN);
|
||||||
|
ptr->value.fun = funs[i].fun;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
symrec *
|
||||||
|
putsym (char const *name, int sym_type)
|
||||||
|
{
|
||||||
|
symrec *res = (symrec *) malloc (sizeof (symrec));
|
||||||
|
res->name = strdup (name);
|
||||||
|
res->type = sym_type;
|
||||||
|
res->value.var = 0; // Set value to 0 even if fun.
|
||||||
|
res->next = sym_table;
|
||||||
|
sym_table = res;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
symrec *
|
||||||
|
getsym (char const *name)
|
||||||
|
{
|
||||||
|
for (symrec *p = sym_table; p; p = p->next)
|
||||||
|
if (strcmp (p->name, name) == 0)
|
||||||
|
return p;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// How many symbols are registered.
|
||||||
|
int
|
||||||
|
symbol_count (void)
|
||||||
|
{
|
||||||
|
int res = 0;
|
||||||
|
for (symrec *p = sym_table; p; p = p->next)
|
||||||
|
++res;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*----------.
|
||||||
|
| Scanner. |
|
||||||
|
`----------*/
|
||||||
|
|
||||||
|
int
|
||||||
|
yylex (const char **line, YYSTYPE *yylval, YYLTYPE *yylloc)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
|
||||||
|
// Ignore white space, get first nonwhite character.
|
||||||
|
do {
|
||||||
|
// Move the first position onto the last.
|
||||||
|
yylloc->first_line = yylloc->last_line;
|
||||||
|
yylloc->first_column = yylloc->last_column;
|
||||||
|
|
||||||
|
yylloc->last_column += 1;
|
||||||
|
c = *((*line)++);
|
||||||
|
} while (c == ' ' || c == '\t');
|
||||||
|
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '+': return TOK_PLUS;
|
||||||
|
case '-': return TOK_MINUS;
|
||||||
|
case '*': return TOK_STAR;
|
||||||
|
case '/': return TOK_SLASH;
|
||||||
|
case '^': return TOK_CARET;
|
||||||
|
case '=': return TOK_EQUAL;
|
||||||
|
case '(': return TOK_LPAREN;
|
||||||
|
case ')': return TOK_RPAREN;
|
||||||
|
|
||||||
|
case '\0': return TOK_YYEOF;
|
||||||
|
|
||||||
|
// Numbers.
|
||||||
|
case '.':
|
||||||
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
|
case '5': case '6': case '7': case '8': case '9':
|
||||||
|
{
|
||||||
|
int nchars = 0;
|
||||||
|
sscanf (*line - 1, "%lf%n", &yylval->TOK_NUM, &nchars);
|
||||||
|
*line += nchars - 1;
|
||||||
|
yylloc->last_column += nchars - 1;
|
||||||
|
return TOK_NUM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Identifiers.
|
||||||
|
case 'a': case 'b': case 'c': case 'd': case 'e':
|
||||||
|
case 'f': case 'g': case 'h': case 'i': case 'j':
|
||||||
|
case 'k': case 'l': case 'm': case 'n': case 'o':
|
||||||
|
case 'p': case 'q': case 'r': case 's': case 't':
|
||||||
|
case 'u': case 'v': case 'w': case 'x': case 'y':
|
||||||
|
case 'z':
|
||||||
|
{
|
||||||
|
int nchars = 0;
|
||||||
|
char buf[100];
|
||||||
|
sscanf (*line - 1, "%99[a-z]%n", buf, &nchars);
|
||||||
|
*line += nchars - 1;
|
||||||
|
yylloc->last_column += nchars - 1;
|
||||||
|
if (strcmp (buf, "exit") == 0)
|
||||||
|
return TOK_EXIT;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
symrec *s = getsym (buf);
|
||||||
|
if (!s)
|
||||||
|
s = putsym (buf, TOK_VAR);
|
||||||
|
yylval->TOK_VAR = s;
|
||||||
|
return s->type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stray characters.
|
||||||
|
default:
|
||||||
|
yyerror (yylloc, "error: invalid character");
|
||||||
|
return yylex (line, yylval, yylloc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*---------.
|
||||||
|
| Parser. |
|
||||||
|
`---------*/
|
||||||
|
|
||||||
|
int
|
||||||
|
yyreport_syntax_error (const yypcontext_t *ctx)
|
||||||
|
{
|
||||||
|
int res = 0;
|
||||||
|
YY_LOCATION_PRINT (stderr, *yypcontext_location (ctx));
|
||||||
|
fprintf (stderr, ": syntax error");
|
||||||
|
// Report the tokens expected at this point.
|
||||||
|
{
|
||||||
|
enum { TOKENMAX = 10 };
|
||||||
|
yysymbol_kind_t expected[TOKENMAX];
|
||||||
|
int n = yypcontext_expected_tokens (ctx, expected, TOKENMAX);
|
||||||
|
if (n < 0)
|
||||||
|
// Forward errors to yyparse.
|
||||||
|
res = n;
|
||||||
|
else
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
fprintf (stderr, "%s %s",
|
||||||
|
i == 0 ? ": expected" : " or", yysymbol_name (expected[i]));
|
||||||
|
}
|
||||||
|
// Report the unexpected token.
|
||||||
|
{
|
||||||
|
yysymbol_kind_t lookahead = yypcontext_token (ctx);
|
||||||
|
if (lookahead != YYSYMBOL_YYEMPTY)
|
||||||
|
fprintf (stderr, " before %s", yysymbol_name (lookahead));
|
||||||
|
}
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called by yyparse on error.
|
||||||
|
void yyerror (YYLTYPE *loc, char const *msg)
|
||||||
|
{
|
||||||
|
YY_LOCATION_PRINT (stderr, *loc);
|
||||||
|
fprintf (stderr, ": %s\n", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-----------.
|
||||||
|
| Readline. |
|
||||||
|
`-----------*/
|
||||||
|
|
||||||
|
// Parse (and execute) this line.
|
||||||
|
int process_line (YYLTYPE *lloc, const char *line)
|
||||||
|
{
|
||||||
|
yypstate *ps = yypstate_new ();
|
||||||
|
int status = 0;
|
||||||
|
do {
|
||||||
|
YYSTYPE lval;
|
||||||
|
status = yypush_parse (ps, yylex (&line, &lval, lloc), &lval, lloc);
|
||||||
|
} while (status == YYPUSH_MORE);
|
||||||
|
yypstate_delete (ps);
|
||||||
|
lloc->last_line++;
|
||||||
|
lloc->last_column = 1;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the list of possible tokens after INPUT was read.
|
||||||
|
int
|
||||||
|
expected_tokens (const char *input,
|
||||||
|
int *tokens, int ntokens)
|
||||||
|
{
|
||||||
|
YYDPRINTF ((stderr, "expected_tokens (\"%s\")", input));
|
||||||
|
|
||||||
|
// Parse the current state of the line.
|
||||||
|
yypstate *ps = yypstate_new ();
|
||||||
|
int status = 0;
|
||||||
|
do {
|
||||||
|
YYLTYPE lloc;
|
||||||
|
YYSTYPE lval;
|
||||||
|
int token = yylex (&input, &lval, &lloc);
|
||||||
|
// Don't let the parse know when we reach the end of input.
|
||||||
|
if (!token)
|
||||||
|
break;
|
||||||
|
status = yypush_parse (ps, token, &lval, &lloc);
|
||||||
|
} while (status == YYPUSH_MORE);
|
||||||
|
|
||||||
|
// Then query for the accepted tokens at this point.
|
||||||
|
int res = yypstate_expected_tokens (ps, tokens, ntokens);
|
||||||
|
yypstate_delete (ps);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Attempt to complete on the contents of TEXT. START and END bound the
|
||||||
|
region of rl_line_buffer that contains the word to complete. TEXT is
|
||||||
|
the word to complete. We can use the entire contents of rl_line_buffer
|
||||||
|
in case we want to do some simple parsing. Return the array of matches,
|
||||||
|
or NULL if there aren't any. */
|
||||||
|
char **
|
||||||
|
completion (const char *text, int start, int end)
|
||||||
|
{
|
||||||
|
YYDPRINTF ((stderr, "completion (\"%.*s[%.*s]%s\")\n",
|
||||||
|
start, rl_line_buffer,
|
||||||
|
end - start, rl_line_buffer + start,
|
||||||
|
rl_line_buffer + end));
|
||||||
|
|
||||||
|
// Get list of token numbers.
|
||||||
|
int tokens[YYNTOKENS];
|
||||||
|
char *line = strndup (rl_line_buffer, start);
|
||||||
|
int ntokens = expected_tokens (line, tokens, YYNTOKENS);
|
||||||
|
free (line);
|
||||||
|
|
||||||
|
// Build MATCHES, the list of possible completions.
|
||||||
|
const int len = strlen (text);
|
||||||
|
// Need initial prefix and final NULL.
|
||||||
|
char **matches = calloc (ntokens + symbol_count () + 2, sizeof *matches);
|
||||||
|
int match = 1;
|
||||||
|
for (int i = 0; i < ntokens; ++i)
|
||||||
|
switch (tokens[i])
|
||||||
|
{
|
||||||
|
case YYSYMBOL_FUN:
|
||||||
|
for (symrec *s = sym_table; s; s = s->next)
|
||||||
|
if (s->type == TOK_FUN && strncmp (text, s->name, len) == 0)
|
||||||
|
matches[match++] = strdup (s->name);
|
||||||
|
break;
|
||||||
|
case YYSYMBOL_VAR:
|
||||||
|
for (symrec *s = sym_table; s; s = s->next)
|
||||||
|
if (s->type == TOK_VAR && strncmp (text, s->name, len) == 0)
|
||||||
|
matches[match++] = strdup (s->name);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
const char* token = yysymbol_name (tokens[i]);
|
||||||
|
if (strncmp (text, token, len) == 0)
|
||||||
|
matches[match++] = strdup (token);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the longest common prefix, and install it in matches[0], as
|
||||||
|
// required by readline.
|
||||||
|
if (match == 1)
|
||||||
|
matches[0] = strdup (text);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int lcplen = strlen (matches[1]);
|
||||||
|
for (int i = 2; i < match && lcplen; ++i)
|
||||||
|
for (int j = 0; j < lcplen; ++j)
|
||||||
|
if (matches[1][j] != matches[i][j])
|
||||||
|
lcplen = j;
|
||||||
|
matches[0] = strndup (matches[1], lcplen);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (yydebug)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "completion (\"%.*s[%.*s]%s\") = ",
|
||||||
|
start, rl_line_buffer,
|
||||||
|
end - start, rl_line_buffer + start,
|
||||||
|
rl_line_buffer + end);
|
||||||
|
for (int i = 1; matches[i]; ++i)
|
||||||
|
fprintf (stderr, "%s%s",
|
||||||
|
i == 1 ? "{" : ", ",
|
||||||
|
matches[i]);
|
||||||
|
fprintf (stderr, "}\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't fall back to proposing file names.
|
||||||
|
rl_attempted_completion_over = 1;
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_readline (void)
|
||||||
|
{
|
||||||
|
// Allow conditional parsing of the ~/.inputrc file.
|
||||||
|
rl_readline_name = "bistromathic";
|
||||||
|
|
||||||
|
// Tell the completer that we want a crack first.
|
||||||
|
rl_attempted_completion_function = completion;
|
||||||
|
|
||||||
|
// The basic list of characters that signal a break between words
|
||||||
|
// for the completer routine.
|
||||||
|
rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&{(+-*/^)";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-------.
|
||||||
|
| Main. |
|
||||||
|
`-------*/
|
||||||
|
|
||||||
|
int main (int argc, char const* argv[])
|
||||||
|
{
|
||||||
|
// Enable parse traces on option -p.
|
||||||
|
if (argc == 2 && strcmp (argv[1], "-p") == 0)
|
||||||
|
yydebug = 1;
|
||||||
|
init_table ();
|
||||||
|
init_readline ();
|
||||||
|
YYLTYPE lloc = {1, 1, 1, 1};
|
||||||
|
while (!done)
|
||||||
|
{
|
||||||
|
char *line = readline ("> ");
|
||||||
|
if (!line)
|
||||||
|
return 0;
|
||||||
|
if (*line)
|
||||||
|
add_history (line);
|
||||||
|
process_line (&lloc, line);
|
||||||
|
free (line);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,4 +34,10 @@ cat >input <<EOF
|
|||||||
(1+2) * 3
|
(1+2) * 3
|
||||||
EOF
|
EOF
|
||||||
run 0 9
|
run 0 9
|
||||||
|
# Check the traces.
|
||||||
run -noerr 0 9 -p
|
run -noerr 0 9 -p
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1++2
|
||||||
|
EOF
|
||||||
|
run 0 "err: syntax error, unexpected '+', expecting number or '('"
|
||||||
|
|||||||
@@ -8,16 +8,22 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
%define api.header.include {"calc.h"}
|
%define api.header.include {"calc.h"}
|
||||||
%define api.value.type union /* Generate YYSTYPE from these types: */
|
|
||||||
|
/* Generate YYSTYPE from the types used in %token and %type. */
|
||||||
|
%define api.value.type union
|
||||||
%token <double> NUM "number"
|
%token <double> NUM "number"
|
||||||
%type <double> expr term fact
|
%type <double> expr term fact
|
||||||
|
|
||||||
/* Generate the parser description file. */
|
/* Generate the parser description file (calc.output). */
|
||||||
%verbose
|
%verbose
|
||||||
|
|
||||||
|
/* Nice error messages with details. */
|
||||||
|
%define parse.error detailed
|
||||||
|
|
||||||
/* Enable run-time traces (yydebug). */
|
/* Enable run-time traces (yydebug). */
|
||||||
%define parse.trace
|
%define parse.trace
|
||||||
|
|
||||||
/* Formatting semantic values. */
|
/* Formatting semantic values in debug traces. */
|
||||||
%printer { fprintf (yyo, "%g", $$); } <double>;
|
%printer { fprintf (yyo, "%g", $$); } <double>;
|
||||||
|
|
||||||
%% /* The grammar follows. */
|
%% /* The grammar follows. */
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
This directory contains lexcalc, the traditional example of using Flex and
|
This directory contains lexcalc, the traditional example of using Flex and
|
||||||
Bison to build a simple calculator.
|
Bison to build a simple calculator.
|
||||||
|
|
||||||
|
It features detailed syntax errors with locations.
|
||||||
|
|
||||||
<!---
|
<!---
|
||||||
Local Variables:
|
Local Variables:
|
||||||
fill-column: 76
|
fill-column: 76
|
||||||
|
|||||||
@@ -29,4 +29,9 @@ run -noerr 0 9 -p
|
|||||||
cat >input <<EOF
|
cat >input <<EOF
|
||||||
(1+2) *
|
(1+2) *
|
||||||
EOF
|
EOF
|
||||||
run 1 'err: syntax error, unexpected end-of-line, expecting ( or number'
|
run 1 'err: 1.8-2.0: syntax error, unexpected end of line, expecting ( or number'
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1 / (2 - 2)
|
||||||
|
EOF
|
||||||
|
run 1 'err: 1.1-11: error: division by zero'
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
{
|
{
|
||||||
// Tell Flex the expected prototype of yylex.
|
// Tell Flex the expected prototype of yylex.
|
||||||
#define YY_DECL \
|
#define YY_DECL \
|
||||||
enum yytokentype yylex (YYSTYPE* yylval, int *nerrs)
|
yytoken_kind_t yylex (YYSTYPE* yylval, YYLTYPE *yylloc, int *nerrs)
|
||||||
YY_DECL;
|
YY_DECL;
|
||||||
|
|
||||||
void yyerror (int *nerrs, const char *msg);
|
void yyerror (YYLTYPE *loc, int *nerrs, const char *msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emitted on top of the implementation file.
|
// Emitted on top of the implementation file.
|
||||||
@@ -19,12 +19,27 @@
|
|||||||
#include <stdlib.h> // getenv.
|
#include <stdlib.h> // getenv.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't share global variables between the scanner and the parser.
|
||||||
%define api.pure full
|
%define api.pure full
|
||||||
|
|
||||||
|
// To avoid name clashes (e.g., with C's EOF) prefix token definitions
|
||||||
|
// with TOK_ (e.g., TOK_EOF).
|
||||||
%define api.token.prefix {TOK_}
|
%define api.token.prefix {TOK_}
|
||||||
|
|
||||||
|
// %token and %type use genuine types (e.g., "%token <int>"). Let
|
||||||
|
// %bison define YYSTYPE as a union of all these types.
|
||||||
%define api.value.type union
|
%define api.value.type union
|
||||||
%define parse.error verbose
|
|
||||||
|
// Generate detailed error messages.
|
||||||
|
%define parse.error detailed
|
||||||
|
|
||||||
|
// with locations.
|
||||||
|
%locations
|
||||||
|
|
||||||
|
// Enable debug traces (see yydebug in main).
|
||||||
%define parse.trace
|
%define parse.trace
|
||||||
// Error count, exchanged between main, yyparse and yylex.
|
|
||||||
|
// Error count, exchanged between main, yyparse and yylex.
|
||||||
%param {int *nerrs}
|
%param {int *nerrs}
|
||||||
|
|
||||||
%token
|
%token
|
||||||
@@ -34,8 +49,7 @@
|
|||||||
SLASH "/"
|
SLASH "/"
|
||||||
LPAREN "("
|
LPAREN "("
|
||||||
RPAREN ")"
|
RPAREN ")"
|
||||||
EOL "end-of-line"
|
EOL "end of line"
|
||||||
EOF 0 "end-of-file"
|
|
||||||
;
|
;
|
||||||
|
|
||||||
%token <int> NUM "number"
|
%token <int> NUM "number"
|
||||||
@@ -66,7 +80,7 @@ exp:
|
|||||||
{
|
{
|
||||||
if ($3 == 0)
|
if ($3 == 0)
|
||||||
{
|
{
|
||||||
yyerror (nerrs, "invalid division by zero");
|
yyerror (&@$, nerrs, "error: division by zero");
|
||||||
YYERROR;
|
YYERROR;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -77,9 +91,11 @@ exp:
|
|||||||
;
|
;
|
||||||
%%
|
%%
|
||||||
// Epilogue (C code).
|
// Epilogue (C code).
|
||||||
void yyerror (int *nerrs, const char *msg)
|
|
||||||
|
void yyerror (YYLTYPE *loc, int *nerrs, const char *msg)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s\n", msg);
|
YY_LOCATION_PRINT (stderr, *loc);
|
||||||
|
fprintf (stderr, ": %s\n", msg);
|
||||||
++*nerrs;
|
++*nerrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Prologue (directives). -*- C++ -*- */
|
/* Prologue (directives). -*- C -*- */
|
||||||
|
|
||||||
/* Disable Flex features we don't need, to avoid warnings. */
|
/* Disable Flex features we don't need, to avoid warnings. */
|
||||||
%option nodefault noinput nounput noyywrap
|
%option nodefault noinput nounput noyywrap
|
||||||
@@ -9,9 +9,24 @@
|
|||||||
#include <stdlib.h> /* strtol */
|
#include <stdlib.h> /* strtol */
|
||||||
|
|
||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
|
|
||||||
|
// Each time a rule is matched, advance the end cursor/position.
|
||||||
|
#define YY_USER_ACTION \
|
||||||
|
yylloc->last_column += yyleng;
|
||||||
|
|
||||||
|
// Move the first position onto the last.
|
||||||
|
#define LOCATION_STEP() \
|
||||||
|
do { \
|
||||||
|
yylloc->first_line = yylloc->last_line; \
|
||||||
|
yylloc->first_column = yylloc->last_column; \
|
||||||
|
} while (0)
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
%{
|
||||||
|
// Each time yylex is called, move the head position to the end one.
|
||||||
|
LOCATION_STEP ();
|
||||||
|
%}
|
||||||
/* Rules. */
|
/* Rules. */
|
||||||
|
|
||||||
"+" return TOK_PLUS;
|
"+" return TOK_PLUS;
|
||||||
@@ -27,18 +42,18 @@
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
long n = strtol (yytext, NULL, 10);
|
long n = strtol (yytext, NULL, 10);
|
||||||
if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
|
if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
|
||||||
yyerror (nerrs, "integer is out of range");
|
yyerror (yylloc, nerrs, "integer is out of range");
|
||||||
yylval->TOK_NUM = (int) n;
|
yylval->TOK_NUM = (int) n;
|
||||||
return TOK_NUM;
|
return TOK_NUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"\n" yylloc->last_line++; yylloc->last_column = 1; return TOK_EOL;
|
||||||
|
|
||||||
/* Ignore white spaces. */
|
/* Ignore white spaces. */
|
||||||
[ \t]+ continue;
|
[ \t]+ LOCATION_STEP (); continue;
|
||||||
|
|
||||||
"\n" return TOK_EOL;
|
. yyerror (yylloc, nerrs, "syntax error, invalid character"); continue;
|
||||||
|
|
||||||
. yyerror (nerrs, "syntax error, invalid character");
|
<<EOF>> return TOK_YYEOF;
|
||||||
|
|
||||||
<<EOF>> return TOK_EOF;
|
|
||||||
%%
|
%%
|
||||||
/* Epilogue (C code). */
|
/* Epilogue (C code). */
|
||||||
|
|||||||
@@ -16,8 +16,10 @@
|
|||||||
cdir = $(docdir)/%D%
|
cdir = $(docdir)/%D%
|
||||||
dist_c_DATA = %D%/README.md
|
dist_c_DATA = %D%/README.md
|
||||||
|
|
||||||
|
include %D%/bistromathic/local.mk
|
||||||
include %D%/calc/local.mk
|
include %D%/calc/local.mk
|
||||||
include %D%/lexcalc/local.mk
|
include %D%/lexcalc/local.mk
|
||||||
include %D%/mfcalc/local.mk
|
include %D%/mfcalc/local.mk
|
||||||
|
include %D%/pushcalc/local.mk
|
||||||
include %D%/reccalc/local.mk
|
include %D%/reccalc/local.mk
|
||||||
include %D%/rpcalc/local.mk
|
include %D%/rpcalc/local.mk
|
||||||
|
|||||||
@@ -25,3 +25,15 @@ cat >input <<EOF
|
|||||||
EOF
|
EOF
|
||||||
run 0 9
|
run 0 9
|
||||||
run -noerr 0 9 -p
|
run -noerr 0 9 -p
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
a = 256
|
||||||
|
sqrt (a)
|
||||||
|
EOF
|
||||||
|
run 0 '256
|
||||||
|
16'
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
16 == 12
|
||||||
|
EOF
|
||||||
|
run 0 'err: syntax error'
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# This Makefile is designed to be simple and readable. It does not
|
||||||
|
# aim at portability. It requires GNU Make.
|
||||||
|
|
||||||
|
BASE = calc
|
||||||
|
BISON = bison
|
||||||
|
XSLTPROC = xsltproc
|
||||||
|
|
||||||
|
all: $(BASE)
|
||||||
|
|
||||||
|
%.c %.h %.xml %.gv: %.y
|
||||||
|
$(BISON) $(BISONFLAGS) --defines --xml --graph=$*.gv -o $*.c $<
|
||||||
|
|
||||||
|
$(BASE): $(BASE).o
|
||||||
|
$(CC) $(CFLAGS) -o $@ $^
|
||||||
|
|
||||||
|
run: $(BASE)
|
||||||
|
@echo "Type arithmetic expressions. Quit with ctrl-d."
|
||||||
|
./$<
|
||||||
|
|
||||||
|
html: $(BASE).html
|
||||||
|
%.html: %.xml
|
||||||
|
$(XSLTPROC) $(XSLTPROCFLAGS) -o $@ $$($(BISON) --print-datadir)/xslt/xml2xhtml.xsl $<
|
||||||
|
|
||||||
|
CLEANFILES = \
|
||||||
|
$(BASE) *.o $(BASE).[ch] $(BASE).output $(BASE).xml $(BASE).html $(BASE).gv
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(CLEANFILES)
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# pushcalc - push parser with Bison
|
||||||
|
|
||||||
|
This directory contains pushcalc, the traditional calculator, implemented as
|
||||||
|
a push parser.
|
||||||
|
|
||||||
|
Traditionally Bison is used to create so called "pull parsers": the user
|
||||||
|
invokes the parser once, which repeatedly calls (pulls) the scanner until
|
||||||
|
the input is drained.
|
||||||
|
|
||||||
|
This example demonstrates the "push parsers": the user calls scanner to
|
||||||
|
fetch the next token, passes (pushes) it to the parser, and repeats the
|
||||||
|
operation until the input is drained.
|
||||||
|
|
||||||
|
This example is a straightforward conversion of the 'calc' example to the
|
||||||
|
push-parser model.
|
||||||
|
|
||||||
|
<!---
|
||||||
|
Local Variables:
|
||||||
|
fill-column: 76
|
||||||
|
ispell-dictionary: "american"
|
||||||
|
End:
|
||||||
|
|
||||||
|
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Permission is granted to copy, distribute and/or modify this document
|
||||||
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||||||
|
any later version published by the Free Software Foundation; with no
|
||||||
|
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
|
||||||
|
Texts. A copy of the license is included in the "GNU Free
|
||||||
|
Documentation License" file as part of this distribution.
|
||||||
|
|
||||||
|
--->
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
# Copyright (C) 2020 Free Software Foundation, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1+2*3
|
||||||
|
EOF
|
||||||
|
run 0 7
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1 - 2 - 3
|
||||||
|
EOF
|
||||||
|
run 0 -4
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
8 / 2 / 2
|
||||||
|
EOF
|
||||||
|
run 0 2
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
(1+2) * 3
|
||||||
|
EOF
|
||||||
|
run 0 9
|
||||||
|
run -noerr 0 9 -p
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1++2
|
||||||
|
EOF
|
||||||
|
run 0 "err: syntax error, unexpected '+', expecting number or '('"
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
%code top {
|
||||||
|
#include <ctype.h> /* isdigit. */
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h> /* For printf, etc. */
|
||||||
|
#include <string.h> /* strcmp. */
|
||||||
|
}
|
||||||
|
|
||||||
|
%code {
|
||||||
|
int yylex (YYSTYPE *yylval);
|
||||||
|
void yyerror (char const *);
|
||||||
|
}
|
||||||
|
|
||||||
|
%define api.header.include {"calc.h"}
|
||||||
|
|
||||||
|
/* Generate YYSTYPE from the types used in %token and %type. */
|
||||||
|
%define api.value.type union
|
||||||
|
%token <double> NUM "number"
|
||||||
|
%type <double> expr term fact
|
||||||
|
|
||||||
|
/* Don't share global variables between the scanner and the parser. */
|
||||||
|
%define api.pure full
|
||||||
|
/* Generate a push parser. */
|
||||||
|
%define api.push-pull push
|
||||||
|
|
||||||
|
/* Nice error messages with details. */
|
||||||
|
%define parse.error detailed
|
||||||
|
|
||||||
|
/* Generate the parser description file (calc.output). */
|
||||||
|
%verbose
|
||||||
|
|
||||||
|
/* Enable run-time traces (yydebug). */
|
||||||
|
%define parse.trace
|
||||||
|
|
||||||
|
/* Formatting semantic values in debug traces. */
|
||||||
|
%printer { fprintf (yyo, "%g", $$); } <double>;
|
||||||
|
|
||||||
|
%% /* The grammar follows. */
|
||||||
|
input:
|
||||||
|
%empty
|
||||||
|
| input line
|
||||||
|
;
|
||||||
|
|
||||||
|
line:
|
||||||
|
'\n'
|
||||||
|
| expr '\n' { printf ("%.10g\n", $1); }
|
||||||
|
| error '\n' { yyerrok; }
|
||||||
|
;
|
||||||
|
|
||||||
|
expr:
|
||||||
|
expr '+' term { $$ = $1 + $3; }
|
||||||
|
| expr '-' term { $$ = $1 - $3; }
|
||||||
|
| term
|
||||||
|
;
|
||||||
|
|
||||||
|
term:
|
||||||
|
term '*' fact { $$ = $1 * $3; }
|
||||||
|
| term '/' fact { $$ = $1 / $3; }
|
||||||
|
| fact
|
||||||
|
;
|
||||||
|
|
||||||
|
fact:
|
||||||
|
"number"
|
||||||
|
| '(' expr ')' { $$ = $expr; }
|
||||||
|
;
|
||||||
|
|
||||||
|
%%
|
||||||
|
|
||||||
|
int
|
||||||
|
yylex (YYSTYPE *yylval)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
|
||||||
|
/* Ignore white space, get first nonwhite character. */
|
||||||
|
while ((c = getchar ()) == ' ' || c == '\t')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (c == EOF)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Char starts a number => parse the number. */
|
||||||
|
if (c == '.' || isdigit (c))
|
||||||
|
{
|
||||||
|
ungetc (c, stdin);
|
||||||
|
scanf ("%lf", &yylval->NUM);
|
||||||
|
return NUM;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Any other character is a token by itself. */
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Called by yyparse on error. */
|
||||||
|
void
|
||||||
|
yyerror (char const *s)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s\n", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char const* argv[])
|
||||||
|
{
|
||||||
|
/* Enable parse traces on option -p. */
|
||||||
|
for (int i = 1; i < argc; ++i)
|
||||||
|
if (!strcmp (argv[i], "-p"))
|
||||||
|
yydebug = 1;
|
||||||
|
int status;
|
||||||
|
yypstate *ps = yypstate_new ();
|
||||||
|
do {
|
||||||
|
YYSTYPE lval;
|
||||||
|
status = yypush_parse (ps, yylex (&lval), &lval);
|
||||||
|
} while (status == YYPUSH_MORE);
|
||||||
|
yypstate_delete (ps);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
## Copyright (C) 2020 Free Software Foundation, Inc.
|
||||||
|
##
|
||||||
|
## This program is free software: you can redistribute it and/or modify
|
||||||
|
## it under the terms of the GNU General Public License as published by
|
||||||
|
## the Free Software Foundation, either version 3 of the License, or
|
||||||
|
## (at your option) any later version.
|
||||||
|
##
|
||||||
|
## This program is distributed in the hope that it will be useful,
|
||||||
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
## GNU General Public License for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License
|
||||||
|
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
pushcalcdir = $(docdir)/%D%
|
||||||
|
|
||||||
|
## ------ ##
|
||||||
|
## Calc. ##
|
||||||
|
## ------ ##
|
||||||
|
|
||||||
|
check_PROGRAMS += %D%/calc
|
||||||
|
TESTS += %D%/calc.test
|
||||||
|
EXTRA_DIST += %D%/calc.test
|
||||||
|
nodist_%C%_calc_SOURCES = %D%/calc.y
|
||||||
|
%D%/calc.c: $(dependencies)
|
||||||
|
|
||||||
|
# Don't use gnulib's system headers.
|
||||||
|
%C%_calc_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
|
||||||
|
|
||||||
|
dist_pushcalc_DATA = %D%/calc.y %D%/Makefile %D%/README.md
|
||||||
|
CLEANFILES += %D%/calc.[ch] %D%/calc.output
|
||||||
|
CLEANDIRS += %D%/*.dSYM
|
||||||
@@ -4,7 +4,11 @@
|
|||||||
// Emitted in the header file, before the definition of YYSTYPE.
|
// Emitted in the header file, before the definition of YYSTYPE.
|
||||||
%code requires
|
%code requires
|
||||||
{
|
{
|
||||||
|
#ifndef YY_TYPEDEF_YY_SCANNER_T
|
||||||
|
# define YY_TYPEDEF_YY_SCANNER_T
|
||||||
typedef void* yyscan_t;
|
typedef void* yyscan_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
// Whether to print the intermediate results.
|
// Whether to print the intermediate results.
|
||||||
@@ -22,7 +26,7 @@
|
|||||||
// Tell Flex the expected prototype of yylex.
|
// Tell Flex the expected prototype of yylex.
|
||||||
// The scanner argument must be named yyscanner.
|
// The scanner argument must be named yyscanner.
|
||||||
#define YY_DECL \
|
#define YY_DECL \
|
||||||
enum yytokentype yylex (YYSTYPE* yylval, yyscan_t yyscanner, result *res)
|
yytoken_kind_t yylex (YYSTYPE* yylval, yyscan_t yyscanner, result *res)
|
||||||
YY_DECL;
|
YY_DECL;
|
||||||
|
|
||||||
void yyerror (yyscan_t scanner, result *res, const char *msg, ...);
|
void yyerror (yyscan_t scanner, result *res, const char *msg, ...);
|
||||||
@@ -132,7 +136,6 @@ exp:
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
// Epilogue (C code).
|
// Epilogue (C code).
|
||||||
|
|
||||||
#include "scan.h"
|
#include "scan.h"
|
||||||
|
|
||||||
result
|
result
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Prologue (directives). -*- C++ -*- */
|
/* Prologue (directives). -*- C -*- */
|
||||||
|
|
||||||
/* Disable Flex features we don't need, to avoid warnings. */
|
/* Disable Flex features we don't need, to avoid warnings. */
|
||||||
%option nodefault noinput nounput noyywrap
|
%option nodefault noinput nounput noyywrap
|
||||||
@@ -17,10 +17,14 @@
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
%{
|
%{
|
||||||
|
// Number of opened parentheses.
|
||||||
int nesting = 0;
|
int nesting = 0;
|
||||||
|
// A buffer storing the text inside the outer parentheses.
|
||||||
char *str = NULL;
|
char *str = NULL;
|
||||||
int size = 0;
|
// Its allocated size.
|
||||||
int capacity = 0;
|
int capacity = 0;
|
||||||
|
// Its used size.
|
||||||
|
int size = 0;
|
||||||
#define STR_APPEND() \
|
#define STR_APPEND() \
|
||||||
do { \
|
do { \
|
||||||
if (capacity < size + yyleng + 1) \
|
if (capacity < size + yyleng + 1) \
|
||||||
|
|||||||
+11
-13
@@ -99,16 +99,15 @@ class CalcLexer(R) : Lexer
|
|||||||
while (!input.empty && input.front != '\n' && isWhite (input.front))
|
while (!input.empty && input.front != '\n' && isWhite (input.front))
|
||||||
input.popFront;
|
input.popFront;
|
||||||
|
|
||||||
// Handle EOF.
|
|
||||||
if (input.empty)
|
if (input.empty)
|
||||||
return YYTokenType.EOF;
|
return TokenKind.YYEOF;
|
||||||
|
|
||||||
// Numbers.
|
// Numbers.
|
||||||
if (input.front.isNumber)
|
if (input.front.isNumber)
|
||||||
{
|
{
|
||||||
import std.conv : parse;
|
import std.conv : parse;
|
||||||
semanticVal_.ival = input.parse!int;
|
semanticVal_.ival = input.parse!int;
|
||||||
return YYTokenType.NUM;
|
return TokenKind.NUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Individual characters
|
// Individual characters
|
||||||
@@ -116,16 +115,15 @@ class CalcLexer(R) : Lexer
|
|||||||
input.popFront;
|
input.popFront;
|
||||||
switch (ch)
|
switch (ch)
|
||||||
{
|
{
|
||||||
case EOF: return YYTokenType.EOF;
|
case '=': return TokenKind.EQ;
|
||||||
case '=': return YYTokenType.EQ;
|
case '+': return TokenKind.PLUS;
|
||||||
case '+': return YYTokenType.PLUS;
|
case '-': return TokenKind.MINUS;
|
||||||
case '-': return YYTokenType.MINUS;
|
case '*': return TokenKind.STAR;
|
||||||
case '*': return YYTokenType.STAR;
|
case '/': return TokenKind.SLASH;
|
||||||
case '/': return YYTokenType.SLASH;
|
case '(': return TokenKind.LPAR;
|
||||||
case '(': return YYTokenType.LPAR;
|
case ')': return TokenKind.RPAR;
|
||||||
case ')': return YYTokenType.RPAR;
|
case '\n': return TokenKind.EOL;
|
||||||
case '\n': return YYTokenType.EOL;
|
default: assert(0);
|
||||||
default: assert(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,168 +0,0 @@
|
|||||||
%language "Java"
|
|
||||||
|
|
||||||
%define api.parser.class {Calc}
|
|
||||||
%define api.parser.public
|
|
||||||
|
|
||||||
%define parse.error verbose
|
|
||||||
%locations
|
|
||||||
|
|
||||||
%code imports {
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.StreamTokenizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
%code {
|
|
||||||
public static void main (String args[]) throws IOException
|
|
||||||
{
|
|
||||||
CalcLexer l = new CalcLexer (System.in);
|
|
||||||
Calc p = new Calc (l);
|
|
||||||
p.parse ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Bison Declarations */
|
|
||||||
%token <Integer> NUM "number"
|
|
||||||
%type <Integer> exp
|
|
||||||
|
|
||||||
%nonassoc '=' /* comparison */
|
|
||||||
%left '-' '+'
|
|
||||||
%left '*' '/'
|
|
||||||
%precedence NEG /* negation--unary minus */
|
|
||||||
%right '^' /* exponentiation */
|
|
||||||
|
|
||||||
/* Grammar follows */
|
|
||||||
%%
|
|
||||||
input:
|
|
||||||
line
|
|
||||||
| input line
|
|
||||||
;
|
|
||||||
|
|
||||||
line:
|
|
||||||
'\n'
|
|
||||||
| exp '\n' { System.out.println ($exp); }
|
|
||||||
| error '\n'
|
|
||||||
;
|
|
||||||
|
|
||||||
exp:
|
|
||||||
NUM { $$ = $1; }
|
|
||||||
| exp '=' exp
|
|
||||||
{
|
|
||||||
if ($1.intValue () != $3.intValue ())
|
|
||||||
yyerror (@$, "calc: error: " + $1 + " != " + $3);
|
|
||||||
}
|
|
||||||
| exp '+' exp { $$ = new Integer ($1.intValue () + $3.intValue ()); }
|
|
||||||
| exp '-' exp { $$ = new Integer ($1.intValue () - $3.intValue ()); }
|
|
||||||
| exp '*' exp { $$ = new Integer ($1.intValue () * $3.intValue ()); }
|
|
||||||
| exp '/' exp { $$ = new Integer ($1.intValue () / $3.intValue ()); }
|
|
||||||
| '-' exp %prec NEG { $$ = new Integer (-$2.intValue ()); }
|
|
||||||
| exp '^' exp { $$ = new Integer ((int)
|
|
||||||
Math.pow ($1.intValue (),
|
|
||||||
$3.intValue ())); }
|
|
||||||
| '(' exp ')' { $$ = $2; }
|
|
||||||
| '(' error ')' { $$ = new Integer (1111); }
|
|
||||||
| '!' { $$ = new Integer (0); return YYERROR; }
|
|
||||||
| '-' error { $$ = new Integer (0); return YYERROR; }
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
%%
|
|
||||||
class CalcLexer implements Calc.Lexer {
|
|
||||||
|
|
||||||
StreamTokenizer st;
|
|
||||||
|
|
||||||
public CalcLexer (InputStream is)
|
|
||||||
{
|
|
||||||
st = new StreamTokenizer (new InputStreamReader (is));
|
|
||||||
st.resetSyntax ();
|
|
||||||
st.eolIsSignificant (true);
|
|
||||||
st.whitespaceChars ('\t', '\t');
|
|
||||||
st.whitespaceChars (' ', ' ');
|
|
||||||
st.wordChars ('0', '9');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Position yypos = new Position (1, 0);
|
|
||||||
|
|
||||||
public Position getStartPos () {
|
|
||||||
return yypos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Position getEndPos () {
|
|
||||||
return yypos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void yyerror (Calc.Location l, String s)
|
|
||||||
{
|
|
||||||
if (l == null)
|
|
||||||
System.err.println (s);
|
|
||||||
else
|
|
||||||
System.err.println (l + ": " + s);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Integer yylval;
|
|
||||||
|
|
||||||
public Object getLVal () {
|
|
||||||
return yylval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int yylex () throws IOException {
|
|
||||||
int ttype = st.nextToken ();
|
|
||||||
yypos = new Position (yypos.lineno (), yypos.token () + 1);
|
|
||||||
if (ttype == st.TT_EOF)
|
|
||||||
return EOF;
|
|
||||||
else if (ttype == st.TT_EOL)
|
|
||||||
{
|
|
||||||
yypos = new Position (yypos.lineno () + 1, 0);
|
|
||||||
return (int) '\n';
|
|
||||||
}
|
|
||||||
else if (ttype == st.TT_WORD)
|
|
||||||
{
|
|
||||||
yylval = new Integer (st.sval);
|
|
||||||
return NUM;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return st.ttype;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class Position {
|
|
||||||
public int line;
|
|
||||||
public int token;
|
|
||||||
|
|
||||||
public Position ()
|
|
||||||
{
|
|
||||||
line = 0;
|
|
||||||
token = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Position (int l, int t)
|
|
||||||
{
|
|
||||||
line = l;
|
|
||||||
token = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals (Position l)
|
|
||||||
{
|
|
||||||
return l.line == line && l.token == token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString ()
|
|
||||||
{
|
|
||||||
return Integer.toString (line) + "." + Integer.toString(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int lineno ()
|
|
||||||
{
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int token ()
|
|
||||||
{
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,8 +5,11 @@ This directory contains examples of Bison grammar files in Java.
|
|||||||
You can run `make` to compile these examples. And `make clean` to tidy
|
You can run `make` to compile these examples. And `make clean` to tidy
|
||||||
afterwards.
|
afterwards.
|
||||||
|
|
||||||
## java/Calc.y
|
## simple/Calc.y
|
||||||
The usual calculator.
|
The usual calculator, a very simple version.
|
||||||
|
|
||||||
|
## calc/Calc.y
|
||||||
|
The calculator, but with location tracking and debug traces.
|
||||||
|
|
||||||
<!---
|
<!---
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
# Copyright (C) 2018-2020 Free Software Foundation, Inc.
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1 + 2 * 3
|
||||||
|
EOF
|
||||||
|
run 0 7
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1 + 2 * 3 = 7
|
||||||
|
(1 + 2) * 3 = 9
|
||||||
|
EOF
|
||||||
|
run 0 '7
|
||||||
|
9'
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1 + 2 * * 3
|
||||||
|
EOF
|
||||||
|
run 0 "err: 1.9-1.10: syntax error: expected ! or - or ( or number before *"
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
12 222
|
||||||
|
EOF
|
||||||
|
run 0 "err: 1.6-1.9: syntax error: expected + or - or * or / or ^ or = or end of line before number"
|
||||||
@@ -0,0 +1,263 @@
|
|||||||
|
%language "Java"
|
||||||
|
|
||||||
|
%define api.parser.class {Calc}
|
||||||
|
%define api.parser.public
|
||||||
|
|
||||||
|
%define parse.error custom
|
||||||
|
%define parse.trace
|
||||||
|
|
||||||
|
%locations
|
||||||
|
|
||||||
|
%code imports {
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.StreamTokenizer;
|
||||||
|
import java.nio.CharBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
%code {
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
CalcLexer l = new CalcLexer(System.in);
|
||||||
|
Calc p = new Calc(l);
|
||||||
|
for (String arg : args)
|
||||||
|
if (arg.equals("-p"))
|
||||||
|
p.setDebugLevel(1);
|
||||||
|
if (!p.parse())
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String i18n(String s) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Bison Declarations */
|
||||||
|
%token
|
||||||
|
BANG "!"
|
||||||
|
PLUS "+"
|
||||||
|
MINUS "-"
|
||||||
|
STAR "*"
|
||||||
|
SLASH "/"
|
||||||
|
CARET "^"
|
||||||
|
LPAREN "("
|
||||||
|
RPAREN ")"
|
||||||
|
EQUAL "="
|
||||||
|
EOL _("end of line")
|
||||||
|
<Integer>
|
||||||
|
NUM _("number")
|
||||||
|
%type <Integer> exp
|
||||||
|
|
||||||
|
%nonassoc "=" /* comparison */
|
||||||
|
%left "-" "+"
|
||||||
|
%left "*" "/"
|
||||||
|
%precedence NEG /* negation--unary minus */
|
||||||
|
%right "^" /* exponentiation */
|
||||||
|
|
||||||
|
/* Grammar follows */
|
||||||
|
%%
|
||||||
|
input:
|
||||||
|
line
|
||||||
|
| input line
|
||||||
|
;
|
||||||
|
|
||||||
|
line:
|
||||||
|
EOL
|
||||||
|
| exp EOL { System.out.println($exp); }
|
||||||
|
| error EOL
|
||||||
|
;
|
||||||
|
|
||||||
|
exp:
|
||||||
|
NUM { $$ = $1; }
|
||||||
|
| exp "=" exp
|
||||||
|
{
|
||||||
|
if ($1.intValue() != $3.intValue())
|
||||||
|
yyerror(@$, "calc: error: " + $1 + " != " + $3);
|
||||||
|
}
|
||||||
|
| exp "+" exp { $$ = $1 + $3; }
|
||||||
|
| exp "-" exp { $$ = $1 - $3; }
|
||||||
|
| exp "*" exp { $$ = $1 * $3; }
|
||||||
|
| exp "/" exp { $$ = $1 / $3; }
|
||||||
|
| "-" exp %prec NEG { $$ = -$2; }
|
||||||
|
| exp "^" exp { $$ = (int) Math.pow($1, $3); }
|
||||||
|
| "(" exp ")" { $$ = $2; }
|
||||||
|
| "(" error ")" { $$ = 1111; }
|
||||||
|
| "!" { $$ = 0; return YYERROR; }
|
||||||
|
| "-" error { $$ = 0; return YYERROR; }
|
||||||
|
;
|
||||||
|
|
||||||
|
%%
|
||||||
|
class CalcLexer implements Calc.Lexer {
|
||||||
|
|
||||||
|
StreamTokenizer st;
|
||||||
|
PositionReader reader;
|
||||||
|
|
||||||
|
public CalcLexer(InputStream is) {
|
||||||
|
reader = new PositionReader(new InputStreamReader(is));
|
||||||
|
st = new StreamTokenizer(reader);
|
||||||
|
st.resetSyntax();
|
||||||
|
st.eolIsSignificant(true);
|
||||||
|
st.wordChars('0', '9');
|
||||||
|
}
|
||||||
|
|
||||||
|
Position start = new Position(1, 0);
|
||||||
|
Position end = new Position(1, 0);
|
||||||
|
|
||||||
|
public Position getStartPos() {
|
||||||
|
return new Position(start);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Position getEndPos() {
|
||||||
|
return new Position(end);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reportSyntaxError(Calc.Context ctx) {
|
||||||
|
System.err.print(ctx.getLocation() + ": syntax error");
|
||||||
|
{
|
||||||
|
final int TOKENMAX = 10;
|
||||||
|
Calc.SymbolKind[] arg = new Calc.SymbolKind[TOKENMAX];
|
||||||
|
int n = ctx.getExpectedTokens(arg, TOKENMAX);
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
System.err.print((i == 0 ? ": expected " : " or ")
|
||||||
|
+ arg[i].getName());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
Calc.SymbolKind lookahead = ctx.getToken();
|
||||||
|
if (lookahead != null)
|
||||||
|
System.err.print(" before " + lookahead.getName());
|
||||||
|
}
|
||||||
|
System.err.println("");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void yyerror(Calc.Location l, String s) {
|
||||||
|
if (l == null)
|
||||||
|
System.err.println(s);
|
||||||
|
else
|
||||||
|
System.err.println(l + ": " + s);
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer yylval;
|
||||||
|
|
||||||
|
public Object getLVal() {
|
||||||
|
return yylval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int yylex() throws IOException {
|
||||||
|
start.set(reader.getPosition());
|
||||||
|
int ttype = st.nextToken();
|
||||||
|
end.set(reader.getPosition());
|
||||||
|
switch (ttype) {
|
||||||
|
case StreamTokenizer.TT_EOF:
|
||||||
|
return EOF;
|
||||||
|
case StreamTokenizer.TT_EOL:
|
||||||
|
end.line += 1;
|
||||||
|
end.column = 0;
|
||||||
|
return EOL;
|
||||||
|
case StreamTokenizer.TT_WORD:
|
||||||
|
yylval = new Integer(st.sval);
|
||||||
|
end.set(reader.getPreviousPosition());
|
||||||
|
return NUM;
|
||||||
|
case ' ': case '\t':
|
||||||
|
return yylex();
|
||||||
|
case '!':
|
||||||
|
return BANG;
|
||||||
|
case '+':
|
||||||
|
return PLUS;
|
||||||
|
case '-':
|
||||||
|
return MINUS;
|
||||||
|
case '*':
|
||||||
|
return STAR;
|
||||||
|
case '/':
|
||||||
|
return SLASH;
|
||||||
|
case '^':
|
||||||
|
return CARET;
|
||||||
|
case '(':
|
||||||
|
return LPAREN;
|
||||||
|
case ')':
|
||||||
|
return RPAREN;
|
||||||
|
case '=':
|
||||||
|
return EQUAL;
|
||||||
|
default:
|
||||||
|
throw new AssertionError("invalid character: " + ttype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Position {
|
||||||
|
public int line = 1;
|
||||||
|
public int column = 1;
|
||||||
|
|
||||||
|
public Position() {
|
||||||
|
line = 1;
|
||||||
|
column = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Position(int l, int t) {
|
||||||
|
line = l;
|
||||||
|
column = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Position(Position p) {
|
||||||
|
line = p.line;
|
||||||
|
column = p.column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(Position p) {
|
||||||
|
line = p.line;
|
||||||
|
column = p.column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Position l) {
|
||||||
|
return l.line == line && l.column == column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return Integer.toString(line) + "." + Integer.toString(column);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int line() {
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int column() {
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PositionReader extends BufferedReader {
|
||||||
|
|
||||||
|
private Position position = new Position();
|
||||||
|
// Position before the latest call to "read", i.e. position
|
||||||
|
// of the last character of the current token.
|
||||||
|
private Position previousPosition = new Position();
|
||||||
|
|
||||||
|
public PositionReader(Reader reader) {
|
||||||
|
super(reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int read() throws IOException {
|
||||||
|
previousPosition.set(position);
|
||||||
|
int res = super.read();
|
||||||
|
if (res > -1) {
|
||||||
|
char c = (char) res;
|
||||||
|
if (c == '\r' || c == '\n') {
|
||||||
|
position.line += 1;
|
||||||
|
position.column = 1;
|
||||||
|
} else {
|
||||||
|
position.column += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Position getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Position getPreviousPosition() {
|
||||||
|
return previousPosition;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
## Copyright (C) 2018-2020 Free Software Foundation, Inc.
|
||||||
|
##
|
||||||
|
## This program is free software: you can redistribute it and/or modify
|
||||||
|
## it under the terms of the GNU General Public License as published by
|
||||||
|
## the Free Software Foundation, either version 3 of the License, or
|
||||||
|
## (at your option) any later version.
|
||||||
|
##
|
||||||
|
## This program is distributed in the hope that it will be useful,
|
||||||
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
## GNU General Public License for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License
|
||||||
|
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
java_calcdir = $(docdir)/%D%
|
||||||
|
|
||||||
|
## ------ ##
|
||||||
|
## Calc. ##
|
||||||
|
## ------ ##
|
||||||
|
|
||||||
|
if ENABLE_JAVA
|
||||||
|
check_SCRIPTS += %D%/Calc.class
|
||||||
|
TESTS += %D%/Calc.test
|
||||||
|
endif
|
||||||
|
EXTRA_DIST += %D%/Calc.test
|
||||||
|
|
||||||
|
%D%/Calc.java: %D%/Calc.y $(dependencies)
|
||||||
|
$(AM_V_GEN)$(MKDIR_P) %D%
|
||||||
|
$(AM_V_at)$(BISON) $(srcdir)/%D%/Calc.y -o $@
|
||||||
|
|
||||||
|
%D%/Calc.class: %D%/Calc.java
|
||||||
|
$(AM_V_GEN) $(SHELL) $(top_builddir)/javacomp.sh %D%/Calc.java
|
||||||
|
|
||||||
|
dist_java_calc_DATA = %D%/Calc.y %D%/Makefile
|
||||||
|
CLEANFILES += %D%/*.class %D%/Calc.java
|
||||||
+4
-20
@@ -1,4 +1,4 @@
|
|||||||
## Copyright (C) 2018-2020 Free Software Foundation, Inc.
|
## Copyright (C) 2020 Free Software Foundation, Inc.
|
||||||
##
|
##
|
||||||
## This program is free software: you can redistribute it and/or modify
|
## This program is free software: you can redistribute it and/or modify
|
||||||
## it under the terms of the GNU General Public License as published by
|
## it under the terms of the GNU General Public License as published by
|
||||||
@@ -14,23 +14,7 @@
|
|||||||
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
javadir = $(docdir)/%D%
|
javadir = $(docdir)/%D%
|
||||||
|
dist_java_DATA = %D%/README.md
|
||||||
|
|
||||||
## ------ ##
|
include %D%/calc/local.mk
|
||||||
## Calc. ##
|
include %D%/simple/local.mk
|
||||||
## ------ ##
|
|
||||||
|
|
||||||
if ENABLE_JAVA
|
|
||||||
check_SCRIPTS += %D%/Calc.class
|
|
||||||
TESTS += %D%/Calc.test
|
|
||||||
endif
|
|
||||||
EXTRA_DIST += %D%/Calc.test
|
|
||||||
|
|
||||||
%D%/Calc.java: %D%/Calc.y $(dependencies)
|
|
||||||
$(AM_V_GEN)$(MKDIR_P) %D%
|
|
||||||
$(AM_V_at)$(BISON) $(srcdir)/%D%/Calc.y -o $@
|
|
||||||
|
|
||||||
%D%/Calc.class: %D%/Calc.java
|
|
||||||
$(AM_V_GEN) $(SHELL) $(top_builddir)/javacomp.sh %D%/Calc.java
|
|
||||||
|
|
||||||
dist_java_DATA = %D%/Calc.y %D%/Makefile %D%/README.md
|
|
||||||
CLEANFILES += %D%/*.class %D%/Calc.java
|
|
||||||
|
|||||||
@@ -20,7 +20,14 @@ cat >input <<EOF
|
|||||||
EOF
|
EOF
|
||||||
run 0 7
|
run 0 7
|
||||||
|
|
||||||
|
cat >input <<EOF
|
||||||
|
1 + 2 * 3 = 7
|
||||||
|
(1 + 2) * 3 = 9
|
||||||
|
EOF
|
||||||
|
run 0 '7
|
||||||
|
9'
|
||||||
|
|
||||||
cat >input <<EOF
|
cat >input <<EOF
|
||||||
1 + 2 * * 3
|
1 + 2 * * 3
|
||||||
EOF
|
EOF
|
||||||
run 0 "err: 1.5: syntax error, unexpected '*', expecting number or '-' or '(' or '!'"
|
run 0 "err: syntax error, unexpected '*', expecting number or '-' or '(' or '!'"
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
%language "Java"
|
||||||
|
|
||||||
|
%define api.parser.class {Calc}
|
||||||
|
%define api.parser.public
|
||||||
|
|
||||||
|
%define parse.error verbose
|
||||||
|
|
||||||
|
%code imports {
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.StreamTokenizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
%code {
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
CalcLexer l = new CalcLexer(System.in);
|
||||||
|
Calc p = new Calc(l);
|
||||||
|
if (!p.parse())
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Bison Declarations */
|
||||||
|
%token <Integer> NUM "number"
|
||||||
|
%type <Integer> exp
|
||||||
|
|
||||||
|
%nonassoc '=' /* comparison */
|
||||||
|
%left '-' '+'
|
||||||
|
%left '*' '/'
|
||||||
|
%precedence NEG /* negation--unary minus */
|
||||||
|
%right '^' /* exponentiation */
|
||||||
|
|
||||||
|
/* Grammar follows */
|
||||||
|
%%
|
||||||
|
input:
|
||||||
|
line
|
||||||
|
| input line
|
||||||
|
;
|
||||||
|
|
||||||
|
line:
|
||||||
|
'\n'
|
||||||
|
| exp '\n' { System.out.println($exp); }
|
||||||
|
| error '\n'
|
||||||
|
;
|
||||||
|
|
||||||
|
exp:
|
||||||
|
NUM { $$ = $1; }
|
||||||
|
| exp '=' exp
|
||||||
|
{
|
||||||
|
if ($1.intValue() != $3.intValue())
|
||||||
|
yyerror("calc: error: " + $1 + " != " + $3);
|
||||||
|
}
|
||||||
|
| exp '+' exp { $$ = $1 + $3; }
|
||||||
|
| exp '-' exp { $$ = $1 - $3; }
|
||||||
|
| exp '*' exp { $$ = $1 * $3; }
|
||||||
|
| exp '/' exp { $$ = $1 / $3; }
|
||||||
|
| '-' exp %prec NEG { $$ = -$2; }
|
||||||
|
| exp '^' exp { $$ = (int) Math.pow($1, $3); }
|
||||||
|
| '(' exp ')' { $$ = $2; }
|
||||||
|
| '(' error ')' { $$ = 1111; }
|
||||||
|
| '!' { $$ = 0; return YYERROR; }
|
||||||
|
| '-' error { $$ = 0; return YYERROR; }
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
%%
|
||||||
|
class CalcLexer implements Calc.Lexer {
|
||||||
|
|
||||||
|
StreamTokenizer st;
|
||||||
|
|
||||||
|
public CalcLexer(InputStream is) {
|
||||||
|
st = new StreamTokenizer(new InputStreamReader(is));
|
||||||
|
st.resetSyntax();
|
||||||
|
st.eolIsSignificant(true);
|
||||||
|
st.whitespaceChars('\t', '\t');
|
||||||
|
st.whitespaceChars(' ', ' ');
|
||||||
|
st.wordChars('0', '9');
|
||||||
|
}
|
||||||
|
|
||||||
|
public void yyerror(String s) {
|
||||||
|
System.err.println(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer yylval;
|
||||||
|
|
||||||
|
public Object getLVal() {
|
||||||
|
return yylval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int yylex() throws IOException {
|
||||||
|
int ttype = st.nextToken();
|
||||||
|
switch (ttype) {
|
||||||
|
case StreamTokenizer.TT_EOF:
|
||||||
|
return EOF;
|
||||||
|
case StreamTokenizer.TT_EOL:
|
||||||
|
return (int) '\n';
|
||||||
|
case StreamTokenizer.TT_WORD:
|
||||||
|
yylval = new Integer(st.sval);
|
||||||
|
return NUM;
|
||||||
|
default:
|
||||||
|
return ttype;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# This Makefile is designed to be simple and readable. It does not
|
||||||
|
# aim at portability. It requires GNU Make.
|
||||||
|
|
||||||
|
BISON = bison
|
||||||
|
JAVAC = javac
|
||||||
|
JAVA = java
|
||||||
|
XSLTPROC = xsltproc
|
||||||
|
|
||||||
|
all: Calc.class
|
||||||
|
|
||||||
|
%.java %.xml %.gv: %.y
|
||||||
|
$(BISON) $(BISONFLAGS) --xml --graph=$*.gv -o $*.java $<
|
||||||
|
|
||||||
|
%.class: %.java
|
||||||
|
$(JAVAC) $(JAVACFLAGS) $<
|
||||||
|
|
||||||
|
run: Calc.class
|
||||||
|
@echo "Type arithmetic expressions. Quit with ctrl-d."
|
||||||
|
$(JAVA) $(JAVAFLAGS) Calc
|
||||||
|
|
||||||
|
html: Calc.html
|
||||||
|
%.html: %.xml
|
||||||
|
$(XSLTPROC) $(XSLTPROCFLAGS) -o $@ $$($(BISON) --print-datadir)/xslt/xml2xhtml.xsl $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.class Calc.java Calc.html Calc.xml Calc.gv
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
## Copyright (C) 2018-2020 Free Software Foundation, Inc.
|
||||||
|
##
|
||||||
|
## This program is free software: you can redistribute it and/or modify
|
||||||
|
## it under the terms of the GNU General Public License as published by
|
||||||
|
## the Free Software Foundation, either version 3 of the License, or
|
||||||
|
## (at your option) any later version.
|
||||||
|
##
|
||||||
|
## This program is distributed in the hope that it will be useful,
|
||||||
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
## GNU General Public License for more details.
|
||||||
|
##
|
||||||
|
## You should have received a copy of the GNU General Public License
|
||||||
|
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
java_simpledir = $(docdir)/%D%
|
||||||
|
|
||||||
|
## ------ ##
|
||||||
|
## Calc. ##
|
||||||
|
## ------ ##
|
||||||
|
|
||||||
|
if ENABLE_JAVA
|
||||||
|
check_SCRIPTS += %D%/Calc.class
|
||||||
|
TESTS += %D%/Calc.test
|
||||||
|
endif
|
||||||
|
EXTRA_DIST += %D%/Calc.test
|
||||||
|
|
||||||
|
%D%/Calc.java: %D%/Calc.y $(dependencies)
|
||||||
|
$(AM_V_GEN)$(MKDIR_P) %D%
|
||||||
|
$(AM_V_at)$(BISON) $(srcdir)/%D%/Calc.y -o $@
|
||||||
|
|
||||||
|
%D%/Calc.class: %D%/Calc.java
|
||||||
|
$(AM_V_GEN) $(SHELL) $(top_builddir)/javacomp.sh %D%/Calc.java
|
||||||
|
|
||||||
|
dist_java_simple_DATA = %D%/Calc.y %D%/Makefile
|
||||||
|
CLEANFILES += %D%/*.class %D%/Calc.java
|
||||||
+21
-3
@@ -30,6 +30,10 @@ exit=true
|
|||||||
# top_builddir.
|
# top_builddir.
|
||||||
cwd=$(pwd)
|
cwd=$(pwd)
|
||||||
|
|
||||||
|
# Whether to strip '> ...' lines from the expected output.
|
||||||
|
# See bistromathic.test.
|
||||||
|
strip_prompt=false
|
||||||
|
|
||||||
# The exercised program.
|
# The exercised program.
|
||||||
abs_medir=$cwd/examples/$medir
|
abs_medir=$cwd/examples/$medir
|
||||||
if test -x "$abs_medir/$me"; then
|
if test -x "$abs_medir/$me"; then
|
||||||
@@ -77,20 +81,34 @@ run ()
|
|||||||
# Expected exit status.
|
# Expected exit status.
|
||||||
sta_exp=$1
|
sta_exp=$1
|
||||||
shift
|
shift
|
||||||
|
|
||||||
# Expected output.
|
# Expected output.
|
||||||
out_exp=$1
|
if $strip_prompt; then
|
||||||
|
out_exp=$(echo "$1" | sed -e 's/^> err:/err:/;/^> /d')
|
||||||
|
else
|
||||||
|
out_exp=$1
|
||||||
|
fi
|
||||||
shift
|
shift
|
||||||
|
|
||||||
# Effective exit status.
|
# Effective exit status.
|
||||||
sta_eff=0
|
sta_eff=0
|
||||||
|
|
||||||
prog "$@" - <input >out_eff 2>err_eff || sta_eff=$?
|
prog "$@" - <input >out_eff 2>err_eff || sta_eff=$?
|
||||||
|
|
||||||
# Combine effective output and error streams.
|
# Combine effective output and error streams.
|
||||||
out_eff=$(cat out_eff && $noerr || sed -e 's/^/err: /g' err_eff)
|
out_eff=$(cat out_eff && $noerr || sed -e 's/^/err: /g' err_eff)
|
||||||
|
|
||||||
if test $sta_eff -eq $sta_exp; then
|
if test $sta_eff -eq $sta_exp; then
|
||||||
if test "$out_eff" = "$out_exp"; then
|
if test "$out_eff" = "$out_exp"; then
|
||||||
echo "$me: PASS: $number"
|
echo "$me: PASS: $number"
|
||||||
else
|
else
|
||||||
echo "$me: FAIL: $number (expected output: $out_exp, effective: $out_eff)"
|
echo "$me: FAIL: $number"
|
||||||
cat err_eff
|
echo "$me: input:"
|
||||||
|
sed -e 's/^/ /' input
|
||||||
|
echo "$me: expected output:"
|
||||||
|
echo "$out_exp" | sed -e 's/^/ /'
|
||||||
|
echo "$me: effective output:"
|
||||||
|
echo "$out_eff" | sed -e 's/^/ /'
|
||||||
exit=false
|
exit=false
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|||||||
+1
-1
Submodule gnulib updated: d279bc6d9f...64e1ff019f
+4
-1
@@ -58,7 +58,6 @@
|
|||||||
/dirname-lgpl.c
|
/dirname-lgpl.c
|
||||||
/dirname.c
|
/dirname.c
|
||||||
/dirname.h
|
/dirname.h
|
||||||
/dosname.h
|
|
||||||
/dup-safer-flag.c
|
/dup-safer-flag.c
|
||||||
/dup-safer.c
|
/dup-safer.c
|
||||||
/dup2.c
|
/dup2.c
|
||||||
@@ -96,9 +95,11 @@
|
|||||||
/fstrcmp.c
|
/fstrcmp.c
|
||||||
/fstrcmp.h
|
/fstrcmp.h
|
||||||
/fsync.c
|
/fsync.c
|
||||||
|
/getdelim.c
|
||||||
/getdtablesize.c
|
/getdtablesize.c
|
||||||
/gethrxtime.c
|
/gethrxtime.c
|
||||||
/gethrxtime.h
|
/gethrxtime.h
|
||||||
|
/getline.c
|
||||||
/getopt-cdefs.h
|
/getopt-cdefs.h
|
||||||
/getopt-cdefs.in.h
|
/getopt-cdefs.in.h
|
||||||
/getopt-core.h
|
/getopt-core.h
|
||||||
@@ -206,6 +207,8 @@
|
|||||||
/raise.c
|
/raise.c
|
||||||
/rawmemchr.c
|
/rawmemchr.c
|
||||||
/rawmemchr.valgrind
|
/rawmemchr.valgrind
|
||||||
|
/readline.c
|
||||||
|
/readline.h
|
||||||
/readlink.c
|
/readlink.c
|
||||||
/realloc.c
|
/realloc.c
|
||||||
/ref-add.sed
|
/ref-add.sed
|
||||||
|
|||||||
@@ -38,8 +38,10 @@
|
|||||||
/fseterr.m4
|
/fseterr.m4
|
||||||
/fstat.m4
|
/fstat.m4
|
||||||
/fsync.m4
|
/fsync.m4
|
||||||
|
/getdelim.m4
|
||||||
/getdtablesize.m4
|
/getdtablesize.m4
|
||||||
/gethrxtime.m4
|
/gethrxtime.m4
|
||||||
|
/getline.m4
|
||||||
/getopt.m4
|
/getopt.m4
|
||||||
/getprogname.m4
|
/getprogname.m4
|
||||||
/getrusage.m4
|
/getrusage.m4
|
||||||
@@ -136,6 +138,7 @@
|
|||||||
/quotearg.m4
|
/quotearg.m4
|
||||||
/raise.m4
|
/raise.m4
|
||||||
/rawmemchr.m4
|
/rawmemchr.m4
|
||||||
|
/readline.m4
|
||||||
/readlink.m4
|
/readlink.m4
|
||||||
/realloc.m4
|
/realloc.m4
|
||||||
/relocatable-lib.m4
|
/relocatable-lib.m4
|
||||||
|
|||||||
+100
-59
@@ -23,6 +23,7 @@
|
|||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
#include <argmatch.h>
|
#include <argmatch.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <progname.h>
|
#include <progname.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -41,9 +42,9 @@ bool warnings_are_errors = false;
|
|||||||
/** Whether -Werror/-Wno-error was applied to a warning. */
|
/** Whether -Werror/-Wno-error was applied to a warning. */
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
errority_unset = 0, /** No explict status. */
|
errority_unset = 0, /** No explicit status. */
|
||||||
errority_disabled = 1, /** Explictly disabled with -Wno-error=foo. */
|
errority_disabled = 1, /** Explicitly disabled with -Wno-error=foo. */
|
||||||
errority_enabled = 2 /** Explictly enabled with -Werror=foo. */
|
errority_enabled = 2 /** Explicitly enabled with -Werror=foo. */
|
||||||
} errority;
|
} errority;
|
||||||
|
|
||||||
/** For each warning type, its errority. */
|
/** For each warning type, its errority. */
|
||||||
@@ -263,6 +264,20 @@ severity_prefix (severity s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
severity_print (severity s, FILE *out)
|
||||||
|
{
|
||||||
|
if (s != severity_disabled)
|
||||||
|
{
|
||||||
|
const char* style = severity_style (s);
|
||||||
|
begin_use_class (style, out);
|
||||||
|
fprintf (out, "%s:", severity_prefix (s));
|
||||||
|
end_use_class (style, out);
|
||||||
|
fputc (' ', out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-----------.
|
/*-----------.
|
||||||
| complain. |
|
| complain. |
|
||||||
`-----------*/
|
`-----------*/
|
||||||
@@ -409,7 +424,6 @@ warnings_print_categories (warnings warn_flags, FILE *out)
|
|||||||
*
|
*
|
||||||
* \param loc the location, defaulting to the current file,
|
* \param loc the location, defaulting to the current file,
|
||||||
* or the program name.
|
* or the program name.
|
||||||
* \param indent optional indentation for the error message.
|
|
||||||
* \param flags the category for this message.
|
* \param flags the category for this message.
|
||||||
* \param sever to decide the prefix to put before the message
|
* \param sever to decide the prefix to put before the message
|
||||||
* (e.g., "warning").
|
* (e.g., "warning").
|
||||||
@@ -421,33 +435,21 @@ warnings_print_categories (warnings warn_flags, FILE *out)
|
|||||||
*/
|
*/
|
||||||
static
|
static
|
||||||
void
|
void
|
||||||
error_message (const location *loc, int *indent, warnings flags,
|
error_message (const location *loc, warnings flags,
|
||||||
severity sever, const char *message, va_list args)
|
severity sever, const char *message, va_list args)
|
||||||
{
|
{
|
||||||
int pos = 0;
|
const char* style = flags & note ? "note" : severity_style (sever);
|
||||||
|
|
||||||
if (loc)
|
if (loc)
|
||||||
pos += location_print (*loc, stderr);
|
location_print (*loc, stderr);
|
||||||
else
|
else
|
||||||
pos += fprintf (stderr, "%s", grammar_file ? grammar_file : program_name);
|
fprintf (stderr, "%s", grammar_file ? grammar_file : program_name);
|
||||||
pos += fprintf (stderr, ": ");
|
fprintf (stderr, ": ");
|
||||||
|
|
||||||
if (indent)
|
|
||||||
{
|
|
||||||
if (*indent)
|
|
||||||
sever = severity_disabled;
|
|
||||||
if (!*indent)
|
|
||||||
*indent = pos;
|
|
||||||
else if (*indent > pos)
|
|
||||||
fprintf (stderr, "%*s", *indent - pos, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* style = severity_style (sever);
|
|
||||||
|
|
||||||
if (sever != severity_disabled)
|
if (sever != severity_disabled)
|
||||||
{
|
{
|
||||||
begin_use_class (style, stderr);
|
begin_use_class (style, stderr);
|
||||||
fprintf (stderr, "%s:", severity_prefix (sever));
|
fprintf (stderr, "%s:", flags & note ? _("note") : severity_prefix (sever));
|
||||||
end_use_class (style, stderr);
|
end_use_class (style, stderr);
|
||||||
fputc (' ', stderr);
|
fputc (' ', stderr);
|
||||||
}
|
}
|
||||||
@@ -458,34 +460,32 @@ error_message (const location *loc, int *indent, warnings flags,
|
|||||||
if (! (flags & silent) && sever != severity_disabled)
|
if (! (flags & silent) && sever != severity_disabled)
|
||||||
warnings_print_categories (flags, stderr);
|
warnings_print_categories (flags, stderr);
|
||||||
|
|
||||||
{
|
size_t l = strlen (message);
|
||||||
size_t l = strlen (message);
|
if (l < 2 || message[l - 2] != ':' || message[l - 1] != ' ')
|
||||||
if (l < 2 || message[l - 2] != ':' || message[l - 1] != ' ')
|
{
|
||||||
{
|
putc ('\n', stderr);
|
||||||
putc ('\n', stderr);
|
flush (stderr);
|
||||||
flush (stderr);
|
if (loc && !(flags & no_caret))
|
||||||
if (loc && feature_flag & feature_caret && !(flags & no_caret))
|
location_caret (*loc, style, stderr);
|
||||||
location_caret (*loc, style, stderr);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
flush (stderr);
|
flush (stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Raise a complaint (fatal error, error or just warning). */
|
/** Raise a complaint (fatal error, error or just warning). */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
complains (const location *loc, int *indent, warnings flags,
|
complains (const location *loc, warnings flags,
|
||||||
const char *message, va_list args)
|
const char *message, va_list args)
|
||||||
{
|
{
|
||||||
severity s = warning_severity (flags);
|
|
||||||
if ((flags & complaint) && complaint_status < status_complaint)
|
if ((flags & complaint) && complaint_status < status_complaint)
|
||||||
complaint_status = status_complaint;
|
complaint_status = status_complaint;
|
||||||
|
|
||||||
|
severity s = warning_severity (flags);
|
||||||
if (severity_warning <= s)
|
if (severity_warning <= s)
|
||||||
{
|
{
|
||||||
if (severity_error <= s && ! complaint_status)
|
if (severity_error <= s && ! complaint_status)
|
||||||
complaint_status = status_warning_as_error;
|
complaint_status = status_warning_as_error;
|
||||||
error_message (loc, indent, flags, s, message, args);
|
error_message (loc, flags, s, message, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & fatal)
|
if (flags & fatal)
|
||||||
@@ -497,41 +497,39 @@ complain (location const *loc, warnings flags, const char *message, ...)
|
|||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start (args, message);
|
va_start (args, message);
|
||||||
complains (loc, NULL, flags, message, args);
|
complains (loc, flags, message, args);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
complain_indent (location const *loc, warnings flags, int *indent,
|
subcomplain (location const *loc, warnings flags, const char *message, ...)
|
||||||
const char *message, ...)
|
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start (args, message);
|
va_start (args, message);
|
||||||
complains (loc, indent, flags, message, args);
|
complains (loc, flags | note | silent, message, args);
|
||||||
va_end (args);
|
va_end (args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
complain_args (location const *loc, warnings w, int *indent,
|
complain_args (location const *loc, warnings w,
|
||||||
int argc, char *argv[])
|
int argc, char *argv[])
|
||||||
{
|
{
|
||||||
switch (argc)
|
switch (argc)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
complain_indent (loc, w, indent, "%s", _(argv[0]));
|
complain (loc, w, "%s", _(argv[0]));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
complain_indent (loc, w, indent, _(argv[0]), argv[1]);
|
complain (loc, w, _(argv[0]), argv[1]);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
complain_indent (loc, w, indent, _(argv[0]), argv[1], argv[2]);
|
complain (loc, w, _(argv[0]), argv[1], argv[2]);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
complain_indent (loc, w, indent, _(argv[0]), argv[1], argv[2], argv[3]);
|
complain (loc, w, _(argv[0]), argv[1], argv[2], argv[3]);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
complain_indent (loc, w, indent, _(argv[0]), argv[1], argv[2], argv[3],
|
complain (loc, w, _(argv[0]), argv[1], argv[2], argv[3], argv[4]);
|
||||||
argv[4]);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
complain (loc, fatal, "too many arguments for complains");
|
complain (loc, fatal, "too many arguments for complains");
|
||||||
@@ -555,8 +553,7 @@ deprecated_directive (location const *loc, char const *old, char const *upd)
|
|||||||
complain (loc, Wdeprecated,
|
complain (loc, Wdeprecated,
|
||||||
_("deprecated directive: %s, use %s"),
|
_("deprecated directive: %s, use %s"),
|
||||||
quote (old), quote_n (1, upd));
|
quote (old), quote_n (1, upd));
|
||||||
if (feature_flag & feature_caret)
|
location_caret_suggestion (*loc, upd, stderr);
|
||||||
location_caret_suggestion (*loc, upd, stderr);
|
|
||||||
/* Register updates only if -Wdeprecated is enabled. */
|
/* Register updates only if -Wdeprecated is enabled. */
|
||||||
fixits_register (loc, upd);
|
fixits_register (loc, upd);
|
||||||
}
|
}
|
||||||
@@ -566,13 +563,11 @@ void
|
|||||||
duplicate_directive (char const *directive,
|
duplicate_directive (char const *directive,
|
||||||
location first, location second)
|
location first, location second)
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
if (feature_flag & feature_caret)
|
if (feature_flag & feature_caret)
|
||||||
complain_indent (&second, Wother, &i, _("duplicate directive"));
|
complain (&second, Wother, _("duplicate directive"));
|
||||||
else
|
else
|
||||||
complain_indent (&second, Wother, &i, _("duplicate directive: %s"), quote (directive));
|
complain (&second, Wother, _("duplicate directive: %s"), quote (directive));
|
||||||
i += SUB_INDENT;
|
subcomplain (&first, Wother, _("previous declaration"));
|
||||||
complain_indent (&first, Wother, &i, _("previous declaration"));
|
|
||||||
fixits_register (&second, "");
|
fixits_register (&second, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,11 +575,57 @@ void
|
|||||||
duplicate_rule_directive (char const *directive,
|
duplicate_rule_directive (char const *directive,
|
||||||
location first, location second)
|
location first, location second)
|
||||||
{
|
{
|
||||||
int i = 0;
|
complain (&second, complaint, _("only one %s allowed per rule"), directive);
|
||||||
complain_indent (&second, complaint, &i,
|
subcomplain (&first, complaint, _("previous declaration"));
|
||||||
_("only one %s allowed per rule"), directive);
|
|
||||||
i += SUB_INDENT;
|
|
||||||
complain_indent (&first, complaint, &i,
|
|
||||||
_("previous declaration"));
|
|
||||||
fixits_register (&second, "");
|
fixits_register (&second, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
syntax_error (location loc,
|
||||||
|
int argc, const char* argv[])
|
||||||
|
{
|
||||||
|
if (complaint_status < status_complaint)
|
||||||
|
complaint_status = status_complaint;
|
||||||
|
assert (argc <= 5);
|
||||||
|
const char *format = NULL;
|
||||||
|
switch (argc)
|
||||||
|
{
|
||||||
|
#define CASE(N, S) \
|
||||||
|
case N: \
|
||||||
|
format = S; \
|
||||||
|
break
|
||||||
|
default: /* Avoid compiler warnings. */
|
||||||
|
CASE (0, _("syntax error"));
|
||||||
|
CASE (1, _("unexpected %0$s"));
|
||||||
|
CASE (2, _("expected %1$s before %0$s"));
|
||||||
|
CASE (3, _("expected %1$s or %2$s before %0$s"));
|
||||||
|
CASE (4, _("expected %1$s or %2$s or %3$s before %0$s"));
|
||||||
|
CASE (5, _("expected %1$s or %2$s or %4$s or %5$s before %0$s"));
|
||||||
|
#undef CASE
|
||||||
|
}
|
||||||
|
location_print (loc, stderr);
|
||||||
|
fputs (": ", stderr);
|
||||||
|
severity_print (severity_error, stderr);
|
||||||
|
|
||||||
|
while (*format)
|
||||||
|
if (format[0] == '%'
|
||||||
|
&& isdigit (format[1])
|
||||||
|
&& format[2] == '$'
|
||||||
|
&& format[3] == 's'
|
||||||
|
&& (format[1] - '0') < argc)
|
||||||
|
{
|
||||||
|
int i = format[1] - '0';
|
||||||
|
const char *style = i == 0 ? "unexpected" : "expected";
|
||||||
|
begin_use_class (style, stderr);
|
||||||
|
fputs (argv[i], stderr);
|
||||||
|
end_use_class (style, stderr);
|
||||||
|
format += 4;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fputc (*format, stderr);
|
||||||
|
++format;
|
||||||
|
}
|
||||||
|
fputc ('\n', stderr);
|
||||||
|
location_caret (loc, "error", stderr);
|
||||||
|
}
|
||||||
|
|||||||
+11
-8
@@ -21,9 +21,6 @@
|
|||||||
|
|
||||||
# include "location.h"
|
# include "location.h"
|
||||||
|
|
||||||
/* Sub-messages indent. */
|
|
||||||
# define SUB_INDENT (4)
|
|
||||||
|
|
||||||
/*---------------.
|
/*---------------.
|
||||||
| Error stream. |
|
| Error stream. |
|
||||||
`---------------*/
|
`---------------*/
|
||||||
@@ -119,6 +116,7 @@ typedef enum
|
|||||||
fatal = 1 << 12, /**< All fatal errors. */
|
fatal = 1 << 12, /**< All fatal errors. */
|
||||||
silent = 1 << 13, /**< Do not display the warning type. */
|
silent = 1 << 13, /**< Do not display the warning type. */
|
||||||
no_caret = 1 << 14, /**< Do not display caret location. */
|
no_caret = 1 << 14, /**< Do not display caret location. */
|
||||||
|
note = 1 << 15, /**< Display as a note. */
|
||||||
|
|
||||||
/**< All above warnings. */
|
/**< All above warnings. */
|
||||||
Weverything = ~complaint & ~fatal & ~silent,
|
Weverything = ~complaint & ~fatal & ~silent,
|
||||||
@@ -137,13 +135,13 @@ void complain (location const *loc, warnings flags, char const *message, ...)
|
|||||||
__attribute__ ((__format__ (__printf__, 3, 4)));
|
__attribute__ ((__format__ (__printf__, 3, 4)));
|
||||||
|
|
||||||
/** Likewise, but with an \a argc/argv interface. */
|
/** Likewise, but with an \a argc/argv interface. */
|
||||||
void complain_args (location const *loc, warnings w, int *indent,
|
void complain_args (location const *loc, warnings w,
|
||||||
int argc, char *arg[]);
|
int argc, char *arg[]);
|
||||||
|
|
||||||
/** Make a complaint with location and some indentation. */
|
/** Make a subcomplain with location and note. */
|
||||||
void complain_indent (location const *loc, warnings flags, int *indent,
|
void subcomplain (location const *loc, warnings flags,
|
||||||
char const *message, ...)
|
char const *message, ...)
|
||||||
__attribute__ ((__format__ (__printf__, 4, 5)));
|
__attribute__ ((__format__ (__printf__, 3, 4)));
|
||||||
|
|
||||||
|
|
||||||
/** GNU Bison extension not valid with POSIX Yacc. */
|
/** GNU Bison extension not valid with POSIX Yacc. */
|
||||||
@@ -161,6 +159,11 @@ void duplicate_directive (char const *directive,
|
|||||||
void duplicate_rule_directive (char const *directive,
|
void duplicate_rule_directive (char const *directive,
|
||||||
location first, location second);
|
location first, location second);
|
||||||
|
|
||||||
|
/** Report a syntax error, where argv[0] is the unexpected
|
||||||
|
token, and argv[1...argc] are the expected ones. */
|
||||||
|
void syntax_error (location loc,
|
||||||
|
int argc, const char* argv[]);
|
||||||
|
|
||||||
/** Warnings treated as errors shouldn't stop the execution as regular
|
/** Warnings treated as errors shouldn't stop the execution as regular
|
||||||
errors should (because due to their nature, it is safe to go
|
errors should (because due to their nature, it is safe to go
|
||||||
on). Thus, there are three possible execution statuses. */
|
on). Thus, there are three possible execution statuses. */
|
||||||
|
|||||||
@@ -402,6 +402,8 @@ caret_set_column (int col)
|
|||||||
void
|
void
|
||||||
location_caret (location loc, const char *style, FILE *out)
|
location_caret (location loc, const char *style, FILE *out)
|
||||||
{
|
{
|
||||||
|
if (!(feature_flag & feature_caret))
|
||||||
|
return;
|
||||||
if (!loc.start.line)
|
if (!loc.start.line)
|
||||||
return;
|
return;
|
||||||
if (!caret_set_file (loc.start.file))
|
if (!caret_set_file (loc.start.file))
|
||||||
@@ -500,6 +502,8 @@ location_caret (location loc, const char *style, FILE *out)
|
|||||||
void
|
void
|
||||||
location_caret_suggestion (location loc, const char *s, FILE *out)
|
location_caret_suggestion (location loc, const char *s, FILE *out)
|
||||||
{
|
{
|
||||||
|
if (!(feature_flag & feature_caret))
|
||||||
|
return;
|
||||||
const char *style = "fixit-insert";
|
const char *style = "fixit-insert";
|
||||||
fprintf (out, " | %*s",
|
fprintf (out, " | %*s",
|
||||||
loc.start.column - 1 - caret_info.skip
|
loc.start.column - 1 - caret_info.skip
|
||||||
|
|||||||
+4
-4
@@ -124,12 +124,12 @@ void caret_init (void);
|
|||||||
left-over by the usage of location_caret. */
|
left-over by the usage of location_caret. */
|
||||||
void caret_free (void);
|
void caret_free (void);
|
||||||
|
|
||||||
/* Quote the line containing LOC onto OUT. Highlight the part of LOC
|
/* If -fcaret is enabled, quote the line containing LOC onto OUT.
|
||||||
with the color STYLE. */
|
Highlight the part of LOC with the color STYLE. */
|
||||||
void location_caret (location loc, const char* style, FILE *out);
|
void location_caret (location loc, const char* style, FILE *out);
|
||||||
|
|
||||||
/* Display a suggestion of replacement for LOC with S. To call after
|
/* If -fcaret is enabled, display a suggestion of replacement for LOC
|
||||||
location_caret. */
|
with S. To call after location_caret. */
|
||||||
void location_caret_suggestion (location loc, const char *s, FILE *out);
|
void location_caret_suggestion (location loc, const char *s, FILE *out);
|
||||||
|
|
||||||
/* Return -1, 0, 1, depending whether a is before, equal, or
|
/* Return -1, 0, 1, depending whether a is before, equal, or
|
||||||
|
|||||||
+9
-13
@@ -524,15 +524,13 @@ muscle_percent_define_insert (char const *var, location variable_loc,
|
|||||||
= atoi (muscle_find_const (how_name));
|
= atoi (muscle_find_const (how_name));
|
||||||
if (how_old == MUSCLE_PERCENT_DEFINE_F)
|
if (how_old == MUSCLE_PERCENT_DEFINE_F)
|
||||||
goto end;
|
goto end;
|
||||||
int i = 0;
|
|
||||||
/* If assigning the same value, make it a warning. */
|
/* If assigning the same value, make it a warning. */
|
||||||
warnings warn = STREQ (value, current_value) ? Wother : complaint;
|
warnings warn = STREQ (value, current_value) ? Wother : complaint;
|
||||||
complain_indent (&variable_loc, warn, &i,
|
complain (&variable_loc, warn,
|
||||||
_("%%define variable %s redefined"),
|
_("%%define variable %s redefined"),
|
||||||
quote (variable));
|
quote (variable));
|
||||||
i += SUB_INDENT;
|
|
||||||
location loc = muscle_percent_define_get_loc (variable);
|
location loc = muscle_percent_define_get_loc (variable);
|
||||||
complain_indent (&loc, warn, &i, _("previous definition"));
|
subcomplain (&loc, warn, _("previous definition"));
|
||||||
fixits_register (&variable_loc, "");
|
fixits_register (&variable_loc, "");
|
||||||
warned = true;
|
warned = true;
|
||||||
}
|
}
|
||||||
@@ -738,14 +736,12 @@ muscle_percent_define_check_values (char const * const *values)
|
|||||||
if (!*values)
|
if (!*values)
|
||||||
{
|
{
|
||||||
location loc = muscle_percent_define_get_loc (*variablep);
|
location loc = muscle_percent_define_get_loc (*variablep);
|
||||||
int i = 0;
|
complain (&loc, complaint,
|
||||||
complain_indent (&loc, complaint, &i,
|
_("invalid value for %%define variable %s: %s"),
|
||||||
_("invalid value for %%define variable %s: %s"),
|
quote (*variablep), quote_n (1, value));
|
||||||
quote (*variablep), quote_n (1, value));
|
|
||||||
i += SUB_INDENT;
|
|
||||||
for (values = variablep + 1; *values; ++values)
|
for (values = variablep + 1; *values; ++values)
|
||||||
complain_indent (&loc, complaint | no_caret | silent, &i,
|
subcomplain (&loc, complaint | no_caret | silent,
|
||||||
_("accepted value: %s"), quote (*values));
|
_("accepted value: %s"), quote (*values));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
while (*values)
|
while (*values)
|
||||||
|
|||||||
+137
-13
@@ -50,6 +50,10 @@ static struct obstack format_obstack;
|
|||||||
| result of formatting the FIRST and then TABLE_DATA[BEGIN..END[ (of |
|
| result of formatting the FIRST and then TABLE_DATA[BEGIN..END[ (of |
|
||||||
| TYPE), and to the muscle NAME_max, the max value of the |
|
| TYPE), and to the muscle NAME_max, the max value of the |
|
||||||
| TABLE_DATA. |
|
| TABLE_DATA. |
|
||||||
|
| |
|
||||||
|
| For the typical case of outputting a complete table from 0, pass |
|
||||||
|
| TABLE[0] as FIRST, and 1 as BEGIN. For instance |
|
||||||
|
| muscle_insert_base_table ("pact", base, base[0], 1, nstates); |
|
||||||
`-------------------------------------------------------------------*/
|
`-------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
@@ -132,42 +136,145 @@ string_output (FILE *out, char const *string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Store in BUFFER a copy of SRC where trigraphs are escaped, return
|
||||||
|
the size of the result (including the final NUL). If called with
|
||||||
|
BUFFERSIZE = 0, returns the needed size for BUFFER. */
|
||||||
|
static ptrdiff_t
|
||||||
|
escape_trigraphs (char *buffer, ptrdiff_t buffersize, const char *src)
|
||||||
|
{
|
||||||
|
#define STORE(c) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
if (res < buffersize) \
|
||||||
|
buffer[res] = (c); \
|
||||||
|
++res; \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
ptrdiff_t res = 0;
|
||||||
|
for (ptrdiff_t i = 0, len = strlen (src); i < len; ++i)
|
||||||
|
{
|
||||||
|
if (i + 2 < len
|
||||||
|
&& src[i] == '?' && src[i+1] == '?')
|
||||||
|
{
|
||||||
|
switch (src[i+2])
|
||||||
|
{
|
||||||
|
case '!': case '\'':
|
||||||
|
case '(': case ')': case '-': case '/':
|
||||||
|
case '<': case '=': case '>':
|
||||||
|
i += 1;
|
||||||
|
STORE ('?');
|
||||||
|
STORE ('"');
|
||||||
|
STORE ('"');
|
||||||
|
STORE ('?');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
STORE (src[i]);
|
||||||
|
}
|
||||||
|
STORE ('\0');
|
||||||
|
#undef STORE
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Same as xstrdup, except that trigraphs are escaped. */
|
||||||
|
static char *
|
||||||
|
xescape_trigraphs (const char *src)
|
||||||
|
{
|
||||||
|
ptrdiff_t bufsize = escape_trigraphs (NULL, 0, src);
|
||||||
|
char *buf = xcharalloc (bufsize);
|
||||||
|
escape_trigraphs (buf, bufsize, src);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Whether some symbol requires internationalization. */
|
||||||
|
static bool
|
||||||
|
has_translations (void)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < nsyms; i++)
|
||||||
|
if (symbols[i]->translatable)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The tag to show in the generated parsers. Use "end of file" rather
|
||||||
|
than "$end". But keep "$end" in the reports, it's shorter and more
|
||||||
|
consistent. Support i18n if the user already uses it. */
|
||||||
|
static const char *
|
||||||
|
symbol_tag (const symbol *sym)
|
||||||
|
{
|
||||||
|
const bool eof_is_user_defined
|
||||||
|
= !endtoken->alias || STRNEQ (endtoken->alias->tag, "$end");
|
||||||
|
|
||||||
|
if (!eof_is_user_defined && sym->content == endtoken->content)
|
||||||
|
return "\"end of file\"";
|
||||||
|
else if (sym->content == undeftoken->content)
|
||||||
|
return "\"invalid token\"";
|
||||||
|
else
|
||||||
|
return sym->tag;
|
||||||
|
}
|
||||||
|
|
||||||
/* Generate the b4_<MUSCLE_NAME> (e.g., b4_tname) table with the
|
/* Generate the b4_<MUSCLE_NAME> (e.g., b4_tname) table with the
|
||||||
symbol names (aka tags). */
|
symbol names (aka tags). */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
prepare_symbol_names (char const *muscle_name)
|
prepare_symbol_names (char const *muscle_name)
|
||||||
{
|
{
|
||||||
|
const bool eof_is_user_defined
|
||||||
|
= !endtoken->alias || STRNEQ (endtoken->alias->tag, "$end");
|
||||||
|
|
||||||
|
const bool quote = STREQ (muscle_name, "tname");
|
||||||
|
const bool with_translations = !quote && has_translations ();
|
||||||
|
|
||||||
/* We assume that the table will be output starting at column 2. */
|
/* We assume that the table will be output starting at column 2. */
|
||||||
int j = 2;
|
int col = 2;
|
||||||
struct quoting_options *qo = clone_quoting_options (0);
|
struct quoting_options *qo = clone_quoting_options (0);
|
||||||
set_quoting_style (qo, c_quoting_style);
|
set_quoting_style (qo, c_quoting_style);
|
||||||
set_quoting_flags (qo, QA_SPLIT_TRIGRAPHS);
|
set_quoting_flags (qo, QA_SPLIT_TRIGRAPHS);
|
||||||
for (int i = 0; i < nsyms; i++)
|
for (int i = 0; i < nsyms; i++)
|
||||||
{
|
{
|
||||||
char *cp = quotearg_alloc (symbols[i]->tag, -1, qo);
|
const char *tag = symbol_tag (symbols[i]);
|
||||||
|
bool translatable =
|
||||||
|
with_translations
|
||||||
|
&& (symbols[i]->translatable
|
||||||
|
|| (!eof_is_user_defined && symbols[i]->content == endtoken->content)
|
||||||
|
|| symbols[i]->content == undeftoken->content);
|
||||||
|
|
||||||
|
char *cp
|
||||||
|
= tag[0] == '"' && !quote
|
||||||
|
? xescape_trigraphs (tag)
|
||||||
|
: quotearg_alloc (tag, -1, qo);
|
||||||
/* Width of the next token, including the two quotes, the
|
/* Width of the next token, including the two quotes, the
|
||||||
comma and the space. */
|
comma and the space. */
|
||||||
int width = strlen (cp) + 2;
|
int width
|
||||||
|
= strlen (cp) + 2
|
||||||
|
+ (translatable ? strlen ("N_()") : 0);
|
||||||
|
|
||||||
if (j + width > 75)
|
if (col + width > 75)
|
||||||
{
|
{
|
||||||
obstack_sgrow (&format_obstack, "\n ");
|
obstack_sgrow (&format_obstack, "\n ");
|
||||||
j = 1;
|
col = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i)
|
if (i)
|
||||||
obstack_1grow (&format_obstack, ' ');
|
obstack_1grow (&format_obstack, ' ');
|
||||||
|
if (translatable)
|
||||||
|
obstack_sgrow (&format_obstack, "]b4_symbol_translate([");
|
||||||
obstack_escape (&format_obstack, cp);
|
obstack_escape (&format_obstack, cp);
|
||||||
|
if (translatable)
|
||||||
|
obstack_sgrow (&format_obstack, "])[");
|
||||||
free (cp);
|
free (cp);
|
||||||
obstack_1grow (&format_obstack, ',');
|
obstack_1grow (&format_obstack, ',');
|
||||||
j += width;
|
col += width;
|
||||||
}
|
}
|
||||||
free (qo);
|
free (qo);
|
||||||
obstack_sgrow (&format_obstack, " ]b4_null[");
|
obstack_sgrow (&format_obstack, " ]b4_null[");
|
||||||
|
|
||||||
/* Finish table and store. */
|
/* Finish table and store. */
|
||||||
muscle_insert (muscle_name, obstack_finish0 (&format_obstack));
|
muscle_insert (muscle_name, obstack_finish0 (&format_obstack));
|
||||||
|
|
||||||
|
/* Announce whether translation support is needed. */
|
||||||
|
if (!quote)
|
||||||
|
MUSCLE_INSERT_BOOL ("has_translations", with_translations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -182,7 +289,6 @@ prepare_symbols (void)
|
|||||||
MUSCLE_INSERT_INT ("tokens_number", ntokens);
|
MUSCLE_INSERT_INT ("tokens_number", ntokens);
|
||||||
MUSCLE_INSERT_INT ("nterms_number", nvars);
|
MUSCLE_INSERT_INT ("nterms_number", nvars);
|
||||||
MUSCLE_INSERT_INT ("symbols_number", nsyms);
|
MUSCLE_INSERT_INT ("symbols_number", nsyms);
|
||||||
MUSCLE_INSERT_INT ("undef_token_number", undeftoken->content->number);
|
|
||||||
MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number);
|
MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number);
|
||||||
|
|
||||||
muscle_insert_symbol_number_table ("translate",
|
muscle_insert_symbol_number_table ("translate",
|
||||||
@@ -192,6 +298,27 @@ prepare_symbols (void)
|
|||||||
|
|
||||||
/* tname -- token names. */
|
/* tname -- token names. */
|
||||||
prepare_symbol_names ("tname");
|
prepare_symbol_names ("tname");
|
||||||
|
prepare_symbol_names ("symbol_names");
|
||||||
|
|
||||||
|
/* translatable -- whether a token is translatable. */
|
||||||
|
{
|
||||||
|
bool translatable = false;
|
||||||
|
for (int i = 0; i < ntokens; ++i)
|
||||||
|
if (symbols[i]->translatable)
|
||||||
|
{
|
||||||
|
translatable = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (translatable)
|
||||||
|
{
|
||||||
|
int *values = xnmalloc (nsyms, sizeof *values);
|
||||||
|
for (int i = 0; i < ntokens; ++i)
|
||||||
|
values[i] = symbols[i]->translatable;
|
||||||
|
muscle_insert_int_table ("translatable", values,
|
||||||
|
values[0], 1, ntokens);
|
||||||
|
free (values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Output YYTOKNUM. */
|
/* Output YYTOKNUM. */
|
||||||
{
|
{
|
||||||
@@ -451,14 +578,13 @@ prepare_symbol_definitions (void)
|
|||||||
|
|
||||||
/* Its tag. Typically for documentation purpose. */
|
/* Its tag. Typically for documentation purpose. */
|
||||||
SET_KEY ("tag");
|
SET_KEY ("tag");
|
||||||
MUSCLE_INSERT_STRING (key, sym->tag);
|
MUSCLE_INSERT_STRING (key, symbol_tag (sym));
|
||||||
|
|
||||||
SET_KEY ("user_number");
|
SET_KEY ("user_number");
|
||||||
MUSCLE_INSERT_INT (key, sym->content->user_token_number);
|
MUSCLE_INSERT_INT (key, sym->content->user_token_number);
|
||||||
|
|
||||||
SET_KEY ("is_token");
|
SET_KEY ("is_token");
|
||||||
MUSCLE_INSERT_INT (key,
|
MUSCLE_INSERT_INT (key, i < ntokens);
|
||||||
i < ntokens && sym != errtoken && sym != undeftoken);
|
|
||||||
|
|
||||||
SET_KEY ("number");
|
SET_KEY ("number");
|
||||||
MUSCLE_INSERT_INT (key, sym->content->number);
|
MUSCLE_INSERT_INT (key, sym->content->number);
|
||||||
@@ -504,9 +630,7 @@ prepare_symbol_definitions (void)
|
|||||||
static void
|
static void
|
||||||
prepare_actions (void)
|
prepare_actions (void)
|
||||||
{
|
{
|
||||||
/* Figure out the actions for the specified state, indexed by
|
/* Figure out the actions for the specified state. */
|
||||||
lookahead token type. */
|
|
||||||
|
|
||||||
muscle_insert_rule_number_table ("defact", yydefact,
|
muscle_insert_rule_number_table ("defact", yydefact,
|
||||||
yydefact[0], 1, nstates);
|
yydefact[0], 1, nstates);
|
||||||
|
|
||||||
|
|||||||
+653
-677
File diff suppressed because it is too large
Load Diff
+107
-142
@@ -1,4 +1,4 @@
|
|||||||
/* A Bison parser, made by GNU Bison 3.5.2. */
|
/* A Bison parser, made by GNU Bison 3.5.4.236-8d75. */
|
||||||
|
|
||||||
/* Bison interface for Yacc-like parsers in C
|
/* Bison interface for Yacc-like parsers in C
|
||||||
|
|
||||||
@@ -72,159 +72,124 @@ extern int gram_debug;
|
|||||||
} value_type;
|
} value_type;
|
||||||
|
|
||||||
|
|
||||||
/* Token type. */
|
/* Token kinds. */
|
||||||
#ifndef GRAM_TOKENTYPE
|
#ifndef GRAM_TOKENTYPE
|
||||||
# define GRAM_TOKENTYPE
|
# define GRAM_TOKENTYPE
|
||||||
enum gram_tokentype
|
enum gram_tokentype
|
||||||
{
|
{
|
||||||
GRAM_EOF = 0,
|
GRAM_EMPTY = -2,
|
||||||
STRING = 3,
|
GRAM_EOF = 0, /* "end of file" */
|
||||||
PERCENT_TOKEN = 4,
|
GRAM_ERRCODE = 1, /* error */
|
||||||
PERCENT_NTERM = 5,
|
GRAM_UNDEF = 2, /* "invalid token" */
|
||||||
PERCENT_TYPE = 6,
|
STRING = 3, /* "string" */
|
||||||
PERCENT_DESTRUCTOR = 7,
|
TSTRING = 4, /* "translatable string" */
|
||||||
PERCENT_PRINTER = 8,
|
PERCENT_TOKEN = 5, /* "%token" */
|
||||||
PERCENT_LEFT = 9,
|
PERCENT_NTERM = 6, /* "%nterm" */
|
||||||
PERCENT_RIGHT = 10,
|
PERCENT_TYPE = 7, /* "%type" */
|
||||||
PERCENT_NONASSOC = 11,
|
PERCENT_DESTRUCTOR = 8, /* "%destructor" */
|
||||||
PERCENT_PRECEDENCE = 12,
|
PERCENT_PRINTER = 9, /* "%printer" */
|
||||||
PERCENT_PREC = 13,
|
PERCENT_LEFT = 10, /* "%left" */
|
||||||
PERCENT_DPREC = 14,
|
PERCENT_RIGHT = 11, /* "%right" */
|
||||||
PERCENT_MERGE = 15,
|
PERCENT_NONASSOC = 12, /* "%nonassoc" */
|
||||||
PERCENT_CODE = 16,
|
PERCENT_PRECEDENCE = 13, /* "%precedence" */
|
||||||
PERCENT_DEFAULT_PREC = 17,
|
PERCENT_PREC = 14, /* "%prec" */
|
||||||
PERCENT_DEFINE = 18,
|
PERCENT_DPREC = 15, /* "%dprec" */
|
||||||
PERCENT_DEFINES = 19,
|
PERCENT_MERGE = 16, /* "%merge" */
|
||||||
PERCENT_ERROR_VERBOSE = 20,
|
PERCENT_CODE = 17, /* "%code" */
|
||||||
PERCENT_EXPECT = 21,
|
PERCENT_DEFAULT_PREC = 18, /* "%default-prec" */
|
||||||
PERCENT_EXPECT_RR = 22,
|
PERCENT_DEFINE = 19, /* "%define" */
|
||||||
PERCENT_FLAG = 23,
|
PERCENT_DEFINES = 20, /* "%defines" */
|
||||||
PERCENT_FILE_PREFIX = 24,
|
PERCENT_ERROR_VERBOSE = 21, /* "%error-verbose" */
|
||||||
PERCENT_GLR_PARSER = 25,
|
PERCENT_EXPECT = 22, /* "%expect" */
|
||||||
PERCENT_INITIAL_ACTION = 26,
|
PERCENT_EXPECT_RR = 23, /* "%expect-rr" */
|
||||||
PERCENT_LANGUAGE = 27,
|
PERCENT_FLAG = 24, /* "%<flag>" */
|
||||||
PERCENT_NAME_PREFIX = 28,
|
PERCENT_FILE_PREFIX = 25, /* "%file-prefix" */
|
||||||
PERCENT_NO_DEFAULT_PREC = 29,
|
PERCENT_GLR_PARSER = 26, /* "%glr-parser" */
|
||||||
PERCENT_NO_LINES = 30,
|
PERCENT_INITIAL_ACTION = 27, /* "%initial-action" */
|
||||||
PERCENT_NONDETERMINISTIC_PARSER = 31,
|
PERCENT_LANGUAGE = 28, /* "%language" */
|
||||||
PERCENT_OUTPUT = 32,
|
PERCENT_NAME_PREFIX = 29, /* "%name-prefix" */
|
||||||
PERCENT_PURE_PARSER = 33,
|
PERCENT_NO_DEFAULT_PREC = 30, /* "%no-default-prec" */
|
||||||
PERCENT_REQUIRE = 34,
|
PERCENT_NO_LINES = 31, /* "%no-lines" */
|
||||||
PERCENT_SKELETON = 35,
|
PERCENT_NONDETERMINISTIC_PARSER = 32, /* "%nondeterministic-parser" */
|
||||||
PERCENT_START = 36,
|
PERCENT_OUTPUT = 33, /* "%output" */
|
||||||
PERCENT_TOKEN_TABLE = 37,
|
PERCENT_PURE_PARSER = 34, /* "%pure-parser" */
|
||||||
PERCENT_VERBOSE = 38,
|
PERCENT_REQUIRE = 35, /* "%require" */
|
||||||
PERCENT_YACC = 39,
|
PERCENT_SKELETON = 36, /* "%skeleton" */
|
||||||
BRACED_CODE = 40,
|
PERCENT_START = 37, /* "%start" */
|
||||||
BRACED_PREDICATE = 41,
|
PERCENT_TOKEN_TABLE = 38, /* "%token-table" */
|
||||||
BRACKETED_ID = 42,
|
PERCENT_VERBOSE = 39, /* "%verbose" */
|
||||||
CHAR = 43,
|
PERCENT_YACC = 40, /* "%yacc" */
|
||||||
COLON = 44,
|
BRACED_CODE = 41, /* "{...}" */
|
||||||
EPILOGUE = 45,
|
BRACED_PREDICATE = 42, /* "%?{...}" */
|
||||||
EQUAL = 46,
|
BRACKETED_ID = 43, /* "[identifier]" */
|
||||||
ID = 47,
|
CHAR = 44, /* "character literal" */
|
||||||
ID_COLON = 48,
|
COLON = 45, /* ":" */
|
||||||
PERCENT_PERCENT = 49,
|
EPILOGUE = 46, /* "epilogue" */
|
||||||
PIPE = 50,
|
EQUAL = 47, /* "=" */
|
||||||
PROLOGUE = 51,
|
ID = 48, /* "identifier" */
|
||||||
SEMICOLON = 52,
|
ID_COLON = 49, /* "identifier:" */
|
||||||
TAG = 53,
|
PERCENT_PERCENT = 50, /* "%%" */
|
||||||
TAG_ANY = 54,
|
PIPE = 51, /* "|" */
|
||||||
TAG_NONE = 55,
|
PROLOGUE = 52, /* "%{...%}" */
|
||||||
INT = 56,
|
SEMICOLON = 53, /* ";" */
|
||||||
PERCENT_PARAM = 57,
|
TAG = 54, /* "<tag>" */
|
||||||
PERCENT_UNION = 58,
|
TAG_ANY = 55, /* "<*>" */
|
||||||
PERCENT_EMPTY = 59
|
TAG_NONE = 56, /* "<>" */
|
||||||
|
INT = 57, /* "integer literal" */
|
||||||
|
PERCENT_PARAM = 58, /* "%param" */
|
||||||
|
PERCENT_UNION = 59, /* "%union" */
|
||||||
|
PERCENT_EMPTY = 60 /* "%empty" */
|
||||||
};
|
};
|
||||||
|
typedef enum gram_tokentype gram_token_kind_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Value type. */
|
/* Value type. */
|
||||||
#if ! defined GRAM_STYPE && ! defined GRAM_STYPE_IS_DECLARED
|
#if ! defined GRAM_STYPE && ! defined GRAM_STYPE_IS_DECLARED
|
||||||
union GRAM_STYPE
|
union GRAM_STYPE
|
||||||
{
|
{
|
||||||
|
assoc precedence_declarator; /* precedence_declarator */
|
||||||
|
char* STRING; /* "string" */
|
||||||
|
char* TSTRING; /* "translatable string" */
|
||||||
|
char* BRACED_CODE; /* "{...}" */
|
||||||
|
char* BRACED_PREDICATE; /* "%?{...}" */
|
||||||
|
char* EPILOGUE; /* "epilogue" */
|
||||||
|
char* PROLOGUE; /* "%{...%}" */
|
||||||
|
code_props_type code_props_type; /* code_props_type */
|
||||||
|
int INT; /* "integer literal" */
|
||||||
|
int yykind_82; /* int.opt */
|
||||||
|
named_ref* yykind_95; /* named_ref.opt */
|
||||||
|
param_type PERCENT_PARAM; /* "%param" */
|
||||||
|
symbol* token_decl; /* token_decl */
|
||||||
|
symbol* alias; /* alias */
|
||||||
|
symbol* token_decl_for_prec; /* token_decl_for_prec */
|
||||||
|
symbol* id; /* id */
|
||||||
|
symbol* id_colon; /* id_colon */
|
||||||
|
symbol* symbol; /* symbol */
|
||||||
|
symbol* string_as_id; /* string_as_id */
|
||||||
|
symbol_list* generic_symlist; /* generic_symlist */
|
||||||
|
symbol_list* generic_symlist_item; /* generic_symlist_item */
|
||||||
|
symbol_list* nterm_decls; /* nterm_decls */
|
||||||
|
symbol_list* token_decls; /* token_decls */
|
||||||
|
symbol_list* yykind_80; /* token_decl.1 */
|
||||||
|
symbol_list* token_decls_for_prec; /* token_decls_for_prec */
|
||||||
|
symbol_list* yykind_85; /* token_decl_for_prec.1 */
|
||||||
|
symbol_list* symbol_decls; /* symbol_decls */
|
||||||
|
symbol_list* yykind_88; /* symbol_decl.1 */
|
||||||
|
uniqstr PERCENT_ERROR_VERBOSE; /* "%error-verbose" */
|
||||||
|
uniqstr PERCENT_FLAG; /* "%<flag>" */
|
||||||
|
uniqstr PERCENT_FILE_PREFIX; /* "%file-prefix" */
|
||||||
|
uniqstr PERCENT_NAME_PREFIX; /* "%name-prefix" */
|
||||||
|
uniqstr PERCENT_PURE_PARSER; /* "%pure-parser" */
|
||||||
|
uniqstr BRACKETED_ID; /* "[identifier]" */
|
||||||
|
uniqstr ID; /* "identifier" */
|
||||||
|
uniqstr ID_COLON; /* "identifier:" */
|
||||||
|
uniqstr TAG; /* "<tag>" */
|
||||||
|
uniqstr yykind_74; /* tag.opt */
|
||||||
|
uniqstr tag; /* tag */
|
||||||
|
uniqstr variable; /* variable */
|
||||||
|
unsigned char CHAR; /* "character literal" */
|
||||||
|
value_type value; /* value */
|
||||||
|
|
||||||
/* precedence_declarator */
|
|
||||||
assoc precedence_declarator;
|
|
||||||
/* "string" */
|
|
||||||
char* STRING;
|
|
||||||
/* "{...}" */
|
|
||||||
char* BRACED_CODE;
|
|
||||||
/* "%?{...}" */
|
|
||||||
char* BRACED_PREDICATE;
|
|
||||||
/* "epilogue" */
|
|
||||||
char* EPILOGUE;
|
|
||||||
/* "%{...%}" */
|
|
||||||
char* PROLOGUE;
|
|
||||||
/* code_props_type */
|
|
||||||
code_props_type code_props_type;
|
|
||||||
/* "integer" */
|
|
||||||
int INT;
|
|
||||||
/* int.opt */
|
|
||||||
int yytype_81;
|
|
||||||
/* named_ref.opt */
|
|
||||||
named_ref* yytype_93;
|
|
||||||
/* "%param" */
|
|
||||||
param_type PERCENT_PARAM;
|
|
||||||
/* token_decl */
|
|
||||||
symbol* token_decl;
|
|
||||||
/* token_decl_for_prec */
|
|
||||||
symbol* token_decl_for_prec;
|
|
||||||
/* id */
|
|
||||||
symbol* id;
|
|
||||||
/* id_colon */
|
|
||||||
symbol* id_colon;
|
|
||||||
/* symbol */
|
|
||||||
symbol* symbol;
|
|
||||||
/* string_as_id */
|
|
||||||
symbol* string_as_id;
|
|
||||||
/* string_as_id.opt */
|
|
||||||
symbol* yytype_100;
|
|
||||||
/* generic_symlist */
|
|
||||||
symbol_list* generic_symlist;
|
|
||||||
/* generic_symlist_item */
|
|
||||||
symbol_list* generic_symlist_item;
|
|
||||||
/* nterm_decls */
|
|
||||||
symbol_list* nterm_decls;
|
|
||||||
/* token_decls */
|
|
||||||
symbol_list* token_decls;
|
|
||||||
/* token_decl.1 */
|
|
||||||
symbol_list* yytype_79;
|
|
||||||
/* token_decls_for_prec */
|
|
||||||
symbol_list* token_decls_for_prec;
|
|
||||||
/* token_decl_for_prec.1 */
|
|
||||||
symbol_list* yytype_83;
|
|
||||||
/* symbol_decls */
|
|
||||||
symbol_list* symbol_decls;
|
|
||||||
/* symbol_decl.1 */
|
|
||||||
symbol_list* yytype_86;
|
|
||||||
/* "%error-verbose" */
|
|
||||||
uniqstr PERCENT_ERROR_VERBOSE;
|
|
||||||
/* "%<flag>" */
|
|
||||||
uniqstr PERCENT_FLAG;
|
|
||||||
/* "%file-prefix" */
|
|
||||||
uniqstr PERCENT_FILE_PREFIX;
|
|
||||||
/* "%name-prefix" */
|
|
||||||
uniqstr PERCENT_NAME_PREFIX;
|
|
||||||
/* "%pure-parser" */
|
|
||||||
uniqstr PERCENT_PURE_PARSER;
|
|
||||||
/* "[identifier]" */
|
|
||||||
uniqstr BRACKETED_ID;
|
|
||||||
/* "identifier" */
|
|
||||||
uniqstr ID;
|
|
||||||
/* "identifier:" */
|
|
||||||
uniqstr ID_COLON;
|
|
||||||
/* "<tag>" */
|
|
||||||
uniqstr TAG;
|
|
||||||
/* tag.opt */
|
|
||||||
uniqstr yytype_73;
|
|
||||||
/* tag */
|
|
||||||
uniqstr tag;
|
|
||||||
/* variable */
|
|
||||||
uniqstr variable;
|
|
||||||
/* "character literal" */
|
|
||||||
unsigned char CHAR;
|
|
||||||
/* value */
|
|
||||||
value_type value;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
typedef union GRAM_STYPE GRAM_STYPE;
|
typedef union GRAM_STYPE GRAM_STYPE;
|
||||||
|
|||||||
+86
-62
@@ -125,7 +125,7 @@
|
|||||||
%define api.token.raw
|
%define api.token.raw
|
||||||
%define api.value.type union
|
%define api.value.type union
|
||||||
%define locations
|
%define locations
|
||||||
%define parse.error verbose
|
%define parse.error custom
|
||||||
%define parse.lac full
|
%define parse.lac full
|
||||||
%define parse.trace
|
%define parse.trace
|
||||||
%defines
|
%defines
|
||||||
@@ -140,31 +140,26 @@
|
|||||||
boundary_set (&@$.end, grammar_file, 1, 1, 1);
|
boundary_set (&@$.end, grammar_file, 1, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Define the tokens together with their human representation. */
|
|
||||||
%token GRAM_EOF 0 "end of file"
|
|
||||||
%token STRING "string"
|
|
||||||
|
|
||||||
%token PERCENT_TOKEN "%token"
|
|
||||||
%token PERCENT_NTERM "%nterm"
|
|
||||||
|
|
||||||
%token PERCENT_TYPE "%type"
|
|
||||||
%token PERCENT_DESTRUCTOR "%destructor"
|
|
||||||
%token PERCENT_PRINTER "%printer"
|
|
||||||
|
|
||||||
%token PERCENT_LEFT "%left"
|
|
||||||
%token PERCENT_RIGHT "%right"
|
|
||||||
%token PERCENT_NONASSOC "%nonassoc"
|
|
||||||
%token PERCENT_PRECEDENCE "%precedence"
|
|
||||||
|
|
||||||
%token PERCENT_PREC "%prec"
|
|
||||||
%token PERCENT_DPREC "%dprec"
|
|
||||||
%token PERCENT_MERGE "%merge"
|
|
||||||
|
|
||||||
/*----------------------.
|
|
||||||
| Global Declarations. |
|
|
||||||
`----------------------*/
|
|
||||||
|
|
||||||
%token
|
%token
|
||||||
|
STRING _("string")
|
||||||
|
TSTRING _("translatable string")
|
||||||
|
|
||||||
|
PERCENT_TOKEN "%token"
|
||||||
|
PERCENT_NTERM "%nterm"
|
||||||
|
|
||||||
|
PERCENT_TYPE "%type"
|
||||||
|
PERCENT_DESTRUCTOR "%destructor"
|
||||||
|
PERCENT_PRINTER "%printer"
|
||||||
|
|
||||||
|
PERCENT_LEFT "%left"
|
||||||
|
PERCENT_RIGHT "%right"
|
||||||
|
PERCENT_NONASSOC "%nonassoc"
|
||||||
|
PERCENT_PRECEDENCE "%precedence"
|
||||||
|
|
||||||
|
PERCENT_PREC "%prec"
|
||||||
|
PERCENT_DPREC "%dprec"
|
||||||
|
PERCENT_MERGE "%merge"
|
||||||
|
|
||||||
PERCENT_CODE "%code"
|
PERCENT_CODE "%code"
|
||||||
PERCENT_DEFAULT_PREC "%default-prec"
|
PERCENT_DEFAULT_PREC "%default-prec"
|
||||||
PERCENT_DEFINE "%define"
|
PERCENT_DEFINE "%define"
|
||||||
@@ -190,24 +185,23 @@
|
|||||||
PERCENT_TOKEN_TABLE "%token-table"
|
PERCENT_TOKEN_TABLE "%token-table"
|
||||||
PERCENT_VERBOSE "%verbose"
|
PERCENT_VERBOSE "%verbose"
|
||||||
PERCENT_YACC "%yacc"
|
PERCENT_YACC "%yacc"
|
||||||
;
|
|
||||||
|
|
||||||
%token BRACED_CODE "{...}"
|
BRACED_CODE "{...}"
|
||||||
%token BRACED_PREDICATE "%?{...}"
|
BRACED_PREDICATE "%?{...}"
|
||||||
%token BRACKETED_ID "[identifier]"
|
BRACKETED_ID _("[identifier]")
|
||||||
%token CHAR "character literal"
|
CHAR _("character literal")
|
||||||
%token COLON ":"
|
COLON ":"
|
||||||
%token EPILOGUE "epilogue"
|
EPILOGUE _("epilogue")
|
||||||
%token EQUAL "="
|
EQUAL "="
|
||||||
%token ID "identifier"
|
ID _("identifier")
|
||||||
%token ID_COLON "identifier:"
|
ID_COLON _("identifier:")
|
||||||
%token PERCENT_PERCENT "%%"
|
PERCENT_PERCENT "%%"
|
||||||
%token PIPE "|"
|
PIPE "|"
|
||||||
%token PROLOGUE "%{...%}"
|
PROLOGUE "%{...%}"
|
||||||
%token SEMICOLON ";"
|
SEMICOLON ";"
|
||||||
%token TAG "<tag>"
|
TAG _("<tag>")
|
||||||
%token TAG_ANY "<*>"
|
TAG_ANY "<*>"
|
||||||
%token TAG_NONE "<>"
|
TAG_NONE "<>"
|
||||||
|
|
||||||
/* Experimental feature, don't rely on it. */
|
/* Experimental feature, don't rely on it. */
|
||||||
%code pre-printer {tron (yyo);}
|
%code pre-printer {tron (yyo);}
|
||||||
@@ -216,8 +210,8 @@
|
|||||||
%type <unsigned char> CHAR
|
%type <unsigned char> CHAR
|
||||||
%printer { fputs (char_name ($$), yyo); } <unsigned char>
|
%printer { fputs (char_name ($$), yyo); } <unsigned char>
|
||||||
|
|
||||||
%type <char*> "{...}" "%?{...}" "%{...%}" EPILOGUE STRING
|
%type <char*> "{...}" "%?{...}" "%{...%}" EPILOGUE STRING TSTRING
|
||||||
%printer { fputs ($$, yyo); } <char*>
|
%printer { fputs ($$, yyo); } <char*>
|
||||||
|
|
||||||
%type <uniqstr>
|
%type <uniqstr>
|
||||||
BRACKETED_ID ID ID_COLON
|
BRACKETED_ID ID ID_COLON
|
||||||
@@ -230,7 +224,7 @@
|
|||||||
%printer { fprintf (yyo, "%%%s", $$); } PERCENT_FLAG
|
%printer { fprintf (yyo, "%%%s", $$); } PERCENT_FLAG
|
||||||
%printer { fprintf (yyo, "<%s>", $$); } TAG tag
|
%printer { fprintf (yyo, "<%s>", $$); } TAG tag
|
||||||
|
|
||||||
%token <int> INT "integer"
|
%token <int> INT _("integer literal")
|
||||||
%printer { fprintf (yyo, "%d", $$); } <int>
|
%printer { fprintf (yyo, "%d", $$); } <int>
|
||||||
|
|
||||||
%type <symbol*> id id_colon string_as_id symbol token_decl token_decl_for_prec
|
%type <symbol*> id id_colon string_as_id symbol token_decl token_decl_for_prec
|
||||||
@@ -532,7 +526,7 @@ token_decl.1:
|
|||||||
|
|
||||||
// One symbol declaration for %token or %nterm.
|
// One symbol declaration for %token or %nterm.
|
||||||
token_decl:
|
token_decl:
|
||||||
id int.opt[num] string_as_id.opt[alias]
|
id int.opt[num] alias
|
||||||
{
|
{
|
||||||
$$ = $id;
|
$$ = $id;
|
||||||
symbol_class_set ($id, current_class, @id, true);
|
symbol_class_set ($id, current_class, @id, true);
|
||||||
@@ -549,6 +543,19 @@ int.opt:
|
|||||||
| INT
|
| INT
|
||||||
;
|
;
|
||||||
|
|
||||||
|
%type <symbol*> alias;
|
||||||
|
alias:
|
||||||
|
%empty { $$ = NULL; }
|
||||||
|
| string_as_id { $$ = $1; }
|
||||||
|
| TSTRING
|
||||||
|
{
|
||||||
|
$$ = symbol_get (quotearg_style (c_quoting_style, $1), @1);
|
||||||
|
symbol_class_set ($$, token_sym, @1, false);
|
||||||
|
$$->translatable = true;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------.
|
/*-------------------------------------.
|
||||||
| token_decls_for_prec (%left, etc.). |
|
| token_decls_for_prec (%left, etc.). |
|
||||||
`-------------------------------------*/
|
`-------------------------------------*/
|
||||||
@@ -748,14 +755,11 @@ id:
|
|||||||
}
|
}
|
||||||
if (muscle_percent_define_ifdef (var))
|
if (muscle_percent_define_ifdef (var))
|
||||||
{
|
{
|
||||||
int indent = 0;
|
complain (&@1, complaint,
|
||||||
complain_indent (&@1, complaint, &indent,
|
_("character literals cannot be used together"
|
||||||
_("character literals cannot be used together"
|
" with %s"), var);
|
||||||
" with %s"), var);
|
|
||||||
indent += SUB_INDENT;
|
|
||||||
location loc = muscle_percent_define_get_loc (var);
|
location loc = muscle_percent_define_get_loc (var);
|
||||||
complain_indent (&loc, complaint, &indent,
|
subcomplain (&loc, complaint, _("definition of %s"), var);
|
||||||
_("definition of %s"), var);
|
|
||||||
}
|
}
|
||||||
$$ = symbol_get (char_name ($1), @1);
|
$$ = symbol_get (char_name ($1), @1);
|
||||||
symbol_class_set ($$, token_sym, @1, false);
|
symbol_class_set ($$, token_sym, @1, false);
|
||||||
@@ -782,12 +786,6 @@ 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
|
||||||
@@ -799,6 +797,32 @@ epilogue.opt:
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
int
|
||||||
|
yyreport_syntax_error (const yypcontext_t *ctx)
|
||||||
|
{
|
||||||
|
int res = 0;
|
||||||
|
/* Arguments of format: reported tokens (one for the "unexpected",
|
||||||
|
one per "expected"). */
|
||||||
|
enum { ARGS_MAX = 5 };
|
||||||
|
const char *argv[ARGS_MAX];
|
||||||
|
int argc = 0;
|
||||||
|
yysymbol_kind_t unexpected = yypcontext_token (ctx);
|
||||||
|
if (unexpected != YYSYMBOL_YYEMPTY)
|
||||||
|
{
|
||||||
|
argv[argc++] = yysymbol_name (unexpected);
|
||||||
|
yysymbol_kind_t expected[ARGS_MAX - 1];
|
||||||
|
int nexpected = yypcontext_expected_tokens (ctx, expected, ARGS_MAX - 1);
|
||||||
|
if (nexpected < 0)
|
||||||
|
res = nexpected;
|
||||||
|
else
|
||||||
|
for (int i = 0; i < nexpected; ++i)
|
||||||
|
argv[argc++] = yysymbol_name (expected[i]);
|
||||||
|
}
|
||||||
|
syntax_error (*yypcontext_location (ctx), argc, argv);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return the location of the left-hand side of a rule whose
|
/* Return the location of the left-hand side of a rule whose
|
||||||
right-hand side is RHS[1] ... RHS[N]. Ignore empty nonterminals in
|
right-hand side is RHS[1] ... RHS[N]. Ignore empty nonterminals in
|
||||||
the right-hand side, and return an empty location equal to the end
|
the right-hand side, and return an empty location equal to the end
|
||||||
@@ -1021,9 +1045,9 @@ handle_require (location const *loc, char const *version)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pretend to be at least 3.5, to check features published in that
|
/* Pretend to be at least that version, to check features published
|
||||||
version while developping it. */
|
in that version while developping it. */
|
||||||
const char* api_version = "3.5";
|
const char* api_version = "3.6";
|
||||||
const char* package_version =
|
const char* package_version =
|
||||||
0 < strverscmp (api_version, PACKAGE_VERSION)
|
0 < strverscmp (api_version, PACKAGE_VERSION)
|
||||||
? api_version : PACKAGE_VERSION;
|
? api_version : PACKAGE_VERSION;
|
||||||
|
|||||||
+1
-1
@@ -329,7 +329,7 @@ print_reductions (FILE *out, int level, state *s)
|
|||||||
|
|
||||||
/*--------------------------------------------------------------.
|
/*--------------------------------------------------------------.
|
||||||
| Report on OUT all the actions (shifts, gotos, reductions, and |
|
| Report on OUT all the actions (shifts, gotos, reductions, and |
|
||||||
| explicit erros from %nonassoc) of S. |
|
| explicit errors from %nonassoc) of S. |
|
||||||
`--------------------------------------------------------------*/
|
`--------------------------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
+1
-1
@@ -319,7 +319,7 @@ print_reductions (FILE *out, state *s)
|
|||||||
|
|
||||||
/*--------------------------------------------------------------.
|
/*--------------------------------------------------------------.
|
||||||
| Report on OUT all the actions (shifts, gotos, reductions, and |
|
| Report on OUT all the actions (shifts, gotos, reductions, and |
|
||||||
| explicit erros from %nonassoc) of S. |
|
| explicit errors from %nonassoc) of S. |
|
||||||
`--------------------------------------------------------------*/
|
`--------------------------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
+16
-14
@@ -124,16 +124,13 @@ record_merge_function_type (int merger, uniqstr type, location declaration_loc)
|
|||||||
aver (merge_function != NULL && merger_find == merger);
|
aver (merge_function != NULL && merger_find == merger);
|
||||||
if (merge_function->type != NULL && !UNIQSTR_EQ (merge_function->type, type))
|
if (merge_function->type != NULL && !UNIQSTR_EQ (merge_function->type, type))
|
||||||
{
|
{
|
||||||
int indent = 0;
|
complain (&declaration_loc, complaint,
|
||||||
complain_indent (&declaration_loc, complaint, &indent,
|
_("result type clash on merge function %s: "
|
||||||
_("result type clash on merge function %s: "
|
"<%s> != <%s>"),
|
||||||
"<%s> != <%s>"),
|
quote (merge_function->name), type,
|
||||||
quote (merge_function->name), type,
|
merge_function->type);
|
||||||
merge_function->type);
|
subcomplain (&merge_function->type_declaration_loc, complaint,
|
||||||
indent += SUB_INDENT;
|
_("previous declaration"));
|
||||||
complain_indent (&merge_function->type_declaration_loc, complaint,
|
|
||||||
&indent,
|
|
||||||
_("previous declaration"));
|
|
||||||
}
|
}
|
||||||
merge_function->type = uniqstr_new (type);
|
merge_function->type = uniqstr_new (type);
|
||||||
merge_function->type_declaration_loc = declaration_loc;
|
merge_function->type_declaration_loc = declaration_loc;
|
||||||
@@ -781,11 +778,16 @@ check_and_convert_grammar (void)
|
|||||||
/* If the user did not define her ENDTOKEN, do it now. */
|
/* If the user did not define her ENDTOKEN, do it now. */
|
||||||
if (!endtoken)
|
if (!endtoken)
|
||||||
{
|
{
|
||||||
endtoken = symbol_get ("$end", empty_loc);
|
endtoken = symbol_get ("YYEOF", empty_loc);
|
||||||
endtoken->content->class = token_sym;
|
endtoken->content->class = token_sym;
|
||||||
endtoken->content->number = 0;
|
endtoken->content->number = 0;
|
||||||
/* Value specified by POSIX. */
|
/* Value specified by POSIX. */
|
||||||
endtoken->content->user_token_number = 0;
|
endtoken->content->user_token_number = 0;
|
||||||
|
{
|
||||||
|
symbol *alias = symbol_get ("$end", empty_loc);
|
||||||
|
symbol_class_set (alias, token_sym, empty_loc, false);
|
||||||
|
symbol_make_alias (endtoken, alias, empty_loc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Report any undefined symbols and consider them nonterminals. */
|
/* Report any undefined symbols and consider them nonterminals. */
|
||||||
@@ -820,9 +822,9 @@ check_and_convert_grammar (void)
|
|||||||
/* Assign the symbols their symbol numbers. */
|
/* Assign the symbols their symbol numbers. */
|
||||||
symbols_pack ();
|
symbols_pack ();
|
||||||
|
|
||||||
/* Scan rule actions after invoking symbol_check_alias_consistency (in
|
/* Scan rule actions after invoking symbol_check_alias_consistency
|
||||||
symbols_pack above) so that token types are set correctly before the rule
|
(in symbols_pack above) so that token types are set correctly
|
||||||
action type checking.
|
before the rule action type checking.
|
||||||
|
|
||||||
Before invoking grammar_rule_check_and_complete (in packgram
|
Before invoking grammar_rule_check_and_complete (in packgram
|
||||||
below) on any rule, make sure all actions have already been
|
below) on any rule, make sure all actions have already been
|
||||||
|
|||||||
+29
-34
@@ -321,14 +321,14 @@ static void
|
|||||||
show_sub_message (warnings warning,
|
show_sub_message (warnings warning,
|
||||||
const char* cp, bool explicit_bracketing,
|
const char* cp, bool explicit_bracketing,
|
||||||
int midrule_rhs_index, char dollar_or_at,
|
int midrule_rhs_index, char dollar_or_at,
|
||||||
int indent, const variant *var)
|
const variant *var)
|
||||||
{
|
{
|
||||||
const char *at_spec = get_at_spec (var->symbol_index);
|
const char *at_spec = get_at_spec (var->symbol_index);
|
||||||
|
|
||||||
if (var->err == 0)
|
if (var->err == 0)
|
||||||
complain_indent (&var->loc, warning, &indent,
|
subcomplain (&var->loc, warning,
|
||||||
_("refers to: %c%s at %s"), dollar_or_at,
|
_("refers to: %c%s at %s"), dollar_or_at,
|
||||||
var->id, at_spec);
|
var->id, at_spec);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const char *id;
|
const char *id;
|
||||||
@@ -375,8 +375,8 @@ show_sub_message (warnings warning,
|
|||||||
_(", cannot be accessed from midrule action at $%d"),
|
_(", cannot be accessed from midrule action at $%d"),
|
||||||
midrule_rhs_index);
|
midrule_rhs_index);
|
||||||
|
|
||||||
complain_indent (&id_loc, warning, &indent, "%s",
|
subcomplain (&id_loc, warning, "%s",
|
||||||
obstack_finish0 (&msg_buf));
|
obstack_finish0 (&msg_buf));
|
||||||
obstack_free (&msg_buf, 0);
|
obstack_free (&msg_buf, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -384,14 +384,13 @@ show_sub_message (warnings warning,
|
|||||||
static void
|
static void
|
||||||
show_sub_messages (warnings warning,
|
show_sub_messages (warnings warning,
|
||||||
const char* cp, bool explicit_bracketing,
|
const char* cp, bool explicit_bracketing,
|
||||||
int midrule_rhs_index, char dollar_or_at,
|
int midrule_rhs_index, char dollar_or_at)
|
||||||
int indent)
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < variant_count; ++i)
|
for (int i = 0; i < variant_count; ++i)
|
||||||
show_sub_message (warning | silent,
|
show_sub_message (warning | silent,
|
||||||
cp, explicit_bracketing,
|
cp, explicit_bracketing,
|
||||||
midrule_rhs_index, dollar_or_at,
|
midrule_rhs_index, dollar_or_at,
|
||||||
indent, &variant_table[i]);
|
&variant_table[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returned from "parse_ref" when the reference
|
/* Returned from "parse_ref" when the reference
|
||||||
@@ -492,47 +491,44 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
|
|||||||
{
|
{
|
||||||
int len = (explicit_bracketing || !ref_tail_fields) ?
|
int len = (explicit_bracketing || !ref_tail_fields) ?
|
||||||
cp_end - cp : ref_tail_fields - cp;
|
cp_end - cp : ref_tail_fields - cp;
|
||||||
int indent = 0;
|
|
||||||
|
|
||||||
complain_indent (text_loc, complaint, &indent,
|
complain (text_loc, complaint,
|
||||||
_("invalid reference: %s"), quote (text));
|
_("invalid reference: %s"), quote (text));
|
||||||
indent += SUB_INDENT;
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
{
|
{
|
||||||
location sym_loc = *text_loc;
|
location sym_loc = *text_loc;
|
||||||
sym_loc.start.column += 1;
|
sym_loc.start.column += 1;
|
||||||
sym_loc.end = sym_loc.start;
|
sym_loc.end = sym_loc.start;
|
||||||
complain_indent (&sym_loc, complaint, &indent,
|
subcomplain (&sym_loc, complaint,
|
||||||
_("syntax error after '%c', expecting integer, "
|
_("syntax error after '%c', expecting integer, "
|
||||||
"letter, '_', '[', or '$'"),
|
"letter, '_', '[', or '$'"),
|
||||||
dollar_or_at);
|
dollar_or_at);
|
||||||
}
|
}
|
||||||
else if (midrule_rhs_index)
|
else if (midrule_rhs_index)
|
||||||
complain_indent (&rule->rhs_loc, complaint, &indent,
|
subcomplain (&rule->rhs_loc, complaint,
|
||||||
_("symbol not found in production before $%d: "
|
_("symbol not found in production before $%d: "
|
||||||
"%.*s"),
|
"%.*s"),
|
||||||
midrule_rhs_index, len, cp);
|
midrule_rhs_index, len, cp);
|
||||||
else
|
else
|
||||||
complain_indent (&rule->rhs_loc, complaint, &indent,
|
subcomplain (&rule->rhs_loc, complaint,
|
||||||
_("symbol not found in production: %.*s"),
|
_("symbol not found in production: %.*s"),
|
||||||
len, cp);
|
len, cp);
|
||||||
|
|
||||||
if (variant_count > 0)
|
if (variant_count > 0)
|
||||||
show_sub_messages (complaint,
|
show_sub_messages (complaint,
|
||||||
cp, explicit_bracketing, midrule_rhs_index,
|
cp, explicit_bracketing, midrule_rhs_index,
|
||||||
dollar_or_at, indent);
|
dollar_or_at);
|
||||||
return INVALID_REF;
|
return INVALID_REF;
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
int indent = 0;
|
|
||||||
if (variant_count > 1)
|
if (variant_count > 1)
|
||||||
{
|
{
|
||||||
complain_indent (text_loc, Wother, &indent,
|
complain (text_loc, Wother,
|
||||||
_("misleading reference: %s"), quote (text));
|
_("misleading reference: %s"), quote (text));
|
||||||
show_sub_messages (Wother,
|
show_sub_messages (Wother,
|
||||||
cp, explicit_bracketing, midrule_rhs_index,
|
cp, explicit_bracketing, midrule_rhs_index,
|
||||||
dollar_or_at, indent + SUB_INDENT);
|
dollar_or_at);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int symbol_index =
|
int symbol_index =
|
||||||
@@ -543,12 +539,11 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
|
|||||||
case 2:
|
case 2:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
int indent = 0;
|
complain (text_loc, complaint,
|
||||||
complain_indent (text_loc, complaint, &indent,
|
_("ambiguous reference: %s"), quote (text));
|
||||||
_("ambiguous reference: %s"), quote (text));
|
|
||||||
show_sub_messages (complaint,
|
show_sub_messages (complaint,
|
||||||
cp, explicit_bracketing, midrule_rhs_index,
|
cp, explicit_bracketing, midrule_rhs_index,
|
||||||
dollar_or_at, indent + SUB_INDENT);
|
dollar_or_at);
|
||||||
return INVALID_REF;
|
return INVALID_REF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -617,7 +612,7 @@ handle_action_dollar (symbol_list *rule, char *text, const location *dollar_loc)
|
|||||||
char *cp = fetch_type_name (text + 1, &type_name, dollar_loc);
|
char *cp = fetch_type_name (text + 1, &type_name, dollar_loc);
|
||||||
int n = parse_ref (cp, effective_rule, effective_rule_length,
|
int n = parse_ref (cp, effective_rule, effective_rule_length,
|
||||||
rule->midrule_parent_rhs_index, text, dollar_loc, '$');
|
rule->midrule_parent_rhs_index, text, dollar_loc, '$');
|
||||||
/* End type_name. Don't do it ealier: parse_ref depends on TEXT. */
|
/* End type_name. Don't do it earlier: parse_ref depends on TEXT. */
|
||||||
if (type_name)
|
if (type_name)
|
||||||
cp[-1] = '\0';
|
cp[-1] = '\0';
|
||||||
|
|
||||||
|
|||||||
+21
-6
@@ -51,7 +51,7 @@ static boundary scanner_cursor;
|
|||||||
|
|
||||||
#define YY_USER_ACTION location_compute (loc, &scanner_cursor, yytext, yyleng);
|
#define YY_USER_ACTION location_compute (loc, &scanner_cursor, yytext, yyleng);
|
||||||
|
|
||||||
/* Report that yytext is an extension, and evaluate to its token type. */
|
/* Report that yytext is an extension, and evaluate to its token kind. */
|
||||||
#define BISON_DIRECTIVE(Directive) \
|
#define BISON_DIRECTIVE(Directive) \
|
||||||
(bison_directive (loc, yytext), PERCENT_ ## Directive)
|
(bison_directive (loc, yytext), PERCENT_ ## Directive)
|
||||||
|
|
||||||
@@ -110,8 +110,8 @@ static void unexpected_newline (boundary, char const *);
|
|||||||
%}
|
%}
|
||||||
/* A C-like comment in directives/rules. */
|
/* A C-like comment in directives/rules. */
|
||||||
%x SC_YACC_COMMENT
|
%x SC_YACC_COMMENT
|
||||||
/* Strings and characters in directives/rules. */
|
/* Characters and strings in directives/rules. */
|
||||||
%x SC_ESCAPED_STRING SC_ESCAPED_CHARACTER
|
%x SC_ESCAPED_CHARACTER SC_ESCAPED_STRING SC_ESCAPED_TSTRING
|
||||||
/* A identifier was just read in directives/rules. Special state
|
/* A identifier was just read in directives/rules. Special state
|
||||||
to capture the sequence 'identifier :'. */
|
to capture the sequence 'identifier :'. */
|
||||||
%x SC_AFTER_IDENTIFIER
|
%x SC_AFTER_IDENTIFIER
|
||||||
@@ -318,6 +318,7 @@ eqopt ({sp}=)?
|
|||||||
|
|
||||||
/* Strings. */
|
/* Strings. */
|
||||||
"\"" token_start = loc->start; BEGIN SC_ESCAPED_STRING;
|
"\"" token_start = loc->start; BEGIN SC_ESCAPED_STRING;
|
||||||
|
"_(\"" token_start = loc->start; BEGIN SC_ESCAPED_TSTRING;
|
||||||
|
|
||||||
/* Prologue. */
|
/* Prologue. */
|
||||||
"%{" code_start = loc->start; BEGIN SC_PROLOGUE;
|
"%{" code_start = loc->start; BEGIN SC_PROLOGUE;
|
||||||
@@ -378,7 +379,7 @@ eqopt ({sp}=)?
|
|||||||
| added value. |
|
| added value. |
|
||||||
`--------------------------------------------------------------*/
|
`--------------------------------------------------------------*/
|
||||||
|
|
||||||
<SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_TAG>
|
<SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_TSTRING,SC_TAG>
|
||||||
{
|
{
|
||||||
\0 complain (loc, complaint, _("invalid null character"));
|
\0 complain (loc, complaint, _("invalid null character"));
|
||||||
}
|
}
|
||||||
@@ -539,6 +540,20 @@ eqopt ({sp}=)?
|
|||||||
{eol} unexpected_newline (token_start, "\"");
|
{eol} unexpected_newline (token_start, "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<SC_ESCAPED_TSTRING>
|
||||||
|
{
|
||||||
|
"\")" {
|
||||||
|
STRING_FINISH;
|
||||||
|
BEGIN INITIAL;
|
||||||
|
loc->start = token_start;
|
||||||
|
complain (loc, Wyacc,
|
||||||
|
_("POSIX Yacc does not support string literals"));
|
||||||
|
RETURN_VALUE (TSTRING, last_string);
|
||||||
|
}
|
||||||
|
<<EOF>> unexpected_eof (token_start, "\"");
|
||||||
|
"\n" unexpected_newline (token_start, "\"");
|
||||||
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------.
|
/*----------------------------------------------------------.
|
||||||
| Scanning a Bison character literal, decoding its escapes. |
|
| Scanning a Bison character literal, decoding its escapes. |
|
||||||
| The initial quote is already eaten. |
|
| The initial quote is already eaten. |
|
||||||
@@ -601,7 +616,7 @@ eqopt ({sp}=)?
|
|||||||
| Decode escaped characters. |
|
| Decode escaped characters. |
|
||||||
`----------------------------*/
|
`----------------------------*/
|
||||||
|
|
||||||
<SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>
|
<SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_TSTRING>
|
||||||
{
|
{
|
||||||
\\[0-7]{1,3} {
|
\\[0-7]{1,3} {
|
||||||
verify (UCHAR_MAX < ULONG_MAX);
|
verify (UCHAR_MAX < ULONG_MAX);
|
||||||
@@ -797,7 +812,7 @@ eqopt ({sp}=)?
|
|||||||
| By default, grow the string obstack with the input. |
|
| By default, grow the string obstack with the input. |
|
||||||
`-----------------------------------------------------*/
|
`-----------------------------------------------------*/
|
||||||
|
|
||||||
<SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE,SC_STRING,SC_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>
|
<SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PREDICATE,SC_PROLOGUE,SC_EPILOGUE,SC_STRING,SC_CHARACTER,SC_ESCAPED_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_TSTRING>
|
||||||
{
|
{
|
||||||
/* Accept multibyte characters in one block instead of byte after
|
/* Accept multibyte characters in one block instead of byte after
|
||||||
byte, so that add_column_width and mbsnwidth can compute correct
|
byte, so that add_column_width and mbsnwidth can compute correct
|
||||||
|
|||||||
+2
-9
@@ -189,7 +189,7 @@ flag (const char *arg)
|
|||||||
else if (STREQ (arg, "fatal"))
|
else if (STREQ (arg, "fatal"))
|
||||||
return fatal;
|
return fatal;
|
||||||
else if (STREQ (arg, "note"))
|
else if (STREQ (arg, "note"))
|
||||||
return silent | complaint | no_caret;
|
return silent | complaint | no_caret | note;
|
||||||
else if (STREQ (arg, "warn"))
|
else if (STREQ (arg, "warn"))
|
||||||
return Wother;
|
return Wother;
|
||||||
else
|
else
|
||||||
@@ -225,14 +225,7 @@ at_complain (int argc, char *argv[], char **out_namep, int *out_linenop)
|
|||||||
boundary_set_from_string (&loc.end, argv[3]);
|
boundary_set_from_string (&loc.end, argv[3]);
|
||||||
locp = &loc;
|
locp = &loc;
|
||||||
}
|
}
|
||||||
static int indent;
|
complain_args (locp, w, argc - 4, argv + 4);
|
||||||
if (w & silent)
|
|
||||||
indent += SUB_INDENT;
|
|
||||||
else
|
|
||||||
indent = 0;
|
|
||||||
complain_args (locp, w, &indent, argc - 4, argv + 4);
|
|
||||||
if (w & silent)
|
|
||||||
indent -= SUB_INDENT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
+87
-77
@@ -65,6 +65,20 @@ static bool *used_assoc = NULL;
|
|||||||
bool tag_seen = false;
|
bool tag_seen = false;
|
||||||
|
|
||||||
|
|
||||||
|
/* Whether SYM was defined by the user. */
|
||||||
|
|
||||||
|
static bool
|
||||||
|
symbol_is_user_defined (symbol *sym)
|
||||||
|
{
|
||||||
|
const bool eof_is_user_defined
|
||||||
|
= !endtoken->alias || STRNEQ (endtoken->alias->tag, "$end");
|
||||||
|
return sym->tag[0] != '$'
|
||||||
|
&& (eof_is_user_defined || (sym != endtoken && sym->alias != errtoken))
|
||||||
|
&& sym != errtoken && sym->alias != errtoken
|
||||||
|
&& sym != undeftoken && sym->alias != undeftoken;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------.
|
/*--------------------------.
|
||||||
| Create a new sym_content. |
|
| Create a new sym_content. |
|
||||||
`--------------------------*/
|
`--------------------------*/
|
||||||
@@ -111,6 +125,7 @@ symbol_new (uniqstr tag, location loc)
|
|||||||
|
|
||||||
res->tag = tag;
|
res->tag = tag;
|
||||||
res->location = loc;
|
res->location = loc;
|
||||||
|
res->translatable = false;
|
||||||
res->location_of_lhs = false;
|
res->location_of_lhs = false;
|
||||||
res->alias = NULL;
|
res->alias = NULL;
|
||||||
res->content = sym_content_new (res);
|
res->content = sym_content_new (res);
|
||||||
@@ -151,9 +166,9 @@ symbol_free (void *ptr)
|
|||||||
/* If needed, swap first and second so that first has the earliest
|
/* If needed, swap first and second so that first has the earliest
|
||||||
location (according to location_cmp).
|
location (according to location_cmp).
|
||||||
|
|
||||||
Many symbol features (e.g., user token numbers) are not assigned
|
Many symbol features (e.g., token codes) are not assigned during
|
||||||
during the parsing, but in a second step, via a traversal of the
|
parsing, but in a second step, via a traversal of the symbol table
|
||||||
symbol table sorted on tag.
|
sorted on tag.
|
||||||
|
|
||||||
However, error messages make more sense if we keep the first
|
However, error messages make more sense if we keep the first
|
||||||
declaration first.
|
declaration first.
|
||||||
@@ -278,6 +293,7 @@ is_identifier (uniqstr s)
|
|||||||
/*-----------------------------------------------.
|
/*-----------------------------------------------.
|
||||||
| Get the identifier associated to this symbol. |
|
| Get the identifier associated to this symbol. |
|
||||||
`-----------------------------------------------*/
|
`-----------------------------------------------*/
|
||||||
|
|
||||||
uniqstr
|
uniqstr
|
||||||
symbol_id_get (symbol const *sym)
|
symbol_id_get (symbol const *sym)
|
||||||
{
|
{
|
||||||
@@ -296,42 +312,29 @@ static void
|
|||||||
complain_symbol_redeclared (symbol *s, const char *what, location first,
|
complain_symbol_redeclared (symbol *s, const char *what, location first,
|
||||||
location second)
|
location second)
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
locations_sort (&first, &second);
|
locations_sort (&first, &second);
|
||||||
complain_indent (&second, complaint, &i,
|
complain (&second, complaint, _("%s redeclaration for %s"), what, s->tag);
|
||||||
_("%s redeclaration for %s"), what, s->tag);
|
subcomplain (&first, complaint, _("previous declaration"));
|
||||||
i += SUB_INDENT;
|
|
||||||
complain_indent (&first, complaint, &i,
|
|
||||||
_("previous declaration"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
complain_semantic_type_redeclared (semantic_type *s, const char *what, location first,
|
complain_semantic_type_redeclared (semantic_type *s, const char *what, location first,
|
||||||
location second)
|
location second)
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
locations_sort (&first, &second);
|
locations_sort (&first, &second);
|
||||||
complain_indent (&second, complaint, &i,
|
complain (&second, complaint, _("%s redeclaration for <%s>"), what, s->tag);
|
||||||
_("%s redeclaration for <%s>"), what, s->tag);
|
subcomplain (&first, complaint, _("previous declaration"));
|
||||||
i += SUB_INDENT;
|
|
||||||
complain_indent (&first, complaint, &i,
|
|
||||||
_("previous declaration"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
complain_class_redeclared (symbol *sym, symbol_class class, location second)
|
complain_class_redeclared (symbol *sym, symbol_class class, location second)
|
||||||
{
|
{
|
||||||
int i = 0;
|
complain (&second, complaint,
|
||||||
complain_indent (&second, complaint, &i,
|
class == token_sym
|
||||||
class == token_sym
|
? _("symbol %s redeclared as a token")
|
||||||
? _("symbol %s redeclared as a token")
|
: _("symbol %s redeclared as a nonterminal"), sym->tag);
|
||||||
: _("symbol %s redeclared as a nonterminal"), sym->tag);
|
|
||||||
if (!location_empty (sym->location))
|
if (!location_empty (sym->location))
|
||||||
{
|
subcomplain (&sym->location, complaint, _("previous definition"));
|
||||||
i += SUB_INDENT;
|
|
||||||
complain_indent (&sym->location, complaint, &i,
|
|
||||||
_("previous definition"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const symbol *
|
static const symbol *
|
||||||
@@ -431,6 +434,7 @@ symbol_code_props_set (symbol *sym, code_props_type kind,
|
|||||||
sym->content->props[kind] = *code;
|
sym->content->props[kind] = *code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------.
|
/*-----------------------------------------------------.
|
||||||
| Set the DESTRUCTOR or PRINTER associated with TYPE. |
|
| Set the DESTRUCTOR or PRINTER associated with TYPE. |
|
||||||
`-----------------------------------------------------*/
|
`-----------------------------------------------------*/
|
||||||
@@ -469,7 +473,7 @@ symbol_code_props_get (symbol *sym, code_props_type kind)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Apply default code props's only to user-defined symbols. */
|
/* Apply default code props's only to user-defined symbols. */
|
||||||
if (sym->tag[0] != '$' && sym != errtoken)
|
if (symbol_is_user_defined (sym))
|
||||||
{
|
{
|
||||||
code_props *code = &semantic_type_get (sym->content->type_name ? "*" : "",
|
code_props *code = &semantic_type_get (sym->content->type_name ? "*" : "",
|
||||||
NULL)->props[kind];
|
NULL)->props[kind];
|
||||||
@@ -547,12 +551,10 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
|
|||||||
{
|
{
|
||||||
if (s->status == declared)
|
if (s->status == declared)
|
||||||
{
|
{
|
||||||
int i = 0;
|
complain (&loc, Wother,
|
||||||
complain_indent (&loc, Wother, &i,
|
_("symbol %s redeclared"), sym->tag);
|
||||||
_("symbol %s redeclared"), sym->tag);
|
subcomplain (&sym->location, Wother,
|
||||||
i += SUB_INDENT;
|
_("previous declaration"));
|
||||||
complain_indent (&sym->location, Wother, &i,
|
|
||||||
_("previous declaration"));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -574,13 +576,13 @@ symbol_user_token_number_set (symbol *sym, int user_token_number, location loc)
|
|||||||
int *user_token_numberp = &sym->content->user_token_number;
|
int *user_token_numberp = &sym->content->user_token_number;
|
||||||
if (sym->content->class != token_sym)
|
if (sym->content->class != token_sym)
|
||||||
complain (&loc, complaint,
|
complain (&loc, complaint,
|
||||||
_("nonterminals cannot be given an explicit number"));
|
_("nonterminals cannot be given a token code"));
|
||||||
else if (*user_token_numberp != USER_NUMBER_UNDEFINED
|
else if (*user_token_numberp != USER_NUMBER_UNDEFINED
|
||||||
&& *user_token_numberp != user_token_number)
|
&& *user_token_numberp != user_token_number)
|
||||||
complain (&loc, complaint, _("redefining user token number of %s"),
|
complain (&loc, complaint, _("redefining code of token %s"),
|
||||||
sym->tag);
|
sym->tag);
|
||||||
else if (user_token_number == INT_MAX)
|
else if (user_token_number == INT_MAX)
|
||||||
complain (&loc, complaint, _("user token number of %s too large"),
|
complain (&loc, complaint, _("code of token %s too large"),
|
||||||
sym->tag);
|
sym->tag);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -723,49 +725,47 @@ symbol_make_alias (symbol *sym, symbol *str, location loc)
|
|||||||
`-------------------------------------------------------------------*/
|
`-------------------------------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
symbol_pack (symbol *this)
|
symbol_pack (symbol *sym)
|
||||||
{
|
{
|
||||||
aver (this->content->number != NUMBER_UNDEFINED);
|
aver (sym->content->number != NUMBER_UNDEFINED);
|
||||||
if (this->content->class == nterm_sym)
|
if (sym->content->class == nterm_sym)
|
||||||
this->content->number += ntokens;
|
sym->content->number += ntokens;
|
||||||
|
|
||||||
symbols[this->content->number] = this->content->symbol;
|
symbols[sym->content->number] = sym->content->symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
complain_user_token_number_redeclared (int num, symbol *first, symbol *second)
|
complain_user_token_number_redeclared (int num, symbol *first, symbol *second)
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
symbols_sort (&first, &second);
|
symbols_sort (&first, &second);
|
||||||
complain_indent (&second->location, complaint, &i,
|
complain (&second->location, complaint,
|
||||||
_("user token number %d redeclaration for %s"),
|
_("code %d reassigned to token %s"),
|
||||||
num, second->tag);
|
num, second->tag);
|
||||||
i += SUB_INDENT;
|
subcomplain (&first->location, complaint,
|
||||||
complain_indent (&first->location, complaint, &i,
|
_("previous declaration for %s"),
|
||||||
_("previous declaration for %s"),
|
first->tag);
|
||||||
first->tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------.
|
/*-------------------------------------------------.
|
||||||
| Put THIS in TOKEN_TRANSLATIONS if it is a token. |
|
| Put SYM in TOKEN_TRANSLATIONS if it is a token. |
|
||||||
`--------------------------------------------------*/
|
`-------------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
symbol_translation (symbol *this)
|
symbol_translation (symbol *sym)
|
||||||
{
|
{
|
||||||
/* Nonterminal? */
|
/* Nonterminal? */
|
||||||
if (this->content->class == token_sym
|
if (sym->content->class == token_sym
|
||||||
&& !this->is_alias)
|
&& !sym->is_alias)
|
||||||
{
|
{
|
||||||
/* A token which translation has already been set?*/
|
/* A token which translation has already been set?*/
|
||||||
if (token_translations[this->content->user_token_number]
|
if (token_translations[sym->content->user_token_number]
|
||||||
!= undeftoken->content->number)
|
!= undeftoken->content->number)
|
||||||
complain_user_token_number_redeclared
|
complain_user_token_number_redeclared
|
||||||
(this->content->user_token_number,
|
(sym->content->user_token_number,
|
||||||
symbols[token_translations[this->content->user_token_number]], this);
|
symbols[token_translations[sym->content->user_token_number]], sym);
|
||||||
else
|
else
|
||||||
token_translations[this->content->user_token_number]
|
token_translations[sym->content->user_token_number]
|
||||||
= this->content->number;
|
= sym->content->number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -847,16 +847,26 @@ symbols_new (void)
|
|||||||
accept->content->class = nterm_sym;
|
accept->content->class = nterm_sym;
|
||||||
accept->content->number = nvars++;
|
accept->content->number = nvars++;
|
||||||
|
|
||||||
/* Construct the error token */
|
/* Construct the YYERRCODE/"error" token */
|
||||||
errtoken = symbol_get ("error", empty_loc);
|
errtoken = symbol_get ("YYERRCODE", empty_loc);
|
||||||
errtoken->content->class = token_sym;
|
errtoken->content->class = token_sym;
|
||||||
errtoken->content->number = ntokens++;
|
errtoken->content->number = ntokens++;
|
||||||
|
{
|
||||||
|
symbol *alias = symbol_get ("error", empty_loc);
|
||||||
|
symbol_class_set (alias, token_sym, empty_loc, false);
|
||||||
|
symbol_make_alias (errtoken, alias, empty_loc);
|
||||||
|
}
|
||||||
|
|
||||||
/* Construct a token that represents all undefined literal tokens.
|
/* Construct the YYUNDEF/"$undefined" token that represents all
|
||||||
It is always token number 2. */
|
undefined literal tokens. It is always symbol number 2. */
|
||||||
undeftoken = symbol_get ("$undefined", empty_loc);
|
undeftoken = symbol_get ("YYUNDEF", empty_loc);
|
||||||
undeftoken->content->class = token_sym;
|
undeftoken->content->class = token_sym;
|
||||||
undeftoken->content->number = ntokens++;
|
undeftoken->content->number = ntokens++;
|
||||||
|
{
|
||||||
|
symbol *alias = symbol_get ("$undefined", empty_loc);
|
||||||
|
symbol_class_set (alias, token_sym, empty_loc, false);
|
||||||
|
symbol_make_alias (undeftoken, alias, empty_loc);
|
||||||
|
}
|
||||||
|
|
||||||
semantic_type_table = hash_xinitialize (HT_INITIAL_CAPACITY,
|
semantic_type_table = hash_xinitialize (HT_INITIAL_CAPACITY,
|
||||||
NULL,
|
NULL,
|
||||||
@@ -959,7 +969,7 @@ dummy_symbol_get (location loc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
symbol_is_dummy (const symbol *sym)
|
symbol_is_dummy (symbol const *sym)
|
||||||
{
|
{
|
||||||
return sym->tag[0] == '@' || (sym->tag[0] == '$' && sym->tag[1] == '@');
|
return sym->tag[0] == '@' || (sym->tag[0] == '$' && sym->tag[1] == '@');
|
||||||
}
|
}
|
||||||
@@ -1034,17 +1044,17 @@ symbols_token_translations_init (void)
|
|||||||
{
|
{
|
||||||
bool num_256_available_p = true;
|
bool num_256_available_p = true;
|
||||||
|
|
||||||
/* Find the highest user token number, and whether 256, the POSIX
|
/* Find the highest token code, and whether 256, the POSIX preferred
|
||||||
preferred user token number for the error token, is used. */
|
token code for the error token, is used. */
|
||||||
max_user_token_number = 0;
|
max_user_token_number = 0;
|
||||||
for (int i = 0; i < ntokens; ++i)
|
for (int i = 0; i < ntokens; ++i)
|
||||||
{
|
{
|
||||||
sym_content *this = symbols[i]->content;
|
sym_content *sym = symbols[i]->content;
|
||||||
if (this->user_token_number != USER_NUMBER_UNDEFINED)
|
if (sym->user_token_number != USER_NUMBER_UNDEFINED)
|
||||||
{
|
{
|
||||||
if (this->user_token_number > max_user_token_number)
|
if (sym->user_token_number > max_user_token_number)
|
||||||
max_user_token_number = this->user_token_number;
|
max_user_token_number = sym->user_token_number;
|
||||||
if (this->user_token_number == 256)
|
if (sym->user_token_number == 256)
|
||||||
num_256_available_p = false;
|
num_256_available_p = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1060,17 +1070,17 @@ symbols_token_translations_init (void)
|
|||||||
|
|
||||||
for (int i = 0; i < ntokens; ++i)
|
for (int i = 0; i < ntokens; ++i)
|
||||||
{
|
{
|
||||||
sym_content *this = symbols[i]->content;
|
sym_content *sym = symbols[i]->content;
|
||||||
if (this->user_token_number == USER_NUMBER_UNDEFINED)
|
if (sym->user_token_number == USER_NUMBER_UNDEFINED)
|
||||||
{
|
{
|
||||||
IGNORE_TYPE_LIMITS_BEGIN
|
IGNORE_TYPE_LIMITS_BEGIN
|
||||||
if (INT_ADD_WRAPV (max_user_token_number, 1, &max_user_token_number))
|
if (INT_ADD_WRAPV (max_user_token_number, 1, &max_user_token_number))
|
||||||
complain (NULL, fatal, _("token number too large"));
|
complain (NULL, fatal, _("token number too large"));
|
||||||
IGNORE_TYPE_LIMITS_END
|
IGNORE_TYPE_LIMITS_END
|
||||||
this->user_token_number = max_user_token_number;
|
sym->user_token_number = max_user_token_number;
|
||||||
}
|
}
|
||||||
if (this->user_token_number > max_user_token_number)
|
if (sym->user_token_number > max_user_token_number)
|
||||||
max_user_token_number = this->user_token_number;
|
max_user_token_number = sym->user_token_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
token_translations = xnmalloc (max_user_token_number + 1,
|
token_translations = xnmalloc (max_user_token_number + 1,
|
||||||
|
|||||||
+7
-2
@@ -97,6 +97,9 @@ struct symbol
|
|||||||
/** The "defining" location. */
|
/** The "defining" location. */
|
||||||
location location;
|
location location;
|
||||||
|
|
||||||
|
/** Whether this symbol is translatable. */
|
||||||
|
bool translatable;
|
||||||
|
|
||||||
/** Whether \a location is about the first uses as left-hand side
|
/** Whether \a location is about the first uses as left-hand side
|
||||||
symbol of a rule (true), or simply the first occurrence (e.g.,
|
symbol of a rule (true), or simply the first occurrence (e.g.,
|
||||||
in a %type, or as a rhs symbol of a rule). The former type of
|
in a %type, or as a rhs symbol of a rule). The former type of
|
||||||
@@ -117,6 +120,8 @@ struct symbol
|
|||||||
|
|
||||||
struct sym_content
|
struct sym_content
|
||||||
{
|
{
|
||||||
|
/** The main symbol that denotes this content (it contains the
|
||||||
|
possible alias). */
|
||||||
symbol *symbol;
|
symbol *symbol;
|
||||||
|
|
||||||
/** Its \c \%type.
|
/** Its \c \%type.
|
||||||
@@ -130,7 +135,7 @@ struct sym_content
|
|||||||
/** Its \c \%type's location. */
|
/** Its \c \%type's location. */
|
||||||
location type_loc;
|
location type_loc;
|
||||||
|
|
||||||
/** Any \c \%destructor (resp. \%printer) declared specificially for this
|
/** Any \c \%destructor (resp. \%printer) declared specifically for this
|
||||||
symbol.
|
symbol.
|
||||||
|
|
||||||
Access this field only through <tt>symbol</tt>'s interface functions. For
|
Access this field only through <tt>symbol</tt>'s interface functions. For
|
||||||
@@ -179,7 +184,7 @@ symbol *dummy_symbol_get (location loc);
|
|||||||
void symbol_print (symbol const *s, FILE *f);
|
void symbol_print (symbol const *s, FILE *f);
|
||||||
|
|
||||||
/** Is this a dummy nonterminal? */
|
/** Is this a dummy nonterminal? */
|
||||||
bool symbol_is_dummy (const symbol *sym);
|
bool symbol_is_dummy (symbol const *sym);
|
||||||
|
|
||||||
/** The name of the code_props type: "\%destructor" or "\%printer". */
|
/** The name of the code_props type: "\%destructor" or "\%printer". */
|
||||||
char const *code_props_type_string (code_props_type kind);
|
char const *code_props_type_string (code_props_type kind);
|
||||||
|
|||||||
+7
-2
@@ -73,9 +73,14 @@ typedef size_t uintptr_t;
|
|||||||
# include <verify.h>
|
# include <verify.h>
|
||||||
# include <xalloc.h>
|
# include <xalloc.h>
|
||||||
|
|
||||||
|
// Clang and ICC like to pretend they are GCC.
|
||||||
|
# if defined __GNUC__ && !defined __clang__ && !defined __ICC
|
||||||
|
# define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
|
||||||
|
# endif
|
||||||
|
|
||||||
/* See https://lists.gnu.org/archive/html/bug-bison/2019-10/msg00061.html. */
|
// See https://lists.gnu.org/archive/html/bug-bison/2019-10/msg00061.html
|
||||||
# if defined __GNUC__ && ! defined __clang__ && ! defined __ICC && __GNUC__ < 5
|
// and https://trac.macports.org/ticket/59927.
|
||||||
|
# if defined GCC_VERSION && 405 <= GCC_VERSION
|
||||||
# define IGNORE_TYPE_LIMITS_BEGIN \
|
# define IGNORE_TYPE_LIMITS_BEGIN \
|
||||||
_Pragma ("GCC diagnostic push") \
|
_Pragma ("GCC diagnostic push") \
|
||||||
_Pragma ("GCC diagnostic ignored \"-Wtype-limits\"")
|
_Pragma ("GCC diagnostic ignored \"-Wtype-limits\"")
|
||||||
|
|||||||
+1
-1
@@ -412,7 +412,7 @@ save_row (state_number s)
|
|||||||
|
|
||||||
/*------------------------------------------------------------------.
|
/*------------------------------------------------------------------.
|
||||||
| Figure out the actions for the specified state, indexed by |
|
| Figure out the actions for the specified state, indexed by |
|
||||||
| lookahead token type. |
|
| lookahead token kind. |
|
||||||
| |
|
| |
|
||||||
| The YYDEFACT table is output now. The detailed info is saved for |
|
| The YYDEFACT table is output now. The detailed info is saved for |
|
||||||
| putting into YYTABLE later. |
|
| putting into YYTABLE later. |
|
||||||
|
|||||||
+83
-35
@@ -183,7 +183,7 @@ AT_BISON_CHECK([-fcaret one.y], [1], [],
|
|||||||
[[one.y:11.13-18: error: only one %empty allowed per rule
|
[[one.y:11.13-18: error: only one %empty allowed per rule
|
||||||
11 | %empty {} %empty
|
11 | %empty {} %empty
|
||||||
| ^~~~~~
|
| ^~~~~~
|
||||||
one.y:11.3-8: previous declaration
|
one.y:11.3-8: note: previous declaration
|
||||||
11 | %empty {} %empty
|
11 | %empty {} %empty
|
||||||
| ^~~~~~
|
| ^~~~~~
|
||||||
one.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
one.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
@@ -193,7 +193,7 @@ AT_BISON_CHECK([-fcaret -u one.y], [1], [],
|
|||||||
[[one.y:11.13-18: error: only one %empty allowed per rule
|
[[one.y:11.13-18: error: only one %empty allowed per rule
|
||||||
11 | %empty {} %empty
|
11 | %empty {} %empty
|
||||||
| ^~~~~~
|
| ^~~~~~
|
||||||
one.y:11.3-8: previous declaration
|
one.y:11.3-8: note: previous declaration
|
||||||
11 | %empty {} %empty
|
11 | %empty {} %empty
|
||||||
| ^~~~~~
|
| ^~~~~~
|
||||||
bison: file 'one.y' was updated (backup: 'one.y~')
|
bison: file 'one.y' was updated (backup: 'one.y~')
|
||||||
@@ -1123,20 +1123,30 @@ AT_PARSER_CHECK([input --debug], 1,
|
|||||||
]],
|
]],
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
Reading a token: Next token is token 'a' (1.1: <> printer for 'a' @ 1)
|
Stack now 0
|
||||||
|
Reading a token
|
||||||
|
Next token is token 'a' (1.1: <> printer for 'a' @ 1)
|
||||||
Shifting token 'a' (1.1: <> printer for 'a' @ 1)
|
Shifting token 'a' (1.1: <> printer for 'a' @ 1)
|
||||||
Entering state 1
|
Entering state 1
|
||||||
Reading a token: Next token is token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
|
Stack now 0 1
|
||||||
|
Reading a token
|
||||||
|
Next token is token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
|
||||||
Shifting token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
|
Shifting token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
|
||||||
Entering state 3
|
Entering state 3
|
||||||
Reading a token: Next token is token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
|
Stack now 0 1 3
|
||||||
|
Reading a token
|
||||||
|
Next token is token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
|
||||||
Shifting token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
|
Shifting token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
|
||||||
Entering state 5
|
Entering state 5
|
||||||
Reading a token: Next token is token 'd' (1.4: <> printer for 'd' @ 4)
|
Stack now 0 1 3 5
|
||||||
|
Reading a token
|
||||||
|
Next token is token 'd' (1.4: <> printer for 'd' @ 4)
|
||||||
Shifting token 'd' (1.4: <> printer for 'd' @ 4)
|
Shifting token 'd' (1.4: <> printer for 'd' @ 4)
|
||||||
Entering state 6
|
Entering state 6
|
||||||
Reading a token: Now at end of input.
|
Stack now 0 1 3 5 6
|
||||||
1.5: syntax error, unexpected $end, expecting 'e'
|
Reading a token
|
||||||
|
Now at end of input.
|
||||||
|
1.5: syntax error, unexpected end of file, expecting 'e'
|
||||||
Error: popping token 'd' (1.4: <> printer for 'd' @ 4)
|
Error: popping token 'd' (1.4: <> printer for 'd' @ 4)
|
||||||
Stack now 0 1 3 5
|
Stack now 0 1 3 5
|
||||||
Error: popping token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
|
Error: popping token 'c' (1.3: 'b'/'c' printer for 'c' @ 3)
|
||||||
@@ -1145,7 +1155,7 @@ Error: popping token 'b' (1.2: 'b'/'c' printer for 'b' @ 2)
|
|||||||
Stack now 0 1
|
Stack now 0 1
|
||||||
Error: popping token 'a' (1.1: <> printer for 'a' @ 1)
|
Error: popping token 'a' (1.1: <> printer for 'a' @ 1)
|
||||||
Stack now 0
|
Stack now 0
|
||||||
Cleanup: discarding lookahead token $end (1.5: )
|
Cleanup: discarding lookahead token "end of file" (1.5: )
|
||||||
Stack now 0
|
Stack now 0
|
||||||
]])
|
]])
|
||||||
|
|
||||||
@@ -1232,26 +1242,40 @@ AT_PARSER_CHECK([input --debug], 1,
|
|||||||
]],
|
]],
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
Reading a token: Next token is token 'a' (<*>/<field2>/e printer)
|
Stack now 0
|
||||||
|
Reading a token
|
||||||
|
Next token is token 'a' (<*>/<field2>/e printer)
|
||||||
Shifting token 'a' (<*>/<field2>/e printer)
|
Shifting token 'a' (<*>/<field2>/e printer)
|
||||||
Entering state 1
|
Entering state 1
|
||||||
Reading a token: Next token is token 'b' (<field1> printer)
|
Stack now 0 1
|
||||||
|
Reading a token
|
||||||
|
Next token is token 'b' (<field1> printer)
|
||||||
Shifting token 'b' (<field1> printer)
|
Shifting token 'b' (<field1> printer)
|
||||||
Entering state 3
|
Entering state 3
|
||||||
Reading a token: Next token is token 'c' ('c' printer)
|
Stack now 0 1 3
|
||||||
|
Reading a token
|
||||||
|
Next token is token 'c' ('c' printer)
|
||||||
Shifting token 'c' ('c' printer)
|
Shifting token 'c' ('c' printer)
|
||||||
Entering state 5
|
Entering state 5
|
||||||
Reading a token: Next token is token 'd' ('d' printer)
|
Stack now 0 1 3 5
|
||||||
|
Reading a token
|
||||||
|
Next token is token 'd' ('d' printer)
|
||||||
Shifting token 'd' ('d' printer)
|
Shifting token 'd' ('d' printer)
|
||||||
Entering state 6
|
Entering state 6
|
||||||
Reading a token: Next token is token 'e' (<*>/<field2>/e printer)
|
Stack now 0 1 3 5 6
|
||||||
|
Reading a token
|
||||||
|
Next token is token 'e' (<*>/<field2>/e printer)
|
||||||
Shifting token 'e' (<*>/<field2>/e printer)
|
Shifting token 'e' (<*>/<field2>/e printer)
|
||||||
Entering state 7
|
Entering state 7
|
||||||
Reading a token: Next token is token 'f' (<*>/<field2>/e printer)
|
Stack now 0 1 3 5 6 7
|
||||||
|
Reading a token
|
||||||
|
Next token is token 'f' (<*>/<field2>/e printer)
|
||||||
Shifting token 'f' (<*>/<field2>/e printer)
|
Shifting token 'f' (<*>/<field2>/e printer)
|
||||||
Entering state 8
|
Entering state 8
|
||||||
Reading a token: Now at end of input.
|
Stack now 0 1 3 5 6 7 8
|
||||||
syntax error, unexpected $end, expecting 'g'
|
Reading a token
|
||||||
|
Now at end of input.
|
||||||
|
syntax error, unexpected end of file, expecting 'g'
|
||||||
Error: popping token 'f' (<*>/<field2>/e printer)
|
Error: popping token 'f' (<*>/<field2>/e printer)
|
||||||
Stack now 0 1 3 5 6 7
|
Stack now 0 1 3 5 6 7
|
||||||
Error: popping token 'e' (<*>/<field2>/e printer)
|
Error: popping token 'e' (<*>/<field2>/e printer)
|
||||||
@@ -1264,7 +1288,7 @@ Error: popping token 'b' (<field1> printer)
|
|||||||
Stack now 0 1
|
Stack now 0 1
|
||||||
Error: popping token 'a' (<*>/<field2>/e printer)
|
Error: popping token 'a' (<*>/<field2>/e printer)
|
||||||
Stack now 0
|
Stack now 0
|
||||||
Cleanup: discarding lookahead token $end ()
|
Cleanup: discarding lookahead token "end of file" ()
|
||||||
Stack now 0
|
Stack now 0
|
||||||
]])
|
]])
|
||||||
|
|
||||||
@@ -1279,6 +1303,15 @@ AT_CLEANUP
|
|||||||
|
|
||||||
AT_SETUP([Default %printer and %destructor for user-defined end token])
|
AT_SETUP([Default %printer and %destructor for user-defined end token])
|
||||||
|
|
||||||
|
# Enable declaration of default %printer/%destructor. Make the parser
|
||||||
|
# use these for all user-declared grammar symbols for which the user
|
||||||
|
# does not declare a specific %printer/%destructor. Thus, the parser
|
||||||
|
# uses it for token 0 if the user declares it but not if Bison
|
||||||
|
# generates it as $end. Discussed starting at
|
||||||
|
# <http://lists.gnu.org/r/bison-patches/2006-02/msg00064.html>,
|
||||||
|
# <http://lists.gnu.org/r/bison-patches/2006-06/msg00091.html>, and
|
||||||
|
# <http://lists.gnu.org/r/bison-patches/2006-07/msg00019.html>.
|
||||||
|
|
||||||
# AT_TEST(TYPED)
|
# AT_TEST(TYPED)
|
||||||
# --------------
|
# --------------
|
||||||
m4_pushdef([AT_TEST],
|
m4_pushdef([AT_TEST],
|
||||||
@@ -1358,14 +1391,17 @@ AT_PARSER_CHECK([input$1 --debug], 0,
|
|||||||
]],
|
]],
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
|
Stack now 0
|
||||||
Reducing stack by rule 1 (line 49):
|
Reducing stack by rule 1 (line 49):
|
||||||
-> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1)
|
-> $$ = nterm start (1.1: <]]kind[[> for 'S' @ 1)
|
||||||
Stack now 0
|
|
||||||
Entering state 1
|
Entering state 1
|
||||||
Reading a token: Now at end of input.
|
Stack now 0 1
|
||||||
|
Reading a token
|
||||||
|
Now at end of input.
|
||||||
Shifting token END (1.1: <]]kind[[> for 'E' @ 1)
|
Shifting token END (1.1: <]]kind[[> for 'E' @ 1)
|
||||||
Entering state 2
|
Entering state 2
|
||||||
Stack now 0 1 2
|
Stack now 0 1 2
|
||||||
|
Stack now 0 1 2
|
||||||
Cleanup: popping token END (1.1: <]]kind[[> for 'E' @ 1)
|
Cleanup: popping token END (1.1: <]]kind[[> for 'E' @ 1)
|
||||||
Cleanup: popping nterm start (1.1: <]]kind[[> for 'S' @ 1)
|
Cleanup: popping nterm start (1.1: <]]kind[[> for 'S' @ 1)
|
||||||
]])
|
]])
|
||||||
@@ -1440,17 +1476,24 @@ AT_COMPILE([input])
|
|||||||
AT_PARSER_CHECK([input --debug], [1], [],
|
AT_PARSER_CHECK([input --debug], [1], [],
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
Reading a token: Next token is token 'a' ('a')
|
Stack now 0
|
||||||
|
Reading a token
|
||||||
|
Next token is token 'a' ('a')
|
||||||
Shifting token 'a' ('a')
|
Shifting token 'a' ('a')
|
||||||
Entering state 1
|
Entering state 1
|
||||||
Reading a token: Next token is token 'b' ('b')
|
Stack now 0 1
|
||||||
|
Reading a token
|
||||||
|
Next token is token 'b' ('b')
|
||||||
syntax error
|
syntax error
|
||||||
Shifting token error ()
|
Shifting token error ()
|
||||||
Entering state 3
|
Entering state 3
|
||||||
|
Stack now 0 1 3
|
||||||
Next token is token 'b' ('b')
|
Next token is token 'b' ('b')
|
||||||
Shifting token 'b' ('b')
|
Shifting token 'b' ('b')
|
||||||
Entering state 5
|
Entering state 5
|
||||||
Reading a token: Next token is token $undefined ()
|
Stack now 0 1 3 5
|
||||||
|
Reading a token
|
||||||
|
Next token is token "invalid token" ()
|
||||||
Error: popping token 'b' ('b')
|
Error: popping token 'b' ('b')
|
||||||
DESTROY 'b'
|
DESTROY 'b'
|
||||||
Stack now 0 1 3
|
Stack now 0 1 3
|
||||||
@@ -1458,14 +1501,17 @@ Error: popping token error ()
|
|||||||
Stack now 0 1
|
Stack now 0 1
|
||||||
Shifting token error ()
|
Shifting token error ()
|
||||||
Entering state 3
|
Entering state 3
|
||||||
Next token is token $undefined ()
|
Stack now 0 1 3
|
||||||
Error: discarding token $undefined ()
|
Next token is token "invalid token" ()
|
||||||
|
Error: discarding token "invalid token" ()
|
||||||
Error: popping token error ()
|
Error: popping token error ()
|
||||||
Stack now 0 1
|
Stack now 0 1
|
||||||
Shifting token error ()
|
Shifting token error ()
|
||||||
Entering state 3
|
Entering state 3
|
||||||
Reading a token: Now at end of input.
|
Stack now 0 1 3
|
||||||
Cleanup: discarding lookahead token $end ()
|
Reading a token
|
||||||
|
Now at end of input.
|
||||||
|
Cleanup: discarding lookahead token "end of file" ()
|
||||||
Stack now 0 1 3
|
Stack now 0 1 3
|
||||||
Cleanup: popping token error ()
|
Cleanup: popping token error ()
|
||||||
Cleanup: popping token 'a' ('a')
|
Cleanup: popping token 'a' ('a')
|
||||||
@@ -1608,23 +1654,25 @@ AT_COMPILE([input])
|
|||||||
AT_PARSER_CHECK([input --debug], 1,,
|
AT_PARSER_CHECK([input --debug], 1,,
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
|
Stack now 0
|
||||||
Reducing stack by rule 1 (line 30):
|
Reducing stack by rule 1 (line 30):
|
||||||
-> $$ = nterm $@1 (: )
|
-> $$ = nterm $@1 (: )
|
||||||
Stack now 0
|
|
||||||
Entering state 2
|
Entering state 2
|
||||||
|
Stack now 0 2
|
||||||
Reducing stack by rule 2 (line 31):
|
Reducing stack by rule 2 (line 31):
|
||||||
-> $$ = nterm @2 (: 2)
|
-> $$ = nterm @2 (: 2)
|
||||||
Stack now 0 2
|
|
||||||
Entering state 4
|
Entering state 4
|
||||||
|
Stack now 0 2 4
|
||||||
Reducing stack by rule 3 (line 32):
|
Reducing stack by rule 3 (line 32):
|
||||||
-> $$ = nterm @3 (: 3)
|
-> $$ = nterm @3 (: 3)
|
||||||
Stack now 0 2 4
|
|
||||||
Entering state 5
|
Entering state 5
|
||||||
|
Stack now 0 2 4 5
|
||||||
Reducing stack by rule 4 (line 33):
|
Reducing stack by rule 4 (line 33):
|
||||||
-> $$ = nterm @4 (: 4)
|
-> $$ = nterm @4 (: 4)
|
||||||
Stack now 0 2 4 5
|
|
||||||
Entering state 6
|
Entering state 6
|
||||||
Reading a token: Now at end of input.
|
Stack now 0 2 4 5 6
|
||||||
|
Reading a token
|
||||||
|
Now at end of input.
|
||||||
syntax error
|
syntax error
|
||||||
Error: popping nterm @4 (: 4)
|
Error: popping nterm @4 (: 4)
|
||||||
DESTROY 4
|
DESTROY 4
|
||||||
@@ -1637,7 +1685,7 @@ DESTROY 2
|
|||||||
Stack now 0 2
|
Stack now 0 2
|
||||||
Error: popping nterm $@1 (: )
|
Error: popping nterm $@1 (: )
|
||||||
Stack now 0
|
Stack now 0
|
||||||
Cleanup: discarding lookahead token $end (: )
|
Cleanup: discarding lookahead token "end of file" (: )
|
||||||
Stack now 0
|
Stack now 0
|
||||||
]])
|
]])
|
||||||
|
|
||||||
@@ -1790,9 +1838,9 @@ AT_PARSER_CHECK([input --debug], 0, [], [stderr])
|
|||||||
# Don't be too picky on the traces, GLR is not exactly the same. Keep
|
# Don't be too picky on the traces, GLR is not exactly the same. Keep
|
||||||
# only the lines from the printer.
|
# only the lines from the printer.
|
||||||
AT_CHECK([[sed -ne '/ival:/p' stderr]], 0,
|
AT_CHECK([[sed -ne '/ival:/p' stderr]], 0,
|
||||||
[[Reading a token: Next token is token UNTYPED (ival: 10, fval: 0.1)
|
[[Next token is token UNTYPED (ival: 10, fval: 0.1)
|
||||||
Shifting token UNTYPED (ival: 10, fval: 0.1)
|
Shifting token UNTYPED (ival: 10, fval: 0.1)
|
||||||
Reading a token: Next token is token INT (ival: 20, fval: 0.2)
|
Next token is token INT (ival: 20, fval: 0.2)
|
||||||
Shifting token INT (ival: 20, fval: 0.2)
|
Shifting token INT (ival: 20, fval: 0.2)
|
||||||
$][1 = token UNTYPED (ival: 10, fval: 0.1)
|
$][1 = token UNTYPED (ival: 10, fval: 0.1)
|
||||||
$][2 = token INT (ival: 20, fval: 0.2)
|
$][2 = token INT (ival: 20, fval: 0.2)
|
||||||
|
|||||||
+16
-8
@@ -385,7 +385,7 @@ AT_DATA_GRAMMAR([list.y],
|
|||||||
// Starting with :: to ensure we don't output "<::" which starts by the
|
// Starting with :: to ensure we don't output "<::" which starts by the
|
||||||
// digraph for the left square bracket.
|
// digraph for the left square bracket.
|
||||||
%type <::string> item;
|
%type <::string> item;
|
||||||
// Using the template type to exercize its parsing.
|
// Using the template type to exercise its parsing.
|
||||||
%type <::std::vector<string>> list;
|
%type <::std::vector<string>> list;
|
||||||
|
|
||||||
%printer { yyo << $$; } <int> <::string> <::std::vector<string>>;
|
%printer { yyo << $$; } <int> <::string> <::std::vector<string>>;
|
||||||
@@ -648,23 +648,28 @@ AT_FULL_COMPILE([[input]])
|
|||||||
AT_PARSER_CHECK([[input]], [[0]], [[]],
|
AT_PARSER_CHECK([[input]], [[0]], [[]],
|
||||||
[[Starting parse
|
[[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
Reading a token: Next token is token NUMBER (1)
|
Stack now 0
|
||||||
|
Reading a token
|
||||||
|
Next token is token NUMBER (1)
|
||||||
Shifting token NUMBER (1)
|
Shifting token NUMBER (1)
|
||||||
Entering state 1
|
Entering state 1
|
||||||
|
Stack now 0 1
|
||||||
Reducing stack by rule 1 (line 34):
|
Reducing stack by rule 1 (line 34):
|
||||||
$1 = token NUMBER (1)
|
$1 = token NUMBER (1)
|
||||||
-> $$ = nterm expr (10)
|
-> $$ = nterm expr (10)
|
||||||
destroy: 1
|
destroy: 1
|
||||||
Stack now 0
|
|
||||||
Entering state 2
|
Entering state 2
|
||||||
Reading a token: Next token is token NUMBER (30)
|
Stack now 0 2
|
||||||
|
Reading a token
|
||||||
|
Next token is token NUMBER (30)
|
||||||
Reducing stack by rule 2 (line 35):
|
Reducing stack by rule 2 (line 35):
|
||||||
-> $$ = nterm @1 (20)
|
-> $$ = nterm @1 (20)
|
||||||
Stack now 2 0
|
|
||||||
Entering state 4
|
Entering state 4
|
||||||
|
Stack now 0 2 4
|
||||||
Next token is token NUMBER (30)
|
Next token is token NUMBER (30)
|
||||||
Shifting token NUMBER (30)
|
Shifting token NUMBER (30)
|
||||||
Entering state 5
|
Entering state 5
|
||||||
|
Stack now 0 2 4 5
|
||||||
Reducing stack by rule 3 (line 35):
|
Reducing stack by rule 3 (line 35):
|
||||||
$1 = nterm expr (10)
|
$1 = nterm expr (10)
|
||||||
$2 = nterm @1 (20)
|
$2 = nterm @1 (20)
|
||||||
@@ -674,11 +679,14 @@ expr: 10 20 30
|
|||||||
destroy: 30
|
destroy: 30
|
||||||
destroy: 20
|
destroy: 20
|
||||||
destroy: 10
|
destroy: 10
|
||||||
Stack now 0
|
|
||||||
Entering state 2
|
Entering state 2
|
||||||
Reading a token: Next token is token EOI ()
|
Stack now 0 2
|
||||||
|
Reading a token
|
||||||
|
Next token is token EOI ()
|
||||||
Shifting token EOI ()
|
Shifting token EOI ()
|
||||||
Entering state 3
|
Entering state 3
|
||||||
|
Stack now 0 2 3
|
||||||
|
Stack now 0 2 3
|
||||||
Cleanup: popping token EOI ()
|
Cleanup: popping token EOI ()
|
||||||
Cleanup: popping nterm expr (40)
|
Cleanup: popping nterm expr (40)
|
||||||
destroy: 40
|
destroy: 40
|
||||||
@@ -1322,7 +1330,7 @@ AT_PARSER_CHECK([[input aaaae]], [[2]], [[]],
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
AT_PARSER_CHECK([[input aaaaE]], [[2]], [[]],
|
AT_PARSER_CHECK([[input aaaaE]], [[2]], [[]],
|
||||||
[[exception caught: syntax error, unexpected $end, expecting 'a'
|
[[exception caught: syntax error, unexpected end of file, expecting 'a'
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_PARSER_CHECK([[input aaaaT]], [[1]])
|
AT_PARSER_CHECK([[input aaaaT]], [[1]])
|
||||||
|
|||||||
+468
-164
@@ -25,6 +25,10 @@
|
|||||||
|
|
||||||
m4_pushdef([AT_CALC_MAIN], [AT_LANG_DISPATCH([$0], $@)])
|
m4_pushdef([AT_CALC_MAIN], [AT_LANG_DISPATCH([$0], $@)])
|
||||||
|
|
||||||
|
# Whether token translation is supported.
|
||||||
|
m4_pushdef([AT_TOKEN_TRANSLATE_IF],
|
||||||
|
[AT_ERROR_CUSTOM_IF([$1], [AT_ERROR_DETAILED_IF([$1], [$2])])])
|
||||||
|
|
||||||
m4_define([AT_CALC_MAIN(c)],
|
m4_define([AT_CALC_MAIN(c)],
|
||||||
[[#include <assert.h>
|
[[#include <assert.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -34,9 +38,9 @@ namespace
|
|||||||
{
|
{
|
||||||
/* A C++ ]AT_NAME_PREFIX[parse that simulates the C signature. */
|
/* A C++ ]AT_NAME_PREFIX[parse that simulates the C signature. */
|
||||||
int
|
int
|
||||||
]AT_NAME_PREFIX[parse (]AT_PARAM_IF([semantic_value *result, int *count]))[
|
]AT_NAME_PREFIX[parse (]AT_PARAM_IF([semantic_value *result, int *count, int *nerrs]))[
|
||||||
{
|
{
|
||||||
]AT_NAME_PREFIX[::parser parser]AT_PARAM_IF([ (result, count)])[;
|
]AT_NAME_PREFIX[::parser parser]AT_PARAM_IF([ (result, count, nerrs)])[;
|
||||||
#if ]AT_API_PREFIX[DEBUG
|
#if ]AT_API_PREFIX[DEBUG
|
||||||
parser.set_debug_level (1);
|
parser.set_debug_level (1);
|
||||||
#endif
|
#endif
|
||||||
@@ -45,15 +49,20 @@ namespace
|
|||||||
}
|
}
|
||||||
]])[
|
]])[
|
||||||
|
|
||||||
|
/* Value of the last computation. */
|
||||||
semantic_value global_result = 0;
|
semantic_value global_result = 0;
|
||||||
|
/* Total number of computations. */
|
||||||
int global_count = 0;
|
int global_count = 0;
|
||||||
|
/* Total number of errors. */
|
||||||
|
int global_nerrs = 0;
|
||||||
|
|
||||||
/* A C main function. */
|
/* A C main function. */
|
||||||
int
|
int
|
||||||
main (int argc, const char **argv)
|
main (int argc, const char **argv)
|
||||||
{
|
{]AT_PARAM_IF([[
|
||||||
semantic_value result = 0;
|
semantic_value result = 0;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
int nerrs = 0;]])[
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
/* This used to be alarm (10), but that isn't enough time for a July
|
/* This used to be alarm (10), but that isn't enough time for a July
|
||||||
@@ -75,11 +84,13 @@ main (int argc, const char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
]AT_CXX_IF([], [AT_DEBUG_IF([ ]AT_NAME_PREFIX[debug = 1;])])[
|
]AT_CXX_IF([], [AT_DEBUG_IF([ ]AT_NAME_PREFIX[debug = 1;])])[
|
||||||
status = ]AT_NAME_PREFIX[parse (]AT_PARAM_IF([[&result, &count]])[);
|
status = ]AT_NAME_PREFIX[parse (]AT_PARAM_IF([[&result, &count, &nerrs]])[);
|
||||||
if (fclose (input))
|
if (fclose (input))
|
||||||
perror ("fclose");
|
perror ("fclose");]AT_PARAM_IF([[
|
||||||
assert (global_result == result); (void) result;
|
assert (global_result == result); (void) result;
|
||||||
assert (global_count == count); (void) count;
|
assert (global_count == count); (void) count;
|
||||||
|
assert (global_nerrs == nerrs); (void) nerrs;
|
||||||
|
printf ("final: %d %d %d\n", global_result, global_count, global_nerrs);]])[
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
]])
|
]])
|
||||||
@@ -88,18 +99,32 @@ m4_copy([AT_CALC_MAIN(c)], [AT_CALC_MAIN(c++)])
|
|||||||
|
|
||||||
m4_define([AT_CALC_MAIN(d)],
|
m4_define([AT_CALC_MAIN(d)],
|
||||||
[[int main (string[] args)
|
[[int main (string[] args)
|
||||||
{
|
{]AT_PARAM_IF([[
|
||||||
semantic_value result = 0;
|
semantic_value result = 0;
|
||||||
int count = 0;
|
int count = 0;]])[
|
||||||
|
|
||||||
File input = args.length == 2 ? File (args[1], "r") : stdin;
|
File input = args.length == 2 ? File (args[1], "r") : stdin;
|
||||||
auto l = calcLexer (input);
|
auto l = calcLexer (input);
|
||||||
auto p = new YYParser (l);
|
auto p = new YYParser (l);]AT_DEBUG_IF([[
|
||||||
|
p.setDebugLevel (1);]])[
|
||||||
return !p.parse ();
|
return !p.parse ();
|
||||||
}
|
}
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
|
||||||
|
m4_define([AT_CALC_MAIN(java)],
|
||||||
|
[[public static void main (String[] args) throws IOException
|
||||||
|
{]AT_LEXPARAM_IF([[
|
||||||
|
Calc p = new Calc (System.in);]], [[
|
||||||
|
CalcLexer l = new CalcLexer (System.in);
|
||||||
|
Calc p = new Calc (l);]])AT_DEBUG_IF([[
|
||||||
|
p.setDebugLevel (1);]])[
|
||||||
|
boolean success = p.parse ();
|
||||||
|
if (!success)
|
||||||
|
System.exit (1);
|
||||||
|
}
|
||||||
|
]])
|
||||||
|
|
||||||
|
|
||||||
# --------------- #
|
# --------------- #
|
||||||
# AT_CALC_YYLEX. #
|
# AT_CALC_YYLEX. #
|
||||||
@@ -281,13 +306,13 @@ class CalcLexer(R) : Lexer
|
|||||||
|
|
||||||
// Handle EOF.
|
// Handle EOF.
|
||||||
if (input.empty)
|
if (input.empty)
|
||||||
return YYTokenType.EOF;
|
return TokenKind.CALC_EOF;
|
||||||
|
|
||||||
// Numbers.
|
// Numbers.
|
||||||
if (input.front.isNumber)
|
if (input.front.isNumber)
|
||||||
{
|
{
|
||||||
semanticVal_.ival = parseInt;
|
semanticVal_.ival = parseInt;
|
||||||
return YYTokenType.NUM;
|
return TokenKind.NUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Individual characters
|
// Individual characters
|
||||||
@@ -306,6 +331,70 @@ class CalcLexer(R) : Lexer
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
|
|
||||||
|
m4_define([AT_CALC_YYLEX(java)],
|
||||||
|
[AT_LEXPARAM_IF([[%code lexer {]],
|
||||||
|
[[%code epilogue { class CalcLexer implements Calc.Lexer {]])[
|
||||||
|
StreamTokenizer st;]AT_LOCATION_IF([[
|
||||||
|
PositionReader reader;]])[
|
||||||
|
|
||||||
|
public ]AT_LEXPARAM_IF([[YYLexer]], [[CalcLexer]])[ (InputStream is)
|
||||||
|
{]AT_LOCATION_IF([[
|
||||||
|
reader = new PositionReader (new InputStreamReader (is));
|
||||||
|
st = new StreamTokenizer (reader);]], [[
|
||||||
|
st = new StreamTokenizer (new InputStreamReader (is));]])[
|
||||||
|
st.resetSyntax ();
|
||||||
|
st.eolIsSignificant (true);
|
||||||
|
st.wordChars ('0', '9');
|
||||||
|
}
|
||||||
|
|
||||||
|
]AT_LOCATION_IF([[
|
||||||
|
Position start = new Position (1, 0);
|
||||||
|
Position end = new Position (1, 0);
|
||||||
|
|
||||||
|
public Position getStartPos () {
|
||||||
|
return new Position (start);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Position getEndPos () {
|
||||||
|
return new Position (end);
|
||||||
|
}
|
||||||
|
|
||||||
|
]])[
|
||||||
|
]AT_YYERROR_DEFINE[
|
||||||
|
|
||||||
|
Integer yylval;
|
||||||
|
|
||||||
|
public Object getLVal () {
|
||||||
|
return yylval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int yylex () throws IOException {;]AT_LOCATION_IF([[
|
||||||
|
start.set (reader.getPosition ());]])[
|
||||||
|
int ttype = st.nextToken ();]AT_LOCATION_IF([[
|
||||||
|
end.set (reader.getPosition ());]])[
|
||||||
|
switch (ttype)
|
||||||
|
{
|
||||||
|
case StreamTokenizer.TT_EOF:
|
||||||
|
return EOF;
|
||||||
|
case StreamTokenizer.TT_EOL:;]AT_LOCATION_IF([[
|
||||||
|
end.line += 1;
|
||||||
|
end.column = 0;]])[
|
||||||
|
return (int) '\n';
|
||||||
|
case StreamTokenizer.TT_WORD:
|
||||||
|
yylval = new Integer (st.sval);]AT_LOCATION_IF([[
|
||||||
|
end.set (reader.getPreviousPosition ());]])[
|
||||||
|
return NUM;
|
||||||
|
case ' ': case '\t':
|
||||||
|
return yylex ();
|
||||||
|
default:
|
||||||
|
return ttype;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]AT_LEXPARAM_IF([], [[}]])[
|
||||||
|
};
|
||||||
|
]])
|
||||||
|
|
||||||
|
|
||||||
# -------------- #
|
# -------------- #
|
||||||
# AT_DATA_CALC. #
|
# AT_DATA_CALC. #
|
||||||
# -------------- #
|
# -------------- #
|
||||||
@@ -326,19 +415,23 @@ class CalcLexer(R) : Lexer
|
|||||||
# stress the use of the generated parser header. To avoid code
|
# stress the use of the generated parser header. To avoid code
|
||||||
# duplication, AT_CALC_YYLEX and AT_CALC_MAIN contain the body of these
|
# duplication, AT_CALC_YYLEX and AT_CALC_MAIN contain the body of these
|
||||||
# two later files.
|
# two later files.
|
||||||
m4_define([_AT_DATA_CALC_Y],
|
m4_pushdef([_AT_DATA_CALC_Y],
|
||||||
[m4_if([$1$2$3], $[1]$[2]$[3], [],
|
[m4_if([$1$2$3], $[1]$[2]$[3], [],
|
||||||
[m4_fatal([$0: Invalid arguments: $@])])dnl
|
[m4_fatal([$0: Invalid arguments: $@])])dnl
|
||||||
|
AT_LANG_DISPATCH([$0], $@)])
|
||||||
|
|
||||||
AT_DATA_GRAMMAR([calc.y],
|
m4_define([_AT_DATA_CALC_Y(c)],
|
||||||
|
[AT_DATA_GRAMMAR([calc.y],
|
||||||
[[/* Infix notation calculator--calc */
|
[[/* Infix notation calculator--calc */
|
||||||
]$4[
|
]$4[
|
||||||
]AT_CXX_IF([%define global_tokens_and_yystype])[
|
]AT_CXX_IF([%define global_tokens_and_yystype])[
|
||||||
]AT_D_IF([[
|
]AT_LANG_MATCH(
|
||||||
|
[d], [[
|
||||||
%code imports {
|
%code imports {
|
||||||
alias semantic_value = int;
|
alias semantic_value = int;
|
||||||
}
|
}
|
||||||
]], [[
|
]],
|
||||||
|
[c\|c++], [[
|
||||||
%code requires
|
%code requires
|
||||||
{
|
{
|
||||||
]AT_LOCATION_TYPE_SPAN_IF([[
|
]AT_LOCATION_TYPE_SPAN_IF([[
|
||||||
@@ -387,7 +480,7 @@ void location_print (FILE *o, Span s);
|
|||||||
%printer { ]AT_CXX_IF([[yyo << $$]],
|
%printer { ]AT_CXX_IF([[yyo << $$]],
|
||||||
[[fprintf (yyo, "%d", $$)]])[; } <ival>;
|
[[fprintf (yyo, "%d", $$)]])[; } <ival>;
|
||||||
|
|
||||||
]AT_D_IF([], [[
|
]AT_LANG_MATCH([c\|c++], [[
|
||||||
%code provides
|
%code provides
|
||||||
{
|
{
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -395,6 +488,7 @@ void location_print (FILE *o, Span s);
|
|||||||
extern FILE *input;
|
extern FILE *input;
|
||||||
extern semantic_value global_result;
|
extern semantic_value global_result;
|
||||||
extern int global_count;
|
extern int global_count;
|
||||||
|
extern int global_nerrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
%code
|
%code
|
||||||
@@ -408,6 +502,21 @@ void location_print (FILE *o, Span s);
|
|||||||
|
|
||||||
]AT_YYERROR_DECLARE[
|
]AT_YYERROR_DECLARE[
|
||||||
]AT_YYLEX_DECLARE_EXTERN[
|
]AT_YYLEX_DECLARE_EXTERN[
|
||||||
|
|
||||||
|
]AT_TOKEN_TRANSLATE_IF([[
|
||||||
|
#define N_
|
||||||
|
static
|
||||||
|
const char *
|
||||||
|
_ (const char *cp)
|
||||||
|
{
|
||||||
|
if (strcmp (cp, "end of input") == 0)
|
||||||
|
return "end of file";
|
||||||
|
else if (strcmp (cp, "number") == 0)
|
||||||
|
return "nombre";
|
||||||
|
else
|
||||||
|
return cp;
|
||||||
|
}
|
||||||
|
]])[
|
||||||
}
|
}
|
||||||
]])[
|
]])[
|
||||||
|
|
||||||
@@ -419,8 +528,8 @@ void location_print (FILE *o, Span s);
|
|||||||
}]])[
|
}]])[
|
||||||
|
|
||||||
/* Bison Declarations */
|
/* Bison Declarations */
|
||||||
%token CALC_EOF 0 "end of input"
|
%token CALC_EOF 0 ]AT_TOKEN_TRANSLATE_IF([_("end of input")], ["end of input"])[
|
||||||
%token <ival> NUM "number"
|
%token <ival> NUM "number"
|
||||||
%type <ival> exp
|
%type <ival> exp
|
||||||
|
|
||||||
%nonassoc '=' /* comparison */
|
%nonassoc '=' /* comparison */
|
||||||
@@ -445,22 +554,40 @@ exp:
|
|||||||
NUM
|
NUM
|
||||||
| exp '=' exp
|
| exp '=' exp
|
||||||
{
|
{
|
||||||
if ($1 != $3)]AT_D_IF([
|
if ($1 != $3)]AT_LANG_CASE(
|
||||||
stderr.writefln ("calc: error: %d != %d", $1, $3);], [
|
[c], [[
|
||||||
fprintf (stderr, "calc: error: %d != %d\n", $1, $3);], [
|
{
|
||||||
])[
|
char buf[1024];
|
||||||
|
snprintf (buf, sizeof buf, "calc: error: %d != %d", $1, $3);]AT_YYERROR_ARG_LOC_IF([[
|
||||||
|
yyerror (&@$, ]AT_PARAM_IF([result, count, nerrs, ])[buf);]], [[
|
||||||
|
{
|
||||||
|
YYLTYPE old_yylloc = yylloc;
|
||||||
|
yylloc = @$;
|
||||||
|
yyerror (]AT_PARAM_IF([result, count, nerrs, ])[buf);
|
||||||
|
yylloc = old_yylloc;
|
||||||
|
}
|
||||||
|
]])[
|
||||||
|
}]],
|
||||||
|
[c++], [[
|
||||||
|
{
|
||||||
|
char buf[1024];
|
||||||
|
snprintf (buf, sizeof buf, "calc: error: %d != %d", $1, $3);
|
||||||
|
]AT_GLR_IF([[yyparser.]])[error (]AT_LOCATION_IF([[@$, ]])[buf);
|
||||||
|
}]],
|
||||||
|
[d], [[
|
||||||
|
yyerror (]AT_LOCATION_IF([[@$, ]])[format ("calc: error: %d != %d", $1, $3));]])[
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
| exp '+' exp { $$ = $1 + $3; }
|
| exp '+' exp { $$ = $1 + $3; }
|
||||||
| exp '-' exp { $$ = $1 - $3; }
|
| exp '-' exp { $$ = $1 - $3; }
|
||||||
| exp '*' exp { $$ = $1 * $3; }
|
| exp '*' exp { $$ = $1 * $3; }
|
||||||
| exp '/' exp { $$ = $1 / $3; }
|
| exp '/' exp { $$ = $1 / $3; }
|
||||||
| '-' exp %prec NEG { $$ = -$2; }
|
| '-' exp %prec NEG { $$ = -$2; }
|
||||||
| exp '^' exp { $$ = power ($1, $3); }
|
| exp '^' exp { $$ = power ($1, $3); }
|
||||||
| '(' exp ')' { $$ = $2; }
|
| '(' exp ')' { $$ = $2; }
|
||||||
| '(' error ')' { $$ = 1111; ]AT_D_IF([], [yyerrok;])[ }
|
| '(' error ')' { $$ = 1111; ]AT_D_IF([], [yyerrok;])[ }
|
||||||
| '!' { $$ = 0; ]AT_D_IF([return YYERROR], [YYERROR])[; }
|
| '!' { $$ = 0; ]AT_D_IF([return YYERROR], [YYERROR])[; }
|
||||||
| '-' error { $$ = 0; ]AT_D_IF([return YYERROR], [YYERROR])[; }
|
| '-' error { $$ = 0; ]AT_D_IF([return YYERROR], [YYERROR])[; }
|
||||||
;
|
;
|
||||||
%%
|
%%
|
||||||
|
|
||||||
@@ -517,6 +644,93 @@ AT_DATA_SOURCE([[calc-main.]AT_LANG_EXT],
|
|||||||
])# _AT_DATA_CALC_Y
|
])# _AT_DATA_CALC_Y
|
||||||
|
|
||||||
|
|
||||||
|
m4_copy([_AT_DATA_CALC_Y(c)], [_AT_DATA_CALC_Y(c++)])
|
||||||
|
m4_copy([_AT_DATA_CALC_Y(c)], [_AT_DATA_CALC_Y(d)])
|
||||||
|
|
||||||
|
m4_define([_AT_DATA_CALC_Y(java)],
|
||||||
|
[AT_DATA_GRAMMAR([Calc.y],
|
||||||
|
[[/* Infix notation calculator--calc */
|
||||||
|
%define api.prefix {Calc}
|
||||||
|
%define api.parser.class {Calc}
|
||||||
|
%define public
|
||||||
|
|
||||||
|
]$4[
|
||||||
|
|
||||||
|
%code imports {]AT_LOCATION_IF([[
|
||||||
|
import java.io.BufferedReader;]])[
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.StreamTokenizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
%code {
|
||||||
|
]AT_CALC_MAIN[
|
||||||
|
|
||||||
|
]AT_TOKEN_TRANSLATE_IF([[
|
||||||
|
static String i18n(String s)
|
||||||
|
{
|
||||||
|
if (s.equals ("end of input"))
|
||||||
|
return "end of file";
|
||||||
|
else if (s.equals ("number"))
|
||||||
|
return "nombre";
|
||||||
|
else
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
]])[
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Bison Declarations */
|
||||||
|
%token CALC_EOF 0 ]AT_TOKEN_TRANSLATE_IF([_("end of input")], ["end of input"])[
|
||||||
|
%token <Integer> NUM "number"
|
||||||
|
%type <Integer> exp
|
||||||
|
|
||||||
|
%nonassoc '=' /* comparison */
|
||||||
|
%left '-' '+'
|
||||||
|
%left '*' '/'
|
||||||
|
%precedence NEG /* negation--unary minus */
|
||||||
|
%right '^' /* exponentiation */
|
||||||
|
|
||||||
|
/* Grammar follows */
|
||||||
|
%%
|
||||||
|
input:
|
||||||
|
line
|
||||||
|
| input line
|
||||||
|
;
|
||||||
|
|
||||||
|
line:
|
||||||
|
'\n'
|
||||||
|
| exp '\n'
|
||||||
|
;
|
||||||
|
|
||||||
|
exp:
|
||||||
|
NUM
|
||||||
|
| exp '=' exp
|
||||||
|
{
|
||||||
|
if ($1.intValue () != $3.intValue ())
|
||||||
|
yyerror (]AT_LOCATION_IF([[@$, ]])["calc: error: " + $1 + " != " + $3);
|
||||||
|
}
|
||||||
|
| exp '+' exp { $$ = $1 + $3; }
|
||||||
|
| exp '-' exp { $$ = $1 - $3; }
|
||||||
|
| exp '*' exp { $$ = $1 * $3; }
|
||||||
|
| exp '/' exp { $$ = $1 / $3; }
|
||||||
|
| '-' exp %prec NEG { $$ = -$2; }
|
||||||
|
| exp '^' exp { $$ = (int) Math.pow ($1, $3); }
|
||||||
|
| '(' exp ')' { $$ = $2; }
|
||||||
|
| '(' error ')' { $$ = 1111; }
|
||||||
|
| '!' { $$ = 0; return YYERROR; }
|
||||||
|
| '-' error { $$ = 0; return YYERROR; }
|
||||||
|
;
|
||||||
|
]AT_CALC_YYLEX[
|
||||||
|
]AT_LOCATION_IF([[
|
||||||
|
%%
|
||||||
|
]AT_JAVA_POSITION_DEFINE])[
|
||||||
|
]])
|
||||||
|
])# _AT_DATA_JAVA_CALC_Y
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# AT_DATA_CALC_Y([BISON-OPTIONS])
|
# AT_DATA_CALC_Y([BISON-OPTIONS])
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
# Produce 'calc.y' and, if %defines was specified, 'calc-lex.c' or
|
# Produce 'calc.y' and, if %defines was specified, 'calc-lex.c' or
|
||||||
@@ -527,8 +741,8 @@ m4_define([AT_DATA_CALC_Y],
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# _AT_CHECK_CALC(BISON-OPTIONS, INPUT, [NUM-STDERR-LINES])
|
# _AT_CHECK_CALC(BISON-OPTIONS, INPUT, [STDOUT], [NUM-STDERR-LINES])
|
||||||
# --------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Run 'calc' on INPUT and expect no STDOUT nor STDERR.
|
# Run 'calc' on INPUT and expect no STDOUT nor STDERR.
|
||||||
#
|
#
|
||||||
# If BISON-OPTIONS contains '%debug' but not '%glr-parser', then
|
# If BISON-OPTIONS contains '%debug' but not '%glr-parser', then
|
||||||
@@ -536,43 +750,54 @@ m4_define([AT_DATA_CALC_Y],
|
|||||||
# Currently this is ignored, though, since the output format is fluctuating.
|
# Currently this is ignored, though, since the output format is fluctuating.
|
||||||
#
|
#
|
||||||
# We don't count GLR's traces yet, since its traces are somewhat
|
# We don't count GLR's traces yet, since its traces are somewhat
|
||||||
# different from LALR's.
|
# different from LALR's. Likewise for D.
|
||||||
|
#
|
||||||
|
# The push traces are the same, except for "Return for a new token", don't
|
||||||
|
# count them.
|
||||||
m4_define([_AT_CHECK_CALC],
|
m4_define([_AT_CHECK_CALC],
|
||||||
[AT_DATA([[input]],
|
[AT_DATA([[input]],
|
||||||
[[$2
|
[$2
|
||||||
]])
|
])
|
||||||
AT_PARSER_CHECK([calc input], 0, [], [stderr])
|
AT_JAVA_IF(
|
||||||
|
[AT_JAVA_PARSER_CHECK([Calc < input], 0, [AT_PARAM_IF([m4_n([$3])])], [stderr])],
|
||||||
|
[AT_PARSER_CHECK([calc input], 0, [AT_PARAM_IF([m4_n([$3])])], [stderr])])
|
||||||
|
AT_LANG_MATCH([c\|c++\|java],
|
||||||
|
[AT_GLR_IF([],
|
||||||
|
[AT_CHECK([grep -v 'Return for a new token:' stderr | wc -l],
|
||||||
|
[0],
|
||||||
|
[m4_n([AT_DEBUG_IF([$4], [0])])])])])
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
# _AT_CHECK_CALC_ERROR(BISON-OPTIONS, EXIT-STATUS, INPUT,
|
# _AT_CHECK_CALC_ERROR($1 = BISON-OPTIONS, $2 = EXIT-STATUS, $3 = INPUT,
|
||||||
# [NUM-STDERR-LINES],
|
# $4 = [STDOUT],
|
||||||
# [VERBOSE-AND-LOCATED-ERROR-MESSAGE])
|
# $5 = [NUM-STDERR-LINES],
|
||||||
# ---------------------------------------------------------
|
# $6 = [CUSTOM-ERROR-MESSAGE])
|
||||||
|
# ----------------------------------------------------------------------
|
||||||
# Run 'calc' on INPUT, and expect a 'syntax error' message.
|
# Run 'calc' on INPUT, and expect a 'syntax error' message.
|
||||||
#
|
#
|
||||||
# If INPUT starts with a slash, it is used as absolute input file name,
|
# If INPUT starts with a slash, it is used as absolute input file name,
|
||||||
# otherwise as contents.
|
# otherwise as contents.
|
||||||
#
|
#
|
||||||
# NUM-STDERR-LINES is the number of expected lines on stderr.
|
# NUM-STDERR-LINES is the number of expected lines on stderr.
|
||||||
# Currently this is ignored, though, since the output format is fluctuating.
|
|
||||||
#
|
|
||||||
# If BISON-OPTIONS contains '%location', then make sure the ERROR-LOCATION
|
|
||||||
# is correctly output on stderr.
|
|
||||||
#
|
|
||||||
# If BISON-OPTIONS contains '%define parse.error verbose', then make sure the
|
|
||||||
# IF-YYERROR-VERBOSE message is properly output after 'syntax error, '
|
|
||||||
# on STDERR.
|
|
||||||
#
|
|
||||||
# If BISON-OPTIONS contains '%debug' but not '%glr', then NUM-STDERR-LINES
|
# If BISON-OPTIONS contains '%debug' but not '%glr', then NUM-STDERR-LINES
|
||||||
# is the number of expected lines on stderr.
|
# is the number of expected lines on stderr.
|
||||||
|
#
|
||||||
|
# CUSTOM-ERROR-MESSAGE is the expected error message when parse.error
|
||||||
|
# is 'custom' and locations are enabled. Other expected formats are
|
||||||
|
# computed from it.
|
||||||
m4_define([_AT_CHECK_CALC_ERROR],
|
m4_define([_AT_CHECK_CALC_ERROR],
|
||||||
[m4_bmatch([$3], [^/],
|
[m4_bmatch([$3], [^/],
|
||||||
[AT_PARSER_CHECK([calc $3], $2, [], [stderr])],
|
[AT_JAVA_IF(
|
||||||
[AT_DATA([[input]],
|
[AT_JAVA_PARSER_CHECK([Calc < $3], $2, [AT_PARAM_IF([m4_n([$4])])], [stderr])],
|
||||||
|
[AT_PARSER_CHECK([calc $3], $2, [AT_PARAM_IF([m4_n([$4])])], [stderr])])],
|
||||||
|
[AT_DATA([[input]],
|
||||||
[[$3
|
[[$3
|
||||||
]])
|
]])
|
||||||
AT_PARSER_CHECK([calc input], $2, [], [stderr])])
|
AT_JAVA_IF(
|
||||||
|
[AT_JAVA_PARSER_CHECK([Calc < input], $2, [AT_PARAM_IF([m4_n([$4])])], [stderr])],
|
||||||
|
[AT_PARSER_CHECK([calc input], $2, [AT_PARAM_IF([m4_n([$4])])], [stderr])])
|
||||||
|
])
|
||||||
|
|
||||||
# Normalize the observed and expected error messages, depending upon the
|
# Normalize the observed and expected error messages, depending upon the
|
||||||
# options.
|
# options.
|
||||||
@@ -596,7 +821,7 @@ mv at-stderr stderr
|
|||||||
|
|
||||||
# 2. Create the reference error message.
|
# 2. Create the reference error message.
|
||||||
AT_DATA([[expout]],
|
AT_DATA([[expout]],
|
||||||
[$5
|
[$6
|
||||||
])
|
])
|
||||||
|
|
||||||
# 3. If locations are not used, remove them.
|
# 3. If locations are not used, remove them.
|
||||||
@@ -604,12 +829,27 @@ AT_YYERROR_SEES_LOC_IF([],
|
|||||||
[[sed 's/^[-0-9.]*: //' expout >at-expout
|
[[sed 's/^[-0-9.]*: //' expout >at-expout
|
||||||
mv at-expout expout]])
|
mv at-expout expout]])
|
||||||
|
|
||||||
# 4. If error-verbose is not used, strip the', unexpected....' part.
|
# 4. If parse.error is not custom, turn the expected message to
|
||||||
m4_bmatch([$1], [%define parse.error verbose], [],
|
# the traditional one.
|
||||||
|
AT_ERROR_CUSTOM_IF([], [
|
||||||
|
AT_PERL_REQUIRE([[-pi -e 'use strict;
|
||||||
|
s{syntax error on token \[(.*?)\] \(expected: (.*)\)}
|
||||||
|
{
|
||||||
|
my $unexp = $][1;
|
||||||
|
my @exps = $][2 =~ /\[(.*?)\]/g;
|
||||||
|
($][#exps && $][#exps < 4)
|
||||||
|
? "syntax error, unexpected $unexp, expecting @{[join(\" or \", @exps)]}"
|
||||||
|
: "syntax error, unexpected $unexp";
|
||||||
|
}eg
|
||||||
|
' expout]])
|
||||||
|
])
|
||||||
|
|
||||||
|
# 5. If parse.error is simple, strip the', unexpected....' part.
|
||||||
|
AT_ERROR_SIMPLE_IF(
|
||||||
[[sed 's/syntax error, .*$/syntax error/' expout >at-expout
|
[[sed 's/syntax error, .*$/syntax error/' expout >at-expout
|
||||||
mv at-expout expout]])
|
mv at-expout expout]])
|
||||||
|
|
||||||
# 5. Check
|
# 6. Actually check.
|
||||||
AT_CHECK([cat stderr], 0, [expout])
|
AT_CHECK([cat stderr], 0, [expout])
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -617,7 +857,7 @@ AT_CHECK([cat stderr], 0, [expout])
|
|||||||
# AT_CHECK_SPACES([FILES])
|
# AT_CHECK_SPACES([FILES])
|
||||||
# ------------------------
|
# ------------------------
|
||||||
# Make sure we did not introduce bad spaces. Checked here because all
|
# Make sure we did not introduce bad spaces. Checked here because all
|
||||||
# the skeletons are (or should be) exercized here.
|
# the skeletons are (or should be) exercised here.
|
||||||
m4_define([AT_CHECK_SPACES],
|
m4_define([AT_CHECK_SPACES],
|
||||||
[AT_PERL_CHECK([-ne '
|
[AT_PERL_CHECK([-ne '
|
||||||
chomp;
|
chomp;
|
||||||
@@ -633,6 +873,15 @@ m4_define([AT_CHECK_SPACES],
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
# AT_CHECK_JAVA_GREP(FILE, [LINE], [COUNT=1])
|
||||||
|
# -------------------------------------------
|
||||||
|
# Check that FILE contains exactly COUNT lines matching ^LINE$
|
||||||
|
# with grep. Unquoted so that COUNT can be a shell expression.
|
||||||
|
m4_define([AT_CHECK_JAVA_GREP],
|
||||||
|
[AT_CHECK_UNQUOTED([grep -c '^$2$' $1], [ignore], [m4_default([$3], [1])
|
||||||
|
])])
|
||||||
|
|
||||||
|
|
||||||
# AT_CHECK_CALC([BISON-OPTIONS], [COMPILER-OPTIONS])
|
# AT_CHECK_CALC([BISON-OPTIONS], [COMPILER-OPTIONS])
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
# Start a testing chunk which compiles 'calc' grammar with
|
# Start a testing chunk which compiles 'calc' grammar with
|
||||||
@@ -646,12 +895,19 @@ AT_SETUP([Calculator $1 $2])
|
|||||||
AT_BISON_OPTION_PUSHDEFS([$1])
|
AT_BISON_OPTION_PUSHDEFS([$1])
|
||||||
|
|
||||||
AT_DATA_CALC_Y([$1])
|
AT_DATA_CALC_Y([$1])
|
||||||
AT_FULL_COMPILE([calc], AT_DEFINES_IF([[lex], [main]], [[], []]), [$2], [-Wno-deprecated])
|
AT_FULL_COMPILE(AT_JAVA_IF([[Calc]], [[calc]]), AT_DEFINES_IF([[lex], [main]], [[], []]), [$2], [-Wno-deprecated])
|
||||||
AT_CHECK_SPACES([calc.AT_LANG_EXT AT_DEFINES_IF([calc.AT_LANG_HDR])])
|
AT_PUSH_IF([AT_JAVA_IF(
|
||||||
|
[# Verify that this is a push parser.
|
||||||
|
AT_CHECK_JAVA_GREP([[Calc.java]],
|
||||||
|
[[.*public void push_parse_initialize ().*]])])])
|
||||||
|
|
||||||
|
AT_CHECK_SPACES([AT_JAVA_IF([Calc], [calc]).AT_LANG_EXT AT_DEFINES_IF([AT_JAVA_IF([Calc], [calc]).AT_LANG_HDR])])
|
||||||
|
|
||||||
# Test the precedences.
|
# Test the precedences.
|
||||||
|
# The Java traces do not show the clean up sequence at the end,
|
||||||
|
# since it does not support %destructor.
|
||||||
_AT_CHECK_CALC([$1],
|
_AT_CHECK_CALC([$1],
|
||||||
[1 + 2 * 3 = 7
|
[[1 + 2 * 3 = 7
|
||||||
1 + 2 * -3 = -5
|
1 + 2 * -3 = -5
|
||||||
|
|
||||||
-1^2 = -1
|
-1^2 = -1
|
||||||
@@ -663,26 +919,40 @@ _AT_CHECK_CALC([$1],
|
|||||||
1 - (2 - 3) = 2
|
1 - (2 - 3) = 2
|
||||||
|
|
||||||
2^2^3 = 256
|
2^2^3 = 256
|
||||||
(2^2)^3 = 64],
|
(2^2)^3 = 64]],
|
||||||
[842])
|
[[final: 64 12 0]],
|
||||||
|
[AT_JAVA_IF([1014], [1017])])
|
||||||
|
|
||||||
# Some syntax errors.
|
# Some syntax errors.
|
||||||
_AT_CHECK_CALC_ERROR([$1], [1], [1 2], [15],
|
_AT_CHECK_CALC_ERROR([$1], [1], [1 2],
|
||||||
[1.3: syntax error, unexpected number])
|
[[final: 0 0 1]],
|
||||||
_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [20],
|
[15],
|
||||||
[1.3: syntax error, unexpected '/', expecting number or '-' or '(' or '!'])
|
[AT_JAVA_IF([1.3-1.4], [1.3])[: syntax error on token [number] (expected: ['='] ['-'] ['+'] ['*'] ['/'] ['^'] ['\n'])]])
|
||||||
_AT_CHECK_CALC_ERROR([$1], [1], [error], [5],
|
_AT_CHECK_CALC_ERROR([$1], [1], [1//2],
|
||||||
[1.1: syntax error, unexpected $undefined])
|
[[final: 0 0 1]],
|
||||||
_AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [30],
|
[20],
|
||||||
[1.7: syntax error, unexpected '='])
|
[AT_JAVA_IF([1.3-1.4], [1.3])[: syntax error on token ['/'] (expected: [number] ['-'] ['('] ['!'])]])
|
||||||
|
_AT_CHECK_CALC_ERROR([$1], [1], [error],
|
||||||
|
[[final: 0 0 1]],
|
||||||
|
[5],
|
||||||
|
[AT_JAVA_IF([1.1-1.2], [1.1])[: syntax error on token [invalid token] (expected: [number] ['-'] ['\n'] ['('] ['!'])]])
|
||||||
|
_AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3],
|
||||||
|
[[final: 0 0 1]],
|
||||||
|
[30],
|
||||||
|
[AT_LAC_IF(
|
||||||
|
[AT_JAVA_IF([1.7-1.8], [1.7])[: syntax error on token ['='] (expected: ['-'] ['+'] ['*'] ['/'] ['^'] ['\n'])]],
|
||||||
|
[AT_JAVA_IF([1.7-1.8], [1.7])[: syntax error on token ['='] (expected: ['-'] ['+'] ['*'] ['/'] ['^'])]])])
|
||||||
_AT_CHECK_CALC_ERROR([$1], [1],
|
_AT_CHECK_CALC_ERROR([$1], [1],
|
||||||
[
|
[
|
||||||
+1],
|
+1],
|
||||||
|
[[final: 0 0 1]],
|
||||||
[20],
|
[20],
|
||||||
[2.1: syntax error, unexpected '+'])
|
[AT_JAVA_IF([2.1-2.2], [2.1])[: syntax error on token ['+'] (expected: ]AT_TOKEN_TRANSLATE_IF([[[end of file]]], [[[end of input]]])[ [number] ['-'] ['\n'] ['('] ['!'])]])
|
||||||
# Exercise error messages with EOF: work on an empty file.
|
# Exercise error messages with EOF: work on an empty file.
|
||||||
_AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4],
|
_AT_CHECK_CALC_ERROR([$1], [1], [/dev/null],
|
||||||
[1.1: syntax error, unexpected end of input])
|
[[final: 0 0 1]],
|
||||||
|
[4],
|
||||||
|
[[1.1: syntax error on token ]AT_TOKEN_TRANSLATE_IF([[[end of file]]], [[[end of input]]])[ (expected: [number] ['-'] ['\n'] ['('] ['!'])]])
|
||||||
|
|
||||||
# Exercise the error token: without it, we die at the first error,
|
# Exercise the error token: without it, we die at the first error,
|
||||||
# hence be sure to
|
# hence be sure to
|
||||||
@@ -702,29 +972,37 @@ _AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4],
|
|||||||
#
|
#
|
||||||
_AT_CHECK_CALC_ERROR([$1], [0],
|
_AT_CHECK_CALC_ERROR([$1], [0],
|
||||||
[() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
|
[() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
|
||||||
|
[[final: 4444 0 5]],
|
||||||
[250],
|
[250],
|
||||||
[1.2: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
|
[AT_JAVA_IF([1.2-1.3], [1.2])[: syntax error on token [')'] (expected: [number] ['-'] ['('] ['!'])
|
||||||
1.18: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
|
]AT_JAVA_IF([1.18-1.19], [1.18])[: syntax error on token [')'] (expected: [number] ['-'] ['('] ['!'])
|
||||||
1.23: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
]AT_JAVA_IF([1.23-1.24], [1.23])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])
|
||||||
1.41: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
]AT_JAVA_IF([1.41-1.42], [1.41])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])
|
||||||
calc: error: 4444 != 1])
|
]AT_JAVA_IF([1.1-1.47], [1.1-46])[: calc: error: 4444 != 1]])
|
||||||
|
|
||||||
# The same, but this time exercising explicitly triggered syntax errors.
|
# The same, but this time exercising explicitly triggered syntax errors.
|
||||||
# POSIX says the lookahead causing the error should not be discarded.
|
# POSIX says the lookahead causing the error should not be discarded.
|
||||||
_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (1 2) = 1], [102],
|
_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (1 2) = 1],
|
||||||
[1.10: syntax error, unexpected number
|
[[final: 2222 0 2]],
|
||||||
calc: error: 2222 != 1])
|
[102],
|
||||||
_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (1 2) = 1], [113],
|
[AT_JAVA_IF([1.10-1.11], [1.10])[: syntax error on token [number] (expected: ['='] ['-'] ['+'] ['*'] ['/'] ['^'] [')'])
|
||||||
[1.4: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
]AT_JAVA_IF([1.1-1.16], [1.1-15])[: calc: error: 2222 != 1]])
|
||||||
1.12: syntax error, unexpected number
|
|
||||||
calc: error: 2222 != 1])
|
_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (1 2) = 1],
|
||||||
|
[[final: 2222 0 3]],
|
||||||
|
[113],
|
||||||
|
[AT_JAVA_IF([1.4-1.5], [1.4])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])
|
||||||
|
]AT_JAVA_IF([1.12-1.13], [1.12])[: syntax error on token [number] (expected: ['='] ['-'] ['+'] ['*'] ['/'] ['^'] [')'])
|
||||||
|
]AT_JAVA_IF([1.1-1.18], [1.1-17])[: calc: error: 2222 != 1]])
|
||||||
|
|
||||||
# Check that yyerrok works properly: second error is not reported,
|
# Check that yyerrok works properly: second error is not reported,
|
||||||
# third and fourth are. Parse status is succesful.
|
# third and fourth are. Parse status is successful.
|
||||||
_AT_CHECK_CALC_ERROR([$1], [0], [(* *) + (*) + (*)], [113],
|
_AT_CHECK_CALC_ERROR([$1], [0], [(* *) + (*) + (*)],
|
||||||
[1.2: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
[[final: 3333 0 3]],
|
||||||
1.10: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
[113],
|
||||||
1.16: syntax error, unexpected '*', expecting number or '-' or '(' or '!'])
|
[AT_JAVA_IF([1.2-1.3], [1.2])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])
|
||||||
|
]AT_JAVA_IF([1.10-1.11], [1.10])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])
|
||||||
|
]AT_JAVA_IF([1.16-1.17], [1.16])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])]])
|
||||||
|
|
||||||
AT_BISON_OPTION_POPDEFS
|
AT_BISON_OPTION_POPDEFS
|
||||||
|
|
||||||
@@ -734,11 +1012,11 @@ AT_CLEANUP
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------ #
|
# ----------------- #
|
||||||
# Simple LALR Calculator. #
|
# LALR Calculator. #
|
||||||
# ------------------------ #
|
# ----------------- #
|
||||||
|
|
||||||
AT_BANNER([[Simple LALR(1) Calculator.]])
|
AT_BANNER([[LALR(1) Calculator.]])
|
||||||
|
|
||||||
# AT_CHECK_CALC_LALR([BISON-OPTIONS])
|
# AT_CHECK_CALC_LALR([BISON-OPTIONS])
|
||||||
# -----------------------------------
|
# -----------------------------------
|
||||||
@@ -747,49 +1025,53 @@ AT_BANNER([[Simple LALR(1) Calculator.]])
|
|||||||
m4_define([AT_CHECK_CALC_LALR],
|
m4_define([AT_CHECK_CALC_LALR],
|
||||||
[AT_CHECK_CALC($@)])
|
[AT_CHECK_CALC($@)])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR()
|
AT_CHECK_CALC_LALR([%define parse.trace])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR([%defines])
|
AT_CHECK_CALC_LALR([%defines])
|
||||||
AT_CHECK_CALC_LALR([%locations])
|
AT_CHECK_CALC_LALR([%debug %locations])
|
||||||
AT_CHECK_CALC_LALR([%locations %define api.location.type {Span}])
|
AT_CHECK_CALC_LALR([%locations %define api.location.type {Span}])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR([%name-prefix "calc"])
|
AT_CHECK_CALC_LALR([%name-prefix "calc"])
|
||||||
AT_CHECK_CALC_LALR([%verbose])
|
AT_CHECK_CALC_LALR([%verbose])
|
||||||
AT_CHECK_CALC_LALR([%yacc])
|
AT_CHECK_CALC_LALR([%yacc])
|
||||||
|
AT_CHECK_CALC_LALR([%define parse.error detailed])
|
||||||
AT_CHECK_CALC_LALR([%define parse.error verbose])
|
AT_CHECK_CALC_LALR([%define parse.error verbose])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR([%define api.pure full %locations])
|
AT_CHECK_CALC_LALR([%define api.pure full %locations])
|
||||||
AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure full %locations])
|
AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure full %locations])
|
||||||
AT_CHECK_CALC_LALR([%define parse.error verbose %locations])
|
AT_CHECK_CALC_LALR([%define parse.error detailed %locations])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR([%define parse.error verbose %locations %defines %define api.prefix {calc} %verbose %yacc])
|
AT_CHECK_CALC_LALR([%define parse.error detailed %locations %defines %define api.prefix {calc} %verbose %yacc])
|
||||||
AT_CHECK_CALC_LALR([%define parse.error verbose %locations %defines %name-prefix "calc" %define api.token.prefix {TOK_} %verbose %yacc])
|
AT_CHECK_CALC_LALR([%define parse.error detailed %locations %defines %name-prefix "calc" %define api.token.prefix {TOK_} %verbose %yacc])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR([%debug])
|
AT_CHECK_CALC_LALR([%debug])
|
||||||
AT_CHECK_CALC_LALR([%define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
|
AT_CHECK_CALC_LALR([%define parse.error detailed %debug %locations %defines %name-prefix "calc" %verbose %yacc])
|
||||||
AT_CHECK_CALC_LALR([%define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc])
|
AT_CHECK_CALC_LALR([%define parse.error detailed %debug %locations %defines %define api.prefix {calc} %verbose %yacc])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR([%define api.pure full %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
|
AT_CHECK_CALC_LALR([%define api.pure full %define parse.error detailed %debug %locations %defines %name-prefix "calc" %verbose %yacc])
|
||||||
AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure full %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc])
|
AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure full %define parse.error detailed %debug %locations %defines %define api.prefix {calc} %verbose %yacc])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
AT_CHECK_CALC_LALR([%define api.pure %define parse.error detailed %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR([%no-lines %define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
AT_CHECK_CALC_LALR([%no-lines %define api.pure %define parse.error detailed %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
|
AT_CHECK_CALC_LALR([%no-lines %define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
|
|
||||||
# ----------------------- #
|
|
||||||
# Simple GLR Calculator. #
|
|
||||||
# ----------------------- #
|
|
||||||
|
|
||||||
AT_BANNER([[Simple GLR Calculator.]])
|
AT_CHECK_CALC_LALR([%define parse.error custom])
|
||||||
|
AT_CHECK_CALC_LALR([%define parse.error custom %locations %define api.prefix {calc}])
|
||||||
|
AT_CHECK_CALC_LALR([%define parse.error custom %locations %define api.prefix {calc} %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
|
AT_CHECK_CALC_LALR([%define parse.error custom %locations %define api.prefix {calc} %parse-param {semantic_value *result}{int *count}{int *nerrs} %define api.push-pull both %define api.pure full])
|
||||||
|
AT_CHECK_CALC_LALR([%define parse.error custom %locations %define api.prefix {calc} %parse-param {semantic_value *result}{int *count}{int *nerrs} %define api.push-pull both %define api.pure full %define parse.lac full])
|
||||||
|
|
||||||
|
# ---------------- #
|
||||||
|
# GLR Calculator. #
|
||||||
|
# ---------------- #
|
||||||
|
|
||||||
|
AT_BANNER([[GLR Calculator.]])
|
||||||
|
|
||||||
# AT_CHECK_CALC_GLR([BISON-OPTIONS])
|
|
||||||
# ----------------------------------
|
|
||||||
# Start a testing chunk which compiles 'calc' grammar with
|
|
||||||
# BISON-OPTIONS and %glr-parser, and performs several tests over the parser.
|
|
||||||
m4_define([AT_CHECK_CALC_GLR],
|
m4_define([AT_CHECK_CALC_GLR],
|
||||||
[AT_CHECK_CALC([%glr-parser] $@)])
|
[AT_CHECK_CALC([%glr-parser] $@)])
|
||||||
|
|
||||||
|
|
||||||
AT_CHECK_CALC_GLR()
|
AT_CHECK_CALC_GLR()
|
||||||
|
|
||||||
AT_CHECK_CALC_GLR([%defines])
|
AT_CHECK_CALC_GLR([%defines])
|
||||||
@@ -798,39 +1080,36 @@ AT_CHECK_CALC_GLR([%locations %define api.location.type {Span}])
|
|||||||
AT_CHECK_CALC_GLR([%name-prefix "calc"])
|
AT_CHECK_CALC_GLR([%name-prefix "calc"])
|
||||||
AT_CHECK_CALC_GLR([%define api.prefix {calc}])
|
AT_CHECK_CALC_GLR([%define api.prefix {calc}])
|
||||||
AT_CHECK_CALC_GLR([%verbose])
|
AT_CHECK_CALC_GLR([%verbose])
|
||||||
AT_CHECK_CALC_GLR([%yacc])
|
|
||||||
AT_CHECK_CALC_GLR([%define parse.error verbose])
|
AT_CHECK_CALC_GLR([%define parse.error verbose])
|
||||||
|
|
||||||
AT_CHECK_CALC_GLR([%define api.pure %locations])
|
AT_CHECK_CALC_GLR([%define api.pure %locations])
|
||||||
AT_CHECK_CALC_GLR([%define parse.error verbose %locations])
|
AT_CHECK_CALC_GLR([%define parse.error verbose %locations])
|
||||||
|
|
||||||
AT_CHECK_CALC_GLR([%define parse.error verbose %locations %defines %name-prefix "calc" %verbose %yacc])
|
AT_CHECK_CALC_GLR([%define parse.error custom %locations %defines %name-prefix "calc" %verbose])
|
||||||
|
AT_CHECK_CALC_GLR([%define parse.error detailed %locations %defines %name-prefix "calc" %verbose])
|
||||||
|
AT_CHECK_CALC_GLR([%define parse.error verbose %locations %defines %name-prefix "calc" %verbose])
|
||||||
|
|
||||||
AT_CHECK_CALC_GLR([%debug])
|
AT_CHECK_CALC_GLR([%debug])
|
||||||
AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
|
AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose])
|
||||||
AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %defines %define api.prefix {calc} %define api.token.prefix {TOK_} %verbose %yacc])
|
AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %defines %define api.prefix {calc} %define api.token.prefix {TOK_} %verbose])
|
||||||
|
|
||||||
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
|
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose])
|
||||||
|
|
||||||
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
|
|
||||||
AT_CHECK_CALC_GLR([%no-lines %define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
AT_CHECK_CALC_GLR([%no-lines %define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------- #
|
# ---------------------- #
|
||||||
# Simple LALR1 C++ Calculator. #
|
# LALR1 C++ Calculator. #
|
||||||
# ----------------------------- #
|
# ---------------------- #
|
||||||
|
|
||||||
AT_BANNER([[Simple LALR(1) C++ Calculator.]])
|
AT_BANNER([[LALR(1) C++ Calculator.]])
|
||||||
|
|
||||||
# First let's try using %skeleton
|
# First let's try using %skeleton
|
||||||
AT_CHECK_CALC([%skeleton "lalr1.cc" %defines])
|
AT_CHECK_CALC([%skeleton "lalr1.cc" %defines])
|
||||||
|
|
||||||
# AT_CHECK_CALC_LALR1_CC([BISON-OPTIONS])
|
|
||||||
# ---------------------------------------
|
|
||||||
# Start a testing chunk which compiles 'calc' grammar with
|
|
||||||
# the C++ skeleton, and performs several tests over the parser.
|
|
||||||
m4_define([AT_CHECK_CALC_LALR1_CC],
|
m4_define([AT_CHECK_CALC_LALR1_CC],
|
||||||
[AT_CHECK_CALC([%language "C++" $1], [$2])])
|
[AT_CHECK_CALC([%language "C++" $1], [$2])])
|
||||||
|
|
||||||
@@ -838,71 +1117,69 @@ AT_CHECK_CALC_LALR1_CC([])
|
|||||||
AT_CHECK_CALC_LALR1_CC([%locations])
|
AT_CHECK_CALC_LALR1_CC([%locations])
|
||||||
AT_CHECK_CALC_LALR1_CC([%locations], [$NO_EXCEPTIONS_CXXFLAGS])
|
AT_CHECK_CALC_LALR1_CC([%locations], [$NO_EXCEPTIONS_CXXFLAGS])
|
||||||
AT_CHECK_CALC_LALR1_CC([%locations %define api.location.type {Span}])
|
AT_CHECK_CALC_LALR1_CC([%locations %define api.location.type {Span}])
|
||||||
AT_CHECK_CALC_LALR1_CC([%defines %locations %define parse.error verbose %name-prefix "calc" %verbose %yacc])
|
AT_CHECK_CALC_LALR1_CC([%defines %locations %define parse.error verbose %name-prefix "calc" %verbose])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %define api.prefix {calc} %verbose %yacc])
|
AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %define api.prefix {calc} %verbose])
|
||||||
AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
|
AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %name-prefix "calc" %verbose])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %define api.prefix {calc} %verbose %yacc])
|
AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %define api.prefix {calc} %verbose])
|
||||||
AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %define api.prefix {calc} %define api.token.prefix {TOK_} %verbose %yacc])
|
AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %define api.prefix {calc} %define api.token.prefix {TOK_} %verbose])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR1_CC([%defines %locations %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
AT_CHECK_CALC_LALR1_CC([%defines %locations %define parse.error verbose %debug %name-prefix "calc" %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR1_CC([%define parse.error verbose %debug %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
AT_CHECK_CALC_LALR1_CC([%define parse.error verbose %debug %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
AT_CHECK_CALC_LALR1_CC([%defines %locations %define parse.error verbose %debug %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
AT_CHECK_CALC_LALR1_CC([%defines %locations %define parse.error verbose %debug %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR1_CC([%defines %locations %define api.location.file none])
|
AT_CHECK_CALC_LALR1_CC([%defines %locations %define api.location.file none])
|
||||||
AT_CHECK_CALC_LALR1_CC([%defines %locations %define api.location.file "my-location.hh"])
|
AT_CHECK_CALC_LALR1_CC([%defines %locations %define api.location.file "my-location.hh"])
|
||||||
|
|
||||||
AT_CHECK_CALC_LALR1_CC([%no-lines %defines %locations %define api.location.file "my-location.hh"])
|
AT_CHECK_CALC_LALR1_CC([%no-lines %defines %locations %define api.location.file "my-location.hh"])
|
||||||
|
|
||||||
|
AT_CHECK_CALC_LALR1_CC([%locations %define parse.lac full %define parse.error verbose])
|
||||||
|
AT_CHECK_CALC_LALR1_CC([%locations %define parse.lac full %define parse.error detailed])
|
||||||
|
|
||||||
# --------------------------- #
|
AT_CHECK_CALC_LALR1_CC([%define parse.error custom])
|
||||||
# Simple GLR C++ Calculator. #
|
AT_CHECK_CALC_LALR1_CC([%define parse.error custom %locations %define api.prefix {calc} %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
# --------------------------- #
|
AT_CHECK_CALC_LALR1_CC([%define parse.error custom %locations %define api.prefix {calc} %parse-param {semantic_value *result}{int *count}{int *nerrs} %define parse.lac full])
|
||||||
|
|
||||||
AT_BANNER([[Simple GLR C++ Calculator.]])
|
# -------------------- #
|
||||||
|
# GLR C++ Calculator. #
|
||||||
|
# -------------------- #
|
||||||
|
|
||||||
|
AT_BANNER([[GLR C++ Calculator.]])
|
||||||
|
|
||||||
# Again, we try also using %skeleton.
|
# Again, we try also using %skeleton.
|
||||||
AT_CHECK_CALC([%skeleton "glr.cc"])
|
AT_CHECK_CALC([%skeleton "glr.cc"])
|
||||||
|
|
||||||
# AT_CHECK_CALC_GLR_CC([BISON-OPTIONS])
|
|
||||||
# -------------------------------------
|
|
||||||
# Start a testing chunk which compiles 'calc' grammar with
|
|
||||||
# the GLR C++ skeleton, and performs several tests over the parser.
|
|
||||||
m4_define([AT_CHECK_CALC_GLR_CC],
|
m4_define([AT_CHECK_CALC_GLR_CC],
|
||||||
[AT_CHECK_CALC([%language "C++" %glr-parser] $@)])
|
[AT_CHECK_CALC([%language "C++" %glr-parser] $@)])
|
||||||
|
|
||||||
AT_CHECK_CALC_GLR_CC([])
|
AT_CHECK_CALC_GLR_CC([])
|
||||||
AT_CHECK_CALC_GLR_CC([%locations])
|
AT_CHECK_CALC_GLR_CC([%locations])
|
||||||
AT_CHECK_CALC_GLR_CC([%locations %define api.location.type {Span}])
|
AT_CHECK_CALC_GLR_CC([%locations %define api.location.type {Span}])
|
||||||
AT_CHECK_CALC_GLR_CC([%defines %define parse.error verbose %name-prefix "calc" %verbose %yacc])
|
AT_CHECK_CALC_GLR_CC([%defines %define parse.error verbose %name-prefix "calc" %verbose])
|
||||||
AT_CHECK_CALC_GLR_CC([%define parse.error verbose %define api.prefix {calc} %verbose %yacc])
|
AT_CHECK_CALC_GLR_CC([%define parse.error verbose %define api.prefix {calc} %verbose])
|
||||||
|
|
||||||
AT_CHECK_CALC_GLR_CC([%debug])
|
AT_CHECK_CALC_GLR_CC([%debug])
|
||||||
|
|
||||||
AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
|
AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %verbose])
|
||||||
AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %define api.token.prefix {TOK_} %verbose %yacc])
|
AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %define api.token.prefix {TOK_} %verbose])
|
||||||
|
|
||||||
AT_CHECK_CALC_GLR_CC([%locations %defines %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
AT_CHECK_CALC_GLR_CC([%locations %defines %define parse.error verbose %debug %name-prefix "calc" %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
AT_CHECK_CALC_GLR_CC([%locations %defines %define parse.error verbose %debug %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
AT_CHECK_CALC_GLR_CC([%locations %defines %define parse.error verbose %debug %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
|
|
||||||
AT_CHECK_CALC_GLR_CC([%no-lines %locations %defines %define parse.error verbose %debug %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
|
AT_CHECK_CALC_GLR_CC([%no-lines %locations %defines %define parse.error verbose %debug %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
|
|
||||||
|
|
||||||
# --------------------------- #
|
# -------------------- #
|
||||||
# Simple LALR1 D Calculator. #
|
# LALR1 D Calculator. #
|
||||||
# --------------------------- #
|
# -------------------- #
|
||||||
|
|
||||||
AT_BANNER([[Simple LALR(1) D Calculator.]])
|
AT_BANNER([[LALR(1) D Calculator.]])
|
||||||
|
|
||||||
# First let's try using %skeleton
|
# First let's try using %skeleton
|
||||||
AT_CHECK_CALC([%skeleton "lalr1.d"])
|
AT_CHECK_CALC([%skeleton "lalr1.d"])
|
||||||
|
|
||||||
# AT_CHECK_CALC_LALR1_D([BISON-OPTIONS])
|
|
||||||
# ---------------------------------------
|
|
||||||
# Start a testing chunk which compiles 'calc' grammar with
|
|
||||||
# the C++ skeleton, and performs several tests over the parser.
|
|
||||||
m4_define([AT_CHECK_CALC_LALR1_D],
|
m4_define([AT_CHECK_CALC_LALR1_D],
|
||||||
[AT_CHECK_CALC([%language "D" $1], [$2])])
|
[AT_CHECK_CALC([%language "D" $1], [$2])])
|
||||||
|
|
||||||
@@ -916,8 +1193,35 @@ AT_CHECK_CALC_LALR1_D([%debug])
|
|||||||
AT_CHECK_CALC_LALR1_D([%define parse.error verbose %debug %verbose])
|
AT_CHECK_CALC_LALR1_D([%define parse.error verbose %debug %verbose])
|
||||||
#AT_CHECK_CALC_LALR1_D([%define parse.error verbose %debug %define api.token.prefix {TOK_} %verbose])
|
#AT_CHECK_CALC_LALR1_D([%define parse.error verbose %debug %define api.token.prefix {TOK_} %verbose])
|
||||||
|
|
||||||
#AT_CHECK_CALC_LALR1_D([%locations %define parse.error verbose %debug %verbose %parse-param {semantic_value *result} %parse-param {int *count}])
|
#AT_CHECK_CALC_LALR1_D([%locations %define parse.error verbose %debug %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
#AT_CHECK_CALC_LALR1_D([%locations %define parse.error verbose %debug %define api.prefix {calc} %verbose %parse-param {semantic_value *result} %parse-param {int *count}])
|
#AT_CHECK_CALC_LALR1_D([%locations %define parse.error verbose %debug %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------- #
|
||||||
|
# LALR1 Java Calculator. #
|
||||||
|
# ----------------------- #
|
||||||
|
|
||||||
|
AT_BANNER([[LALR(1) Java Calculator.]])
|
||||||
|
|
||||||
|
m4_define([AT_CHECK_CALC_LALR1_JAVA],
|
||||||
|
[AT_CHECK_CALC([%language "Java" $1], [$2])])
|
||||||
|
|
||||||
|
AT_CHECK_CALC_LALR1_JAVA
|
||||||
|
AT_CHECK_CALC_LALR1_JAVA([%define parse.error custom])
|
||||||
|
AT_CHECK_CALC_LALR1_JAVA([%define parse.error detailed])
|
||||||
|
AT_CHECK_CALC_LALR1_JAVA([%define parse.error verbose])
|
||||||
|
AT_CHECK_CALC_LALR1_JAVA([%locations %define parse.error custom])
|
||||||
|
AT_CHECK_CALC_LALR1_JAVA([%locations %define parse.error detailed])
|
||||||
|
AT_CHECK_CALC_LALR1_JAVA([%locations %define parse.error verbose])
|
||||||
|
AT_CHECK_CALC_LALR1_JAVA([%define parse.trace %define parse.error verbose])
|
||||||
|
AT_CHECK_CALC_LALR1_JAVA([%define parse.trace %define parse.error verbose %locations %lex-param {InputStream is}])
|
||||||
|
|
||||||
|
AT_CHECK_CALC_LALR1_JAVA([%define api.push-pull both])
|
||||||
|
AT_CHECK_CALC_LALR1_JAVA([%define api.push-pull both %define parse.error detailed %locations])
|
||||||
|
AT_CHECK_CALC_LALR1_JAVA([%define parse.trace %define parse.error custom %locations %lex-param {InputStream is} %define api.push-pull both])
|
||||||
|
AT_CHECK_CALC_LALR1_JAVA([%define parse.trace %define parse.error verbose %locations %lex-param {InputStream is} %define api.push-pull both])
|
||||||
|
|
||||||
|
|
||||||
|
m4_popdef([AT_TOKEN_TRANSLATE_IF])
|
||||||
m4_popdef([AT_CALC_MAIN])
|
m4_popdef([AT_CALC_MAIN])
|
||||||
m4_popdef([AT_CALC_YYLEX])
|
m4_popdef([AT_CALC_YYLEX])
|
||||||
|
|||||||
+17
-16
@@ -309,7 +309,6 @@ AT_DATA_GRAMMAR([input.y],
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#define YYERROR_VERBOSE 1
|
|
||||||
]AT_YYERROR_DEFINE[
|
]AT_YYERROR_DEFINE[
|
||||||
/* The current argument. */
|
/* The current argument. */
|
||||||
static const char *input;
|
static const char *input;
|
||||||
@@ -324,6 +323,8 @@ yylex (void)
|
|||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
%define parse.error verbose
|
||||||
|
|
||||||
%nonassoc '<' '>'
|
%nonassoc '<' '>'
|
||||||
|
|
||||||
%%
|
%%
|
||||||
@@ -345,7 +346,7 @@ m4_pushdef([AT_NONASSOC_AND_EOF_CHECK],
|
|||||||
[AT_BISON_CHECK([$1[ -o input.c input.y]])
|
[AT_BISON_CHECK([$1[ -o input.c input.y]])
|
||||||
AT_COMPILE([input])
|
AT_COMPILE([input])
|
||||||
|
|
||||||
m4_pushdef([AT_EXPECTING], [m4_if($2, [correct], [[, expecting $end]])])
|
m4_pushdef([AT_EXPECTING], [m4_if($2, [correct], [[, expecting end of file]])])
|
||||||
|
|
||||||
AT_PARSER_CHECK([input '0<0'])
|
AT_PARSER_CHECK([input '0<0'])
|
||||||
AT_PARSER_CHECK([input '0<0<0'], [1], [],
|
AT_PARSER_CHECK([input '0<0<0'], [1], [],
|
||||||
@@ -508,50 +509,50 @@ m4_pushdef([AT_PREVIOUS_STATE_INPUT], [[a]])
|
|||||||
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr]],
|
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr]],
|
||||||
[AT_PREVIOUS_STATE_GRAMMAR],
|
[AT_PREVIOUS_STATE_GRAMMAR],
|
||||||
[AT_PREVIOUS_STATE_INPUT],
|
[AT_PREVIOUS_STATE_INPUT],
|
||||||
[[$end]], [[none]])
|
[[end of file]], [[none]])
|
||||||
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
|
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
|
||||||
%glr-parser]],
|
%glr-parser]],
|
||||||
[AT_PREVIOUS_STATE_GRAMMAR],
|
[AT_PREVIOUS_STATE_GRAMMAR],
|
||||||
[AT_PREVIOUS_STATE_INPUT],
|
[AT_PREVIOUS_STATE_INPUT],
|
||||||
[[$end]], [[none]])
|
[[end of file]], [[none]])
|
||||||
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
|
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
|
||||||
%language "c++"]],
|
%language "c++"]],
|
||||||
[AT_PREVIOUS_STATE_GRAMMAR],
|
[AT_PREVIOUS_STATE_GRAMMAR],
|
||||||
[AT_PREVIOUS_STATE_INPUT],
|
[AT_PREVIOUS_STATE_INPUT],
|
||||||
[[$end]], [[none]])
|
[[end of file]], [[none]])
|
||||||
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
|
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
|
||||||
%language "java"]],
|
%language "java"]],
|
||||||
[AT_PREVIOUS_STATE_GRAMMAR],
|
[AT_PREVIOUS_STATE_GRAMMAR],
|
||||||
[AT_PREVIOUS_STATE_INPUT],
|
[AT_PREVIOUS_STATE_INPUT],
|
||||||
[[end of input]], [[none]])
|
[[end of file]], [[none]])
|
||||||
|
|
||||||
# Even canonical LR doesn't foresee the error for 'a'!
|
# Even canonical LR doesn't foresee the error for 'a'!
|
||||||
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
|
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
|
||||||
%define lr.default-reduction consistent]],
|
%define lr.default-reduction consistent]],
|
||||||
[AT_PREVIOUS_STATE_GRAMMAR],
|
[AT_PREVIOUS_STATE_GRAMMAR],
|
||||||
[AT_PREVIOUS_STATE_INPUT],
|
[AT_PREVIOUS_STATE_INPUT],
|
||||||
[[$end]], [[ab]])
|
[[end of file]], [[ab]])
|
||||||
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
|
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
|
||||||
%define lr.default-reduction accepting]],
|
%define lr.default-reduction accepting]],
|
||||||
[AT_PREVIOUS_STATE_GRAMMAR],
|
[AT_PREVIOUS_STATE_GRAMMAR],
|
||||||
[AT_PREVIOUS_STATE_INPUT],
|
[AT_PREVIOUS_STATE_INPUT],
|
||||||
[[$end]], [[ab]])
|
[[end of file]], [[ab]])
|
||||||
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr]],
|
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr]],
|
||||||
[AT_PREVIOUS_STATE_GRAMMAR],
|
[AT_PREVIOUS_STATE_GRAMMAR],
|
||||||
[AT_PREVIOUS_STATE_INPUT],
|
[AT_PREVIOUS_STATE_INPUT],
|
||||||
[[$end]], [[ab]])
|
[[end of file]], [[ab]])
|
||||||
|
|
||||||
# Only LAC gets it right. In C.
|
# Only LAC gets it right. In C.
|
||||||
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr
|
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr
|
||||||
%define parse.lac full]],
|
%define parse.lac full]],
|
||||||
[AT_PREVIOUS_STATE_GRAMMAR],
|
[AT_PREVIOUS_STATE_GRAMMAR],
|
||||||
[AT_PREVIOUS_STATE_INPUT],
|
[AT_PREVIOUS_STATE_INPUT],
|
||||||
[[$end]], [[b]])
|
[[end of file]], [[b]])
|
||||||
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
|
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type ielr
|
||||||
%define parse.lac full]],
|
%define parse.lac full]],
|
||||||
[AT_PREVIOUS_STATE_GRAMMAR],
|
[AT_PREVIOUS_STATE_GRAMMAR],
|
||||||
[AT_PREVIOUS_STATE_INPUT],
|
[AT_PREVIOUS_STATE_INPUT],
|
||||||
[[$end]], [[b]])
|
[[end of file]], [[b]])
|
||||||
|
|
||||||
# Only LAC gets it right. In C++.
|
# Only LAC gets it right. In C++.
|
||||||
AT_CONSISTENT_ERRORS_CHECK([[%language "c++"
|
AT_CONSISTENT_ERRORS_CHECK([[%language "c++"
|
||||||
@@ -559,13 +560,13 @@ AT_CONSISTENT_ERRORS_CHECK([[%language "c++"
|
|||||||
%define parse.lac full]],
|
%define parse.lac full]],
|
||||||
[AT_PREVIOUS_STATE_GRAMMAR],
|
[AT_PREVIOUS_STATE_GRAMMAR],
|
||||||
[AT_PREVIOUS_STATE_INPUT],
|
[AT_PREVIOUS_STATE_INPUT],
|
||||||
[[$end]], [[b]])
|
[[end of file]], [[b]])
|
||||||
AT_CONSISTENT_ERRORS_CHECK([[%language "c++"
|
AT_CONSISTENT_ERRORS_CHECK([[%language "c++"
|
||||||
%define lr.type ielr
|
%define lr.type ielr
|
||||||
%define parse.lac full]],
|
%define parse.lac full]],
|
||||||
[AT_PREVIOUS_STATE_GRAMMAR],
|
[AT_PREVIOUS_STATE_GRAMMAR],
|
||||||
[AT_PREVIOUS_STATE_INPUT],
|
[AT_PREVIOUS_STATE_INPUT],
|
||||||
[[$end]], [[b]])
|
[[end of file]], [[b]])
|
||||||
|
|
||||||
m4_popdef([AT_PREVIOUS_STATE_GRAMMAR])
|
m4_popdef([AT_PREVIOUS_STATE_GRAMMAR])
|
||||||
m4_popdef([AT_PREVIOUS_STATE_INPUT])
|
m4_popdef([AT_PREVIOUS_STATE_INPUT])
|
||||||
@@ -637,11 +638,11 @@ AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reduction consistent]],
|
|||||||
AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reduction accepting]],
|
AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reduction accepting]],
|
||||||
[AT_USER_ACTION_GRAMMAR],
|
[AT_USER_ACTION_GRAMMAR],
|
||||||
[AT_USER_ACTION_INPUT],
|
[AT_USER_ACTION_INPUT],
|
||||||
[[$end]], [[a]])
|
[[end of file]], [[a]])
|
||||||
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr]],
|
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr]],
|
||||||
[AT_USER_ACTION_GRAMMAR],
|
[AT_USER_ACTION_GRAMMAR],
|
||||||
[AT_USER_ACTION_INPUT],
|
[AT_USER_ACTION_INPUT],
|
||||||
[[$end]], [[a]])
|
[[end of file]], [[a]])
|
||||||
|
|
||||||
AT_CONSISTENT_ERRORS_CHECK([[%define parse.lac full]],
|
AT_CONSISTENT_ERRORS_CHECK([[%define parse.lac full]],
|
||||||
[AT_USER_ACTION_GRAMMAR],
|
[AT_USER_ACTION_GRAMMAR],
|
||||||
@@ -651,7 +652,7 @@ AT_CONSISTENT_ERRORS_CHECK([[%define parse.lac full
|
|||||||
%define lr.default-reduction accepting]],
|
%define lr.default-reduction accepting]],
|
||||||
[AT_USER_ACTION_GRAMMAR],
|
[AT_USER_ACTION_GRAMMAR],
|
||||||
[AT_USER_ACTION_INPUT],
|
[AT_USER_ACTION_INPUT],
|
||||||
[[$end]], [[none]])
|
[[end of file]], [[none]])
|
||||||
|
|
||||||
m4_popdef([AT_USER_ACTION_GRAMMAR])
|
m4_popdef([AT_USER_ACTION_GRAMMAR])
|
||||||
m4_popdef([AT_USER_ACTION_INPUT])
|
m4_popdef([AT_USER_ACTION_INPUT])
|
||||||
|
|||||||
+20
-20
@@ -77,31 +77,31 @@ exp: %empty;
|
|||||||
[[input.y:9.12-14: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
|
[[input.y:9.12-14: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
|
||||||
9 | %token FOO <warning>FOO</warning> FOO
|
9 | %token FOO <warning>FOO</warning> FOO
|
||||||
| <warning>^~~</warning>
|
| <warning>^~~</warning>
|
||||||
input.y:9.8-10: previous declaration
|
input.y:9.8-10: <note>note:</note> previous declaration
|
||||||
9 | %token <note>FOO</note> FOO FOO
|
9 | %token <note>FOO</note> FOO FOO
|
||||||
| <note>^~~</note>
|
| <note>^~~</note>
|
||||||
input.y:9.16-18: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
|
input.y:9.16-18: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
|
||||||
9 | %token FOO FOO <warning>FOO</warning>
|
9 | %token FOO FOO <warning>FOO</warning>
|
||||||
| <warning>^~~</warning>
|
| <warning>^~~</warning>
|
||||||
input.y:9.8-10: previous declaration
|
input.y:9.8-10: <note>note:</note> previous declaration
|
||||||
9 | %token <note>FOO</note> FOO FOO
|
9 | %token <note>FOO</note> FOO FOO
|
||||||
| <note>^~~</note>
|
| <note>^~~</note>
|
||||||
input.y:10.8-10: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
|
input.y:10.8-10: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
|
||||||
10 | %token <warning>FOO</warning> FOO FOO
|
10 | %token <warning>FOO</warning> FOO FOO
|
||||||
| <warning>^~~</warning>
|
| <warning>^~~</warning>
|
||||||
input.y:9.8-10: previous declaration
|
input.y:9.8-10: <note>note:</note> previous declaration
|
||||||
9 | %token <note>FOO</note> FOO FOO
|
9 | %token <note>FOO</note> FOO FOO
|
||||||
| <note>^~~</note>
|
| <note>^~~</note>
|
||||||
input.y:10.13-15: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
|
input.y:10.13-15: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
|
||||||
10 | %token FOO <warning>FOO</warning> FOO
|
10 | %token FOO <warning>FOO</warning> FOO
|
||||||
| <warning>^~~</warning>
|
| <warning>^~~</warning>
|
||||||
input.y:9.8-10: previous declaration
|
input.y:9.8-10: <note>note:</note> previous declaration
|
||||||
9 | %token <note>FOO</note> FOO FOO
|
9 | %token <note>FOO</note> FOO FOO
|
||||||
| <note>^~~</note>
|
| <note>^~~</note>
|
||||||
input.y:10.18-20: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
|
input.y:10.18-20: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
|
||||||
10 | %token FOO FOO <warning>FOO</warning>
|
10 | %token FOO FOO <warning>FOO</warning>
|
||||||
| <warning>^~~</warning>
|
| <warning>^~~</warning>
|
||||||
input.y:9.8-10: previous declaration
|
input.y:9.8-10: <note>note:</note> previous declaration
|
||||||
9 | %token <note>FOO</note> FOO FOO
|
9 | %token <note>FOO</note> FOO FOO
|
||||||
| <note>^~~</note>
|
| <note>^~~</note>
|
||||||
]])
|
]])
|
||||||
@@ -158,7 +158,7 @@ input.y: <warning>warning:</warning> fix-its can be applied. Rerun with option
|
|||||||
## ------------------------------------- ##
|
## ------------------------------------- ##
|
||||||
|
|
||||||
# We trust the "#line", since that's what allows us to quote the
|
# We trust the "#line", since that's what allows us to quote the
|
||||||
# actual source from which the gramar file was generated. But #line
|
# actual source from which the grammar file was generated. But #line
|
||||||
# can also be wrong, and point to a line which is shorter that the bad
|
# can also be wrong, and point to a line which is shorter that the bad
|
||||||
# one. In which case we can easily forget to close the styling.
|
# one. In which case we can easily forget to close the styling.
|
||||||
#
|
#
|
||||||
@@ -178,16 +178,16 @@ exp:
|
|||||||
[[input.y:13.8-10: <warning>warning:</warning> symbol foo redeclared [<warning>-Wother</warning>]
|
[[input.y:13.8-10: <warning>warning:</warning> symbol foo redeclared [<warning>-Wother</warning>]
|
||||||
13 | %token <warning>foo</warning> 123
|
13 | %token <warning>foo</warning> 123
|
||||||
| <warning>^~~</warning>
|
| <warning>^~~</warning>
|
||||||
input.y:12.8-10: previous declaration
|
input.y:12.8-10: <note>note:</note> previous declaration
|
||||||
12 | %token <note>foo</note> 123123
|
12 | %token <note>foo</note> 123123
|
||||||
| <note>^~~</note>
|
| <note>^~~</note>
|
||||||
input.y:13.12-17: <error>error:</error> redefining user token number of foo
|
input.y:13.12-17: <error>error:</error> redefining code of token foo
|
||||||
13 | %token foo <error>123</error>
|
13 | %token foo <error>123</error>
|
||||||
| <error>^~~~~~</error>
|
| <error>^~~~~~</error>
|
||||||
input.y:14.8-10: <warning>warning:</warning> symbol foo redeclared [<warning>-Wother</warning>]
|
input.y:14.8-10: <warning>warning:</warning> symbol foo redeclared [<warning>-Wother</warning>]
|
||||||
14 | %%
|
14 | %%
|
||||||
| <warning>^~~</warning>
|
| <warning>^~~</warning>
|
||||||
input.y:12.8-10: previous declaration
|
input.y:12.8-10: <note>note:</note> previous declaration
|
||||||
12 | %token <note>foo</note> 123123
|
12 | %token <note>foo</note> 123123
|
||||||
| <note>^~~</note>
|
| <note>^~~</note>
|
||||||
]])
|
]])
|
||||||
@@ -332,7 +332,7 @@ AT_TEST([[Carriage return]],
|
|||||||
[[input.y:10.8-11.0: <error>error:</error> missing '"' at end of line
|
[[input.y:10.8-11.0: <error>error:</error> missing '"' at end of line
|
||||||
10 | %token <error>"</error>
|
10 | %token <error>"</error>
|
||||||
| <error>^</error>
|
| <error>^</error>
|
||||||
input.y:10.8-11.0: <error>error:</error> syntax error, unexpected string, expecting character literal or identifier or <tag>
|
input.y:10.8-11.0: <error>error:</error> expected <expected>character literal</expected> or <expected>identifier</expected> or <expected><tag></expected> before <unexpected>string</unexpected>
|
||||||
10 | %token <error>"</error>
|
10 | %token <error>"</error>
|
||||||
| <error>^</error>
|
| <error>^</error>
|
||||||
]])
|
]])
|
||||||
@@ -355,7 +355,7 @@ exp:^M
|
|||||||
[[input.y:11.9-11: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
|
[[input.y:11.9-11: <warning>warning:</warning> symbol FOO redeclared [<warning>-Wother</warning>]
|
||||||
11 | %token
<warning>FOO</warning>
|
11 | %token
<warning>FOO</warning>
|
||||||
| <warning>^~~</warning>
|
| <warning>^~~</warning>
|
||||||
input.y:10.9-11: previous declaration
|
input.y:10.9-11: <note>note:</note> previous declaration
|
||||||
10 | %token
<note>FOO</note>
|
10 | %token
<note>FOO</note>
|
||||||
| <note>^~~</note>
|
| <note>^~~</note>
|
||||||
input.y:13.5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
|
input.y:13.5: <warning>warning:</warning> empty rule without %empty [<warning>-Wempty-rule</warning>]
|
||||||
@@ -381,19 +381,19 @@ exp: ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
|||||||
[[input.y:9.36-61: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
[[input.y:9.36-61: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
||||||
9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||||
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
||||||
input.y:9.8-33: previous declaration
|
input.y:9.8-33: <note>note:</note> previous declaration
|
||||||
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||||
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
||||||
input.y:9.64-89: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
input.y:9.64-89: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
||||||
9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning> ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning> ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||||
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
||||||
input.y:9.8-33: previous declaration
|
input.y:9.8-33: <note>note:</note> previous declaration
|
||||||
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||||
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
||||||
input.y:9.92-117: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
input.y:9.92-117: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
||||||
9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning>
|
9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning>
|
||||||
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
||||||
input.y:9.8-33: previous declaration
|
input.y:9.8-33: <note>note:</note> previous declaration
|
||||||
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||||
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
||||||
input.y:10.56-69: <warning>warning:</warning> deprecated directive: '%error-verbose', use '%define parse.error verbose' [<warning>-Wdeprecated</warning>]
|
input.y:10.56-69: <warning>warning:</warning> deprecated directive: '%error-verbose', use '%define parse.error verbose' [<warning>-Wdeprecated</warning>]
|
||||||
@@ -414,19 +414,19 @@ exp: ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
|||||||
[[input.y:9.36-61: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
[[input.y:9.36-61: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
||||||
9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning> ABCDEF...
|
9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning> ABCDEF...
|
||||||
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
||||||
input.y:9.8-33: previous declaration
|
input.y:9.8-33: <note>note:</note> previous declaration
|
||||||
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEF...
|
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEF...
|
||||||
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
||||||
input.y:9.64-89: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
input.y:9.64-89: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
||||||
9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEF</warning>...
|
9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEF</warning>...
|
||||||
| <warning>^~~~~~</warning>
|
| <warning>^~~~~~</warning>
|
||||||
input.y:9.8-33: previous declaration
|
input.y:9.8-33: <note>note:</note> previous declaration
|
||||||
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEF...
|
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEF...
|
||||||
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
||||||
input.y:9.92-117: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
input.y:9.92-117: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
||||||
9 | ...TUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning>
|
9 | ...TUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning>
|
||||||
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
||||||
input.y:9.8-33: previous declaration
|
input.y:9.8-33: <note>note:</note> previous declaration
|
||||||
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEF...
|
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEF...
|
||||||
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
||||||
input.y:10.56-69: <warning>warning:</warning> deprecated directive: '%error-verbose', use '%define parse.error verbose' [<warning>-Wdeprecated</warning>]
|
input.y:10.56-69: <warning>warning:</warning> deprecated directive: '%error-verbose', use '%define parse.error verbose' [<warning>-Wdeprecated</warning>]
|
||||||
@@ -447,19 +447,19 @@ exp: ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
|||||||
[[input.y:9.36-61: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
[[input.y:9.36-61: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
||||||
9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMN</warning>...
|
9 | %token ABCDEFGHIJKLMNOPQRSTUVWXYZ <warning>ABCDEFGHIJKLMN</warning>...
|
||||||
| <warning>^~~~~~~~~~~~~~</warning>
|
| <warning>^~~~~~~~~~~~~~</warning>
|
||||||
input.y:9.8-33: previous declaration
|
input.y:9.8-33: <note>note:</note> previous declaration
|
||||||
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMN...
|
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMN...
|
||||||
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
||||||
input.y:9.64-89: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
input.y:9.64-89: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
||||||
9 | ...TUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning> ABCDEFGHI...
|
9 | ...TUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning> ABCDEFGHI...
|
||||||
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
||||||
input.y:9.8-33: previous declaration
|
input.y:9.8-33: <note>note:</note> previous declaration
|
||||||
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMN...
|
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMN...
|
||||||
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
||||||
input.y:9.92-117: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
input.y:9.92-117: <warning>warning:</warning> symbol ABCDEFGHIJKLMNOPQRSTUVWXYZ redeclared [<warning>-Wother</warning>]
|
||||||
9 | ...TUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning>
|
9 | ...TUVWXYZ <warning>ABCDEFGHIJKLMNOPQRSTUVWXYZ</warning>
|
||||||
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
| <warning>^~~~~~~~~~~~~~~~~~~~~~~~~~</warning>
|
||||||
input.y:9.8-33: previous declaration
|
input.y:9.8-33: <note>note:</note> previous declaration
|
||||||
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMN...
|
9 | %token <note>ABCDEFGHIJKLMNOPQRSTUVWXYZ</note> ABCDEFGHIJKLMN...
|
||||||
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
| <note>^~~~~~~~~~~~~~~~~~~~~~~~~~</note>
|
||||||
input.y:10.56-69: <warning>warning:</warning> deprecated directive: '%error-verbose', use '%define parse.error verbose' [<warning>-Wdeprecated</warning>]
|
input.y:10.56-69: <warning>warning:</warning> deprecated directive: '%error-verbose', use '%define parse.error verbose' [<warning>-Wdeprecated</warning>]
|
||||||
|
|||||||
+15
-9
@@ -1661,9 +1661,9 @@ AT_BISON_OPTION_POPDEFS
|
|||||||
|
|
||||||
AT_BISON_CHECK([[-o glr-regr18.c -rall glr-regr18.y]], 1, [],
|
AT_BISON_CHECK([[-o glr-regr18.c -rall glr-regr18.y]], 1, [],
|
||||||
[[glr-regr18.y:28.18-24: error: result type clash on merge function 'merge': <type2> != <type1>
|
[[glr-regr18.y:28.18-24: error: result type clash on merge function 'merge': <type2> != <type1>
|
||||||
glr-regr18.y:27.18-24: previous declaration
|
glr-regr18.y:27.18-24: note: previous declaration
|
||||||
glr-regr18.y:29.13-19: error: result type clash on merge function 'merge': <type3> != <type2>
|
glr-regr18.y:29.13-19: error: result type clash on merge function 'merge': <type3> != <type2>
|
||||||
glr-regr18.y:28.18-24: previous declaration
|
glr-regr18.y:28.18-24: note: previous declaration
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
@@ -1700,7 +1700,6 @@ d: /* nada. */;
|
|||||||
]AT_YYLEX_DEFINE(["abc"])[
|
]AT_YYLEX_DEFINE(["abc"])[
|
||||||
]AT_MAIN_DEFINE[
|
]AT_MAIN_DEFINE[
|
||||||
]])
|
]])
|
||||||
AT_BISON_OPTION_POPDEFS
|
|
||||||
|
|
||||||
AT_BISON_CHECK([[-o input.c input.y]], 0, [],
|
AT_BISON_CHECK([[-o input.c input.y]], 0, [],
|
||||||
[[input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
[[input.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
|
||||||
@@ -1710,23 +1709,27 @@ AT_COMPILE([input])
|
|||||||
AT_PARSER_CHECK([[input --debug]], 1, [],
|
AT_PARSER_CHECK([[input --debug]], 1, [],
|
||||||
[Starting parse
|
[Starting parse
|
||||||
Entering state 0
|
Entering state 0
|
||||||
Reading a token: Next token is token 'a' ()
|
Reading a token
|
||||||
|
Next token is token 'a' ()
|
||||||
Shifting token 'a' ()
|
Shifting token 'a' ()
|
||||||
Entering state 1
|
Entering state 1
|
||||||
Reading a token: Next token is token 'b' ()
|
Reading a token
|
||||||
|
Next token is token 'b' ()
|
||||||
Shifting token 'b' ()
|
Shifting token 'b' ()
|
||||||
Entering state 3
|
Entering state 3
|
||||||
Reducing stack 0 by rule 3 (line 27):
|
Reducing stack 0 by rule 3 (line 27):
|
||||||
$1 = token 'b' ()
|
$1 = token 'b' ()
|
||||||
-> $$ = nterm b ()
|
-> $$ = nterm b ()
|
||||||
Entering state 4
|
Entering state 4
|
||||||
Reading a token: Next token is token 'c' ()
|
Reading a token
|
||||||
|
Next token is token 'c' ()
|
||||||
Shifting token 'c' ()
|
Shifting token 'c' ()
|
||||||
Entering state 6
|
Entering state 6
|
||||||
Reducing stack 0 by rule 4 (line 28):
|
Reducing stack 0 by rule 4 (line 28):
|
||||||
-> $$ = nterm d ()
|
-> $$ = nterm d ()
|
||||||
Entering state 7
|
Entering state 7
|
||||||
Reading a token: Now at end of input.
|
Reading a token
|
||||||
|
Now at end of input.
|
||||||
Stack 0 Entering state 7
|
Stack 0 Entering state 7
|
||||||
Now at end of input.
|
Now at end of input.
|
||||||
Splitting off stack 1 from 0.
|
Splitting off stack 1 from 0.
|
||||||
@@ -1739,7 +1742,7 @@ Stack 1 Entering state 2
|
|||||||
Now at end of input.
|
Now at end of input.
|
||||||
Removing dead stacks.
|
Removing dead stacks.
|
||||||
Rename stack 1 -> 0.
|
Rename stack 1 -> 0.
|
||||||
On stack 0, shifting token $end ()
|
On stack 0, shifting token "end of file" ()
|
||||||
Stack 0 now in state #5
|
Stack 0 now in state #5
|
||||||
Ambiguity detected.
|
Ambiguity detected.
|
||||||
Option 1,
|
Option 1,
|
||||||
@@ -1757,7 +1760,7 @@ Option 2,
|
|||||||
d <empty>
|
d <empty>
|
||||||
|
|
||||||
syntax is ambiguous
|
syntax is ambiguous
|
||||||
Cleanup: popping token $end ()
|
Cleanup: popping token "end of file" ()
|
||||||
Cleanup: popping unresolved nterm start ()
|
Cleanup: popping unresolved nterm start ()
|
||||||
Cleanup: popping nterm d ()
|
Cleanup: popping nterm d ()
|
||||||
Cleanup: popping token 'c' ()
|
Cleanup: popping token 'c' ()
|
||||||
@@ -1765,6 +1768,7 @@ Cleanup: popping nterm b ()
|
|||||||
Cleanup: popping token 'a' ()
|
Cleanup: popping token 'a' ()
|
||||||
])
|
])
|
||||||
|
|
||||||
|
AT_BISON_OPTION_POPDEFS
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|
||||||
|
|
||||||
@@ -1777,6 +1781,7 @@ AT_CLEANUP
|
|||||||
|
|
||||||
AT_SETUP([Predicates])
|
AT_SETUP([Predicates])
|
||||||
|
|
||||||
|
AT_BISON_OPTION_PUSHDEFS
|
||||||
AT_DATA_GRAMMAR([input.y],
|
AT_DATA_GRAMMAR([input.y],
|
||||||
[[%define parse.assert
|
[[%define parse.assert
|
||||||
%glr-parser
|
%glr-parser
|
||||||
@@ -1829,4 +1834,5 @@ AT_PARSER_CHECK([[input Owio]], [0], [old])
|
|||||||
AT_PARSER_CHECK([[input Nwio]], [1], [], [[syntax error, unexpected 'o', expecting 'n'
|
AT_PARSER_CHECK([[input Nwio]], [1], [], [[syntax error, unexpected 'o', expecting 'n'
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
AT_BISON_OPTION_POPDEFS
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|||||||
+8
-4
@@ -115,7 +115,7 @@ AT_CLEANUP
|
|||||||
|
|
||||||
# AT_TEST([DIRECTIVES], [COMPILER-FLAGS])
|
# AT_TEST([DIRECTIVES], [COMPILER-FLAGS])
|
||||||
# ---------------------------------------
|
# ---------------------------------------
|
||||||
# Check that headers are self-contained and protected againt multiple
|
# Check that headers are self-contained and protected against multiple
|
||||||
# inclusions.
|
# inclusions.
|
||||||
|
|
||||||
m4_pushdef([AT_TEST],
|
m4_pushdef([AT_TEST],
|
||||||
@@ -125,7 +125,9 @@ AT_BISON_OPTION_PUSHDEFS([$1])
|
|||||||
AT_DATA_GRAMMAR([input.y],
|
AT_DATA_GRAMMAR([input.y],
|
||||||
[[$1
|
[[$1
|
||||||
%define parse.error verbose
|
%define parse.error verbose
|
||||||
]AT_VARIANT_IF([%token <int> 'x'], [%union {int integer;}])[
|
]AT_VARIANT_IF([%token <int> X],
|
||||||
|
[%union {int integer;}
|
||||||
|
%token <integer> X])[
|
||||||
%code {
|
%code {
|
||||||
#include <stdio.h> /* printf. */
|
#include <stdio.h> /* printf. */
|
||||||
]AT_PUSH_IF([[
|
]AT_PUSH_IF([[
|
||||||
@@ -138,12 +140,12 @@ AT_DATA_GRAMMAR([input.y],
|
|||||||
}
|
}
|
||||||
%%
|
%%
|
||||||
exp:
|
exp:
|
||||||
'x' { printf ("x\n"); }
|
X { printf ("x\n"); }
|
||||||
;
|
;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
]AT_YYERROR_DEFINE[
|
]AT_YYERROR_DEFINE[
|
||||||
]AT_YYLEX_DEFINE(["x"])[
|
]AT_YYLEX_DEFINE([{AT_CXX_IF([yy::parser::token::])X, 0}])[
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_BISON_CHECK([-d -o input.AT_LANG_EXT input.y])
|
AT_BISON_CHECK([-d -o input.AT_LANG_EXT input.y])
|
||||||
@@ -319,7 +321,9 @@ AT_PERL_CHECK([[-n -0777 -e '
|
|||||||
s{//.*}{}g;
|
s{//.*}{}g;
|
||||||
s{\b((defined|if)\ YYDEBUG
|
s{\b((defined|if)\ YYDEBUG
|
||||||
|YYChar
|
|YYChar
|
||||||
|
|YYNTOKENS # This is actual scoped in a C++ class.
|
||||||
|YYPUSH_MORE(?:_DEFINED)?
|
|YYPUSH_MORE(?:_DEFINED)?
|
||||||
|
|S_(YY(ACCEPT|EMPTY|EOF|ERROR|UNDEF)) # These guys are scoped.
|
||||||
|YYUSE
|
|YYUSE
|
||||||
|YY_ATTRIBUTE(?:_PURE|_UNUSED)
|
|YY_ATTRIBUTE(?:_PURE|_UNUSED)
|
||||||
|YY(?:_REINTERPRET)?_CAST
|
|YY(?:_REINTERPRET)?_CAST
|
||||||
|
|||||||
+131
-87
@@ -102,7 +102,7 @@ input.y:6.1-17: error: invalid directive: '%a-does-not-exist'
|
|||||||
input.y:7.1: error: invalid character: '%'
|
input.y:7.1: error: invalid character: '%'
|
||||||
input.y:7.2: error: invalid character: '-'
|
input.y:7.2: error: invalid character: '-'
|
||||||
input.y:8.1-9.0: error: missing '%}' at end of file
|
input.y:8.1-9.0: error: missing '%}' at end of file
|
||||||
input.y:8.1-9.0: error: syntax error, unexpected %{...%}
|
input.y:8.1-9.0: error: unexpected %{...%}
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
@@ -124,7 +124,7 @@ AT_DATA([input.y],
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
AT_BISON_CHECK([input.y], [1], [],
|
AT_BISON_CHECK([input.y], [1], [],
|
||||||
[[input.y:3.1-15: error: syntax error, unexpected %initial-action, expecting {...}
|
[[input.y:3.1-15: error: expected {...} before %initial-action
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
@@ -269,10 +269,10 @@ AT_BISON_CHECK([-fcaret input.y], [1], [],
|
|||||||
[[input.y:1.13-24: error: nonterminals cannot be given a string alias
|
[[input.y:1.13-24: error: nonterminals cannot be given a string alias
|
||||||
1 | %nterm expr "expression";
|
1 | %nterm expr "expression";
|
||||||
| ^~~~~~~~~~~~
|
| ^~~~~~~~~~~~
|
||||||
input.y:2.13-15: error: nonterminals cannot be given an explicit number
|
input.y:2.13-15: error: nonterminals cannot be given a token code
|
||||||
2 | %nterm term 123;
|
2 | %nterm term 123;
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:3.13-15: error: nonterminals cannot be given an explicit number
|
input.y:3.13-15: error: nonterminals cannot be given a token code
|
||||||
3 | %nterm fact 124 "factor";
|
3 | %nterm fact 124 "factor";
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:3.17-24: error: nonterminals cannot be given a string alias
|
input.y:3.17-24: error: nonterminals cannot be given a string alias
|
||||||
@@ -281,16 +281,16 @@ input.y:3.17-24: error: nonterminals cannot be given a string alias
|
|||||||
input.y:4.8-10: error: character literals cannot be nonterminals
|
input.y:4.8-10: error: character literals cannot be nonterminals
|
||||||
4 | %nterm '+' '*';
|
4 | %nterm '+' '*';
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:5.8-15: error: syntax error, unexpected string, expecting character literal or identifier or <tag>
|
input.y:5.8-15: error: expected character literal or identifier or <tag> before string
|
||||||
5 | %nterm "number";
|
5 | %nterm "number";
|
||||||
| ^~~~~~~~
|
| ^~~~~~~~
|
||||||
input.y:6.8-13: error: syntax error, unexpected string, expecting character literal or identifier or <tag>
|
input.y:6.8-13: error: expected character literal or identifier or <tag> before string
|
||||||
6 | %token "tok1" 1;
|
6 | %token "tok1" 1;
|
||||||
| ^~~~~~
|
| ^~~~~~
|
||||||
input.y:7.14: error: syntax error, unexpected integer
|
input.y:7.14: error: unexpected integer literal
|
||||||
7 | %left "tok2" 2;
|
7 | %left "tok2" 2;
|
||||||
| ^
|
| ^
|
||||||
input.y:8.14: error: syntax error, unexpected integer
|
input.y:8.14: error: unexpected integer literal
|
||||||
8 | %type "tok3" 3;
|
8 | %type "tok3" 3;
|
||||||
| ^
|
| ^
|
||||||
]])
|
]])
|
||||||
@@ -306,6 +306,7 @@ AT_SETUP([Redefining the error token])
|
|||||||
|
|
||||||
# We used to crash when trying to display the original definition of
|
# We used to crash when trying to display the original definition of
|
||||||
# "error", which is a builtin without any location.
|
# "error", which is a builtin without any location.
|
||||||
|
AT_BISON_OPTION_PUSHDEFS
|
||||||
|
|
||||||
AT_DATA([input.y],
|
AT_DATA([input.y],
|
||||||
[[%token error 123
|
[[%token error 123
|
||||||
@@ -318,29 +319,42 @@ AT_BISON_CHECK([-fcaret input.y], [1], [],
|
|||||||
[[input.y:2.8-12: warning: symbol error redeclared [-Wother]
|
[[input.y:2.8-12: warning: symbol error redeclared [-Wother]
|
||||||
2 | %token error 124
|
2 | %token error 124
|
||||||
| ^~~~~
|
| ^~~~~
|
||||||
input.y:1.8-12: previous declaration
|
input.y:1.8-12: note: previous declaration
|
||||||
1 | %token error 123
|
1 | %token error 123
|
||||||
| ^~~~~
|
| ^~~~~
|
||||||
input.y:2.14-16: error: redefining user token number of error
|
input.y:2.14-16: error: redefining code of token error
|
||||||
2 | %token error 124
|
2 | %token error 124
|
||||||
| ^~~
|
| ^~~
|
||||||
]])
|
]])
|
||||||
|
|
||||||
# While at it, make sure we properly used the user's number for
|
# While at it, make sure we properly used the user's number for
|
||||||
# "error".
|
# "error". I don't see what it buys us, but...
|
||||||
AT_DATA([input.y],
|
AT_DATA([input.y],
|
||||||
[[%token error 123
|
[[%{
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
]AT_YYERROR_DEFINE[
|
||||||
|
]AT_YYLEX_DEFINE[
|
||||||
|
%}
|
||||||
|
|
||||||
|
%token error 123
|
||||||
%%
|
%%
|
||||||
exp:
|
exp:
|
||||||
|
%%
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
assert (YYERRCODE == 123);
|
||||||
|
assert (YYTRANSLATE (YYEOF) == YYSYMBOL_YYEOF);
|
||||||
|
assert (YYTRANSLATE (YYERRCODE) == YYSYMBOL_YYERROR);
|
||||||
|
assert (YYTRANSLATE (YYUNDEF) == YYSYMBOL_YYUNDEF);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_BISON_CHECK([input.y])
|
AT_FULL_COMPILE([input])
|
||||||
|
AT_PARSER_CHECK([input], 0)
|
||||||
AT_CHECK([$EGREP -E '123|256' input.tab.c], [],
|
|
||||||
[[ 0, 123, 257
|
|
||||||
#define YYERRCODE 123
|
|
||||||
]])
|
|
||||||
|
|
||||||
|
AT_BISON_OPTION_POPDEFS
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|
||||||
|
|
||||||
@@ -377,7 +391,9 @@ AT_CLEANUP
|
|||||||
AT_SETUP([Symbol declarations])
|
AT_SETUP([Symbol declarations])
|
||||||
|
|
||||||
AT_DATA([dump-symbols.m4],
|
AT_DATA([dump-symbols.m4],
|
||||||
[[m4@&t@_define([b4_symbol_dump],
|
[[m4@&t@_define([b4_api_PREFIX], [YY])
|
||||||
|
|
||||||
|
m4@&t@_define([b4_symbol_dump],
|
||||||
[$1, d@&t@nl
|
[$1, d@&t@nl
|
||||||
b4_symbol_if([$1], [is_token], [Token], [Nonterminal]), d@&t@nl
|
b4_symbol_if([$1], [is_token], [Token], [Nonterminal]), d@&t@nl
|
||||||
b4_symbol([$1], [tag]), d@&t@nl
|
b4_symbol([$1], [tag]), d@&t@nl
|
||||||
@@ -415,9 +431,9 @@ exp:;
|
|||||||
AT_BISON_CHECK([-Wno-other -S./dump-symbols.m4 input.y])
|
AT_BISON_CHECK([-Wno-other -S./dump-symbols.m4 input.y])
|
||||||
AT_CHECK([cat symbols.csv], [],
|
AT_CHECK([cat symbols.csv], [],
|
||||||
[[number, class, tag, id, user_number, type,
|
[[number, class, tag, id, user_number, type,
|
||||||
0, Token, $end, , 0, ,
|
0, Token, "end of file", YYEOF, 0, ,
|
||||||
1, Nonterminal, error, error, 256, ,
|
1, Token, error, YYERRCODE, 256, ,
|
||||||
2, Nonterminal, $undefined, , 257, ,
|
2, Token, "invalid token", YYUNDEF, 257, ,
|
||||||
3, Token, 'a', , 97, ,
|
3, Token, 'a', , 97, ,
|
||||||
4, Token, "A1", A1, 1, ,
|
4, Token, "A1", A1, 1, ,
|
||||||
5, Token, A2, A2, 258, ,
|
5, Token, A2, A2, 258, ,
|
||||||
@@ -753,19 +769,19 @@ AT_BISON_CHECK([-fcaret input.y], [0], [],
|
|||||||
[[input.y:1.12-14: warning: symbol FOO redeclared [-Wother]
|
[[input.y:1.12-14: warning: symbol FOO redeclared [-Wother]
|
||||||
1 | %token FOO FOO
|
1 | %token FOO FOO
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:1.8-10: previous declaration
|
input.y:1.8-10: note: previous declaration
|
||||||
1 | %token FOO FOO
|
1 | %token FOO FOO
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:2.15-17: warning: symbol BAR redeclared [-Wother]
|
input.y:2.15-17: warning: symbol BAR redeclared [-Wother]
|
||||||
2 | %token BAR 12 BAR 12
|
2 | %token BAR 12 BAR 12
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:2.8-10: previous declaration
|
input.y:2.8-10: note: previous declaration
|
||||||
2 | %token BAR 12 BAR 12
|
2 | %token BAR 12 BAR 12
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:3.14-16: warning: symbol EOF redeclared [-Wother]
|
input.y:3.14-16: warning: symbol EOF redeclared [-Wother]
|
||||||
3 | %token EOF 0 EOF 0
|
3 | %token EOF 0 EOF 0
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:3.8-10: previous declaration
|
input.y:3.8-10: note: previous declaration
|
||||||
3 | %token EOF 0 EOF 0
|
3 | %token EOF 0 EOF 0
|
||||||
| ^~~
|
| ^~~
|
||||||
]])
|
]])
|
||||||
@@ -793,13 +809,13 @@ AT_BISON_CHECK([-fcaret input.y], [1], [],
|
|||||||
[[input.y:2.8-10: error: symbol FOO redeclared as a nonterminal
|
[[input.y:2.8-10: error: symbol FOO redeclared as a nonterminal
|
||||||
2 | %nterm FOO BAR
|
2 | %nterm FOO BAR
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:1.8-10: previous definition
|
input.y:1.8-10: note: previous definition
|
||||||
1 | %token FOO
|
1 | %token FOO
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:3.8-10: error: symbol BAR redeclared as a token
|
input.y:3.8-10: error: symbol BAR redeclared as a token
|
||||||
3 | %token BAR
|
3 | %token BAR
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:2.12-14: previous definition
|
input.y:2.12-14: note: previous definition
|
||||||
2 | %nterm FOO BAR
|
2 | %nterm FOO BAR
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:4.8-12: error: symbol error redeclared as a nonterminal
|
input.y:4.8-12: error: symbol error redeclared as a nonterminal
|
||||||
@@ -841,37 +857,37 @@ AT_BISON_CHECK([-fcaret input.y], [1], [],
|
|||||||
[[input.y:1.13-29: error: %destructor redeclaration for <>
|
[[input.y:1.13-29: error: %destructor redeclaration for <>
|
||||||
1 | %destructor { destroy ($$); } <> <>
|
1 | %destructor { destroy ($$); } <> <>
|
||||||
| ^~~~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~~~
|
||||||
input.y:1.13-29: previous declaration
|
input.y:1.13-29: note: previous declaration
|
||||||
1 | %destructor { destroy ($$); } <> <>
|
1 | %destructor { destroy ($$); } <> <>
|
||||||
| ^~~~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~~~
|
||||||
input.y:2.10-24: error: %printer redeclaration for <>
|
input.y:2.10-24: error: %printer redeclaration for <>
|
||||||
2 | %printer { print ($$); } <> <>
|
2 | %printer { print ($$); } <> <>
|
||||||
| ^~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~
|
||||||
input.y:2.10-24: previous declaration
|
input.y:2.10-24: note: previous declaration
|
||||||
2 | %printer { print ($$); } <> <>
|
2 | %printer { print ($$); } <> <>
|
||||||
| ^~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~
|
||||||
input.y:4.13-29: error: %destructor redeclaration for <>
|
input.y:4.13-29: error: %destructor redeclaration for <>
|
||||||
4 | %destructor { destroy ($$); } <>
|
4 | %destructor { destroy ($$); } <>
|
||||||
| ^~~~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~~~
|
||||||
input.y:1.13-29: previous declaration
|
input.y:1.13-29: note: previous declaration
|
||||||
1 | %destructor { destroy ($$); } <> <>
|
1 | %destructor { destroy ($$); } <> <>
|
||||||
| ^~~~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~~~
|
||||||
input.y:5.10-24: error: %printer redeclaration for <>
|
input.y:5.10-24: error: %printer redeclaration for <>
|
||||||
5 | %printer { print ($$); } <>
|
5 | %printer { print ($$); } <>
|
||||||
| ^~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~
|
||||||
input.y:2.10-24: previous declaration
|
input.y:2.10-24: note: previous declaration
|
||||||
2 | %printer { print ($$); } <> <>
|
2 | %printer { print ($$); } <> <>
|
||||||
| ^~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~
|
||||||
input.y:11.13-29: error: %destructor redeclaration for <>
|
input.y:11.13-29: error: %destructor redeclaration for <>
|
||||||
11 | %destructor { destroy ($$); } <>;
|
11 | %destructor { destroy ($$); } <>;
|
||||||
| ^~~~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~~~
|
||||||
input.y:1.13-29: previous declaration
|
input.y:1.13-29: note: previous declaration
|
||||||
1 | %destructor { destroy ($$); } <> <>
|
1 | %destructor { destroy ($$); } <> <>
|
||||||
| ^~~~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~~~
|
||||||
input.y:12.10-24: error: %printer redeclaration for <>
|
input.y:12.10-24: error: %printer redeclaration for <>
|
||||||
12 | %printer { print ($$); } <>;
|
12 | %printer { print ($$); } <>;
|
||||||
| ^~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~
|
||||||
input.y:2.10-24: previous declaration
|
input.y:2.10-24: note: previous declaration
|
||||||
2 | %printer { print ($$); } <> <>
|
2 | %printer { print ($$); } <> <>
|
||||||
| ^~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~
|
||||||
]])
|
]])
|
||||||
@@ -907,21 +923,21 @@ start: %empty;
|
|||||||
|
|
||||||
AT_BISON_CHECK([input.y], [1], [],
|
AT_BISON_CHECK([input.y], [1], [],
|
||||||
[[input.y:4.13-29: error: %destructor redeclaration for <field1>
|
[[input.y:4.13-29: error: %destructor redeclaration for <field1>
|
||||||
input.y:1.13-29: previous declaration
|
input.y:1.13-29: note: previous declaration
|
||||||
input.y:4.13-29: error: %destructor redeclaration for <field1>
|
input.y:4.13-29: error: %destructor redeclaration for <field1>
|
||||||
input.y:1.13-29: previous declaration
|
input.y:1.13-29: note: previous declaration
|
||||||
input.y:5.10-24: error: %printer redeclaration for <field2>
|
input.y:5.10-24: error: %printer redeclaration for <field2>
|
||||||
input.y:2.10-24: previous declaration
|
input.y:2.10-24: note: previous declaration
|
||||||
input.y:5.10-24: error: %printer redeclaration for <field2>
|
input.y:5.10-24: error: %printer redeclaration for <field2>
|
||||||
input.y:2.10-24: previous declaration
|
input.y:2.10-24: note: previous declaration
|
||||||
input.y:11.13-29: error: %destructor redeclaration for <field2>
|
input.y:11.13-29: error: %destructor redeclaration for <field2>
|
||||||
input.y:1.13-29: previous declaration
|
input.y:1.13-29: note: previous declaration
|
||||||
input.y:11.13-29: error: %destructor redeclaration for <field1>
|
input.y:11.13-29: error: %destructor redeclaration for <field1>
|
||||||
input.y:1.13-29: previous declaration
|
input.y:1.13-29: note: previous declaration
|
||||||
input.y:12.10-24: error: %printer redeclaration for <field2>
|
input.y:12.10-24: error: %printer redeclaration for <field2>
|
||||||
input.y:2.10-24: previous declaration
|
input.y:2.10-24: note: previous declaration
|
||||||
input.y:12.10-24: error: %printer redeclaration for <field1>
|
input.y:12.10-24: error: %printer redeclaration for <field1>
|
||||||
input.y:2.10-24: previous declaration
|
input.y:2.10-24: note: previous declaration
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
@@ -1178,10 +1194,10 @@ AT_BISON_CHECK([-fcaret input.y], [1], [],
|
|||||||
[[input.y:2.17-21: warning: symbol "foo" used more than once as a literal string [-Wother]
|
[[input.y:2.17-21: warning: symbol "foo" used more than once as a literal string [-Wother]
|
||||||
2 | BAR 42 "foo"
|
2 | BAR 42 "foo"
|
||||||
| ^~~~~
|
| ^~~~~
|
||||||
input.y:2.10-12: error: user token number 42 redeclaration for BAR
|
input.y:2.10-12: error: code 42 reassigned to token BAR
|
||||||
2 | BAR 42 "foo"
|
2 | BAR 42 "foo"
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:1.15-19: previous declaration for "foo"
|
input.y:1.15-19: note: previous declaration for "foo"
|
||||||
1 | %token FOO 42 "foo"
|
1 | %token FOO 42 "foo"
|
||||||
| ^~~~~
|
| ^~~~~
|
||||||
]])
|
]])
|
||||||
@@ -1212,7 +1228,7 @@ exp: foo;
|
|||||||
[[input.y:3.7-11: error: %type redeclaration for foo
|
[[input.y:3.7-11: error: %type redeclaration for foo
|
||||||
3 | %type <baz> foo
|
3 | %type <baz> foo
|
||||||
| ^~~~~
|
| ^~~~~
|
||||||
input.y:2.7-11: previous declaration
|
input.y:2.7-11: note: previous declaration
|
||||||
2 | %type <bar> "foo"
|
2 | %type <bar> "foo"
|
||||||
| ^~~~~
|
| ^~~~~
|
||||||
]])
|
]])
|
||||||
@@ -1226,7 +1242,7 @@ exp: foo;
|
|||||||
[[input.y:3.10-14: error: %printer redeclaration for foo
|
[[input.y:3.10-14: error: %printer redeclaration for foo
|
||||||
3 | %printer {baz} foo
|
3 | %printer {baz} foo
|
||||||
| ^~~~~
|
| ^~~~~
|
||||||
input.y:2.10-14: previous declaration
|
input.y:2.10-14: note: previous declaration
|
||||||
2 | %printer {bar} "foo"
|
2 | %printer {bar} "foo"
|
||||||
| ^~~~~
|
| ^~~~~
|
||||||
]])
|
]])
|
||||||
@@ -1240,7 +1256,7 @@ exp: foo;
|
|||||||
[[input.y:3.13-17: error: %destructor redeclaration for foo
|
[[input.y:3.13-17: error: %destructor redeclaration for foo
|
||||||
3 | %destructor {baz} foo
|
3 | %destructor {baz} foo
|
||||||
| ^~~~~
|
| ^~~~~
|
||||||
input.y:2.13-17: previous declaration
|
input.y:2.13-17: note: previous declaration
|
||||||
2 | %destructor {bar} "foo"
|
2 | %destructor {bar} "foo"
|
||||||
| ^~~~~
|
| ^~~~~
|
||||||
]])
|
]])
|
||||||
@@ -1254,7 +1270,7 @@ exp: foo;
|
|||||||
[[input.y:3.1-5: error: %left redeclaration for foo
|
[[input.y:3.1-5: error: %left redeclaration for foo
|
||||||
3 | %left foo
|
3 | %left foo
|
||||||
| ^~~~~
|
| ^~~~~
|
||||||
input.y:2.1-5: previous declaration
|
input.y:2.1-5: note: previous declaration
|
||||||
2 | %left "foo"
|
2 | %left "foo"
|
||||||
| ^~~~~
|
| ^~~~~
|
||||||
]])
|
]])
|
||||||
@@ -1271,7 +1287,7 @@ exp: foo;
|
|||||||
[[input.y:2.1-5: error: %left redeclaration for foo
|
[[input.y:2.1-5: error: %left redeclaration for foo
|
||||||
2 | %left foo
|
2 | %left foo
|
||||||
| ^~~~~
|
| ^~~~~
|
||||||
input.y:1.1-5: previous declaration
|
input.y:1.1-5: note: previous declaration
|
||||||
1 | %left "foo"
|
1 | %left "foo"
|
||||||
| ^~~~~
|
| ^~~~~
|
||||||
]])
|
]])
|
||||||
@@ -1286,7 +1302,7 @@ exp: foo;
|
|||||||
[[input.y:2.10-11: error: %printer redeclaration for foo
|
[[input.y:2.10-11: error: %printer redeclaration for foo
|
||||||
2 | %printer {} foo
|
2 | %printer {} foo
|
||||||
| ^~
|
| ^~
|
||||||
input.y:1.10-11: previous declaration
|
input.y:1.10-11: note: previous declaration
|
||||||
1 | %printer {} "foo"
|
1 | %printer {} "foo"
|
||||||
| ^~
|
| ^~
|
||||||
]])
|
]])
|
||||||
@@ -1301,7 +1317,7 @@ exp: foo;
|
|||||||
[[input.y:2.13-14: error: %destructor redeclaration for foo
|
[[input.y:2.13-14: error: %destructor redeclaration for foo
|
||||||
2 | %destructor {} foo
|
2 | %destructor {} foo
|
||||||
| ^~
|
| ^~
|
||||||
input.y:1.13-14: previous declaration
|
input.y:1.13-14: note: previous declaration
|
||||||
1 | %destructor {} "foo"
|
1 | %destructor {} "foo"
|
||||||
| ^~
|
| ^~
|
||||||
]])
|
]])
|
||||||
@@ -1323,7 +1339,7 @@ AT_SETUP([Torturing the Scanner])
|
|||||||
AT_BISON_OPTION_PUSHDEFS
|
AT_BISON_OPTION_PUSHDEFS
|
||||||
AT_DATA([input.y], [])
|
AT_DATA([input.y], [])
|
||||||
AT_BISON_CHECK([input.y], [1], [],
|
AT_BISON_CHECK([input.y], [1], [],
|
||||||
[[input.y:1.1: error: syntax error, unexpected end of file
|
[[input.y:1.1: error: unexpected end of file
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
|
||||||
@@ -1331,7 +1347,7 @@ AT_DATA([input.y],
|
|||||||
[{}
|
[{}
|
||||||
])
|
])
|
||||||
AT_BISON_CHECK([-fcaret input.y], [1], [],
|
AT_BISON_CHECK([-fcaret input.y], [1], [],
|
||||||
[[input.y:1.1-2: error: syntax error, unexpected {...}
|
[[input.y:1.1-2: error: unexpected {...}
|
||||||
1 | {}
|
1 | {}
|
||||||
| ^~
|
| ^~
|
||||||
]])
|
]])
|
||||||
@@ -1528,7 +1544,7 @@ AT_CHECK_REQUIRE(100.0, 63)
|
|||||||
AT_SETUP([String aliases for character tokens])
|
AT_SETUP([String aliases for character tokens])
|
||||||
|
|
||||||
# Bison once thought a character token and its alias were different
|
# Bison once thought a character token and its alias were different
|
||||||
# symbols with the same user token number.
|
# symbols with the same code.
|
||||||
|
|
||||||
AT_BISON_OPTION_PUSHDEFS
|
AT_BISON_OPTION_PUSHDEFS
|
||||||
AT_DATA_GRAMMAR([input.y],
|
AT_DATA_GRAMMAR([input.y],
|
||||||
@@ -1627,10 +1643,10 @@ start: DECIMAL_1 HEXADECIMAL_2;
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
AT_BISON_CHECK([redecl.y], [1], [],
|
AT_BISON_CHECK([redecl.y], [1], [],
|
||||||
[[redecl.y:10.10-22: error: user token number 11259375 redeclaration for HEXADECIMAL_1
|
[[redecl.y:10.10-22: error: code 11259375 reassigned to token HEXADECIMAL_1
|
||||||
redecl.y:9.8-16: previous declaration for DECIMAL_1
|
redecl.y:9.8-16: note: previous declaration for DECIMAL_1
|
||||||
redecl.y:12.10-18: error: user token number 16702650 redeclaration for DECIMAL_2
|
redecl.y:12.10-18: error: code 16702650 reassigned to token DECIMAL_2
|
||||||
redecl.y:11.10-22: previous declaration for HEXADECIMAL_2
|
redecl.y:11.10-22: note: previous declaration for HEXADECIMAL_2
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_DATA_GRAMMAR([too-large.y],
|
AT_DATA_GRAMMAR([too-large.y],
|
||||||
@@ -1643,9 +1659,9 @@ start: TOO_LARGE_DEC TOO_LARGE_HEX
|
|||||||
|
|
||||||
AT_BISON_CHECK([too-large.y], [1], [],
|
AT_BISON_CHECK([too-large.y], [1], [],
|
||||||
[[too-large.y:9.22-42: error: integer out of range: '999999999999999999999'
|
[[too-large.y:9.22-42: error: integer out of range: '999999999999999999999'
|
||||||
too-large.y:9.22-42: error: user token number of TOO_LARGE_DEC too large
|
too-large.y:9.22-42: error: code of token TOO_LARGE_DEC too large
|
||||||
too-large.y:10.24-44: error: integer out of range: '0xFFFFFFFFFFFFFFFFFFF'
|
too-large.y:10.24-44: error: integer out of range: '0xFFFFFFFFFFFFFFFFFFF'
|
||||||
too-large.y:10.24-44: error: user token number of TOO_LARGE_HEX too large
|
too-large.y:10.24-44: error: code of token TOO_LARGE_HEX too large
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_BISON_OPTION_POPDEFS
|
AT_BISON_OPTION_POPDEFS
|
||||||
@@ -1701,7 +1717,7 @@ input.y:16.11-17.0: error: missing '"' at end of line
|
|||||||
input.y:19.13-20.0: error: missing '}' at end of file
|
input.y:19.13-20.0: error: missing '}' at end of file
|
||||||
19 | %destructor { free ($$)
|
19 | %destructor { free ($$)
|
||||||
| ^~~~~~~~~~~
|
| ^~~~~~~~~~~
|
||||||
input.y:20.1: error: syntax error, unexpected end of file
|
input.y:20.1: error: unexpected end of file
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
@@ -1916,9 +1932,9 @@ start: %empty;
|
|||||||
|
|
||||||
AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
|
AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
|
||||||
[[input-redefined.y:2.1-20: warning: %define variable 'var' redefined [-Wother]
|
[[input-redefined.y:2.1-20: warning: %define variable 'var' redefined [-Wother]
|
||||||
input-redefined.y:1.1-20: previous definition
|
input-redefined.y:1.1-20: note: previous definition
|
||||||
input-redefined.y:3.2-21: error: %define variable 'var' redefined
|
input-redefined.y:3.2-21: error: %define variable 'var' redefined
|
||||||
input-redefined.y:2.1-20: previous definition
|
input-redefined.y:2.1-20: note: previous definition
|
||||||
input-redefined.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
input-redefined.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
@@ -1974,7 +1990,7 @@ start: %empty;
|
|||||||
]])
|
]])
|
||||||
AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
|
AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
|
||||||
[[input-dg.y:1.1-18: error: %define variable 'var' redefined
|
[[input-dg.y:1.1-18: error: %define variable 'var' redefined
|
||||||
<command line>:3: previous definition
|
<command line>:3: note: previous definition
|
||||||
input-dg.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
input-dg.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
@@ -1987,7 +2003,7 @@ AT_BISON_CHECK([[-fcaret -Dvar=cmd-d input-dg.y]], [[1]], [],
|
|||||||
[[input-dg.y:1.1-18: error: %define variable 'var' redefined
|
[[input-dg.y:1.1-18: error: %define variable 'var' redefined
|
||||||
1 | %define var "gram"
|
1 | %define var "gram"
|
||||||
| ^~~~~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~~~~
|
||||||
<command line>:4: previous definition
|
<command line>:4: note: previous definition
|
||||||
input-dg.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
input-dg.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
@@ -2110,9 +2126,9 @@ AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
|
|||||||
[[input.y:1.1-34: error: invalid value for %define variable 'lr.default-reduction': 'bogus'
|
[[input.y:1.1-34: error: invalid value for %define variable 'lr.default-reduction': 'bogus'
|
||||||
1 | %define lr.default-reduction bogus
|
1 | %define lr.default-reduction bogus
|
||||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
input.y:1.1-34: accepted value: 'most'
|
input.y:1.1-34: note: accepted value: 'most'
|
||||||
input.y:1.1-34: accepted value: 'consistent'
|
input.y:1.1-34: note: accepted value: 'consistent'
|
||||||
input.y:1.1-34: accepted value: 'accepting'
|
input.y:1.1-34: note: accepted value: 'accepting'
|
||||||
]])
|
]])
|
||||||
|
|
||||||
# Check escapes.
|
# Check escapes.
|
||||||
@@ -2128,9 +2144,9 @@ AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
|
|||||||
input.y:1.1-35: error: invalid value for %define variable 'lr.default-reduction': '[$@]'
|
input.y:1.1-35: error: invalid value for %define variable 'lr.default-reduction': '[$@]'
|
||||||
1 | %define lr.default-reduction {[$@]}
|
1 | %define lr.default-reduction {[$@]}
|
||||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
input.y:1.1-35: accepted value: 'most'
|
input.y:1.1-35: note: accepted value: 'most'
|
||||||
input.y:1.1-35: accepted value: 'consistent'
|
input.y:1.1-35: note: accepted value: 'consistent'
|
||||||
input.y:1.1-35: accepted value: 'accepting'
|
input.y:1.1-35: note: accepted value: 'accepting'
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
|
||||||
@@ -2144,9 +2160,9 @@ AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
|
|||||||
[[input.y:1.1-29: error: invalid value for %define variable 'api.push-pull': 'neither'
|
[[input.y:1.1-29: error: invalid value for %define variable 'api.push-pull': 'neither'
|
||||||
1 | %define api.push-pull neither
|
1 | %define api.push-pull neither
|
||||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
input.y:1.1-29: accepted value: 'pull'
|
input.y:1.1-29: note: accepted value: 'pull'
|
||||||
input.y:1.1-29: accepted value: 'push'
|
input.y:1.1-29: note: accepted value: 'push'
|
||||||
input.y:1.1-29: accepted value: 'both'
|
input.y:1.1-29: note: accepted value: 'both'
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
@@ -2441,14 +2457,14 @@ AT_BISON_CHECK([[-Dparse.lac=full -L c++ input.y]])
|
|||||||
AT_BISON_CHECK([[-Dparse.lac=unsupported input.y]],
|
AT_BISON_CHECK([[-Dparse.lac=unsupported input.y]],
|
||||||
[[1]], [],
|
[[1]], [],
|
||||||
[[<command line>:3: error: invalid value for %define variable 'parse.lac': 'unsupported'
|
[[<command line>:3: error: invalid value for %define variable 'parse.lac': 'unsupported'
|
||||||
<command line>:3: accepted value: 'full'
|
<command line>:3: note: accepted value: 'full'
|
||||||
<command line>:3: accepted value: 'none'
|
<command line>:3: note: accepted value: 'none'
|
||||||
]])
|
]])
|
||||||
AT_BISON_CHECK([[-Dparse.lac=unsupported -L c++ input.y]],
|
AT_BISON_CHECK([[-Dparse.lac=unsupported -L c++ input.y]],
|
||||||
[[1]], [],
|
[[1]], [],
|
||||||
[[<command line>:3: error: invalid value for %define variable 'parse.lac': 'unsupported'
|
[[<command line>:3: error: invalid value for %define variable 'parse.lac': 'unsupported'
|
||||||
<command line>:3: accepted value: 'full'
|
<command line>:3: note: accepted value: 'full'
|
||||||
<command line>:3: accepted value: 'none'
|
<command line>:3: note: accepted value: 'none'
|
||||||
]])
|
]])
|
||||||
|
|
||||||
# parse.lac.* options are useless if LAC isn't actually activated.
|
# parse.lac.* options are useless if LAC isn't actually activated.
|
||||||
@@ -2573,9 +2589,9 @@ AT_TEST([[%union foo {};
|
|||||||
%define api.value.union.name foo]],
|
%define api.value.union.name foo]],
|
||||||
[0],
|
[0],
|
||||||
[[input.y:3.8-10: warning: %define variable 'api.value.union.name' redefined [-Wother]
|
[[input.y:3.8-10: warning: %define variable 'api.value.union.name' redefined [-Wother]
|
||||||
input.y:1.8-10: previous definition
|
input.y:1.8-10: note: previous definition
|
||||||
input.y:4.1-32: warning: %define variable 'api.value.union.name' redefined [-Wother]
|
input.y:4.1-32: warning: %define variable 'api.value.union.name' redefined [-Wother]
|
||||||
input.y:3.8-10: previous definition
|
input.y:3.8-10: note: previous definition
|
||||||
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
|
|
||||||
@@ -2747,7 +2763,7 @@ fix-it:"input.y":{12:1-12:11}:"%expect-rr"
|
|||||||
input.y:13.1-14: warning: deprecated directive: '%file-prefix =', use '%file-prefix' [-Wdeprecated]
|
input.y:13.1-14: warning: deprecated directive: '%file-prefix =', use '%file-prefix' [-Wdeprecated]
|
||||||
fix-it:"input.y":{13:1-13:15}:"%file-prefix"
|
fix-it:"input.y":{13:1-13:15}:"%file-prefix"
|
||||||
input.y:14.1-16.5: warning: duplicate directive: '%file-prefix\n =' [-Wother]
|
input.y:14.1-16.5: warning: duplicate directive: '%file-prefix\n =' [-Wother]
|
||||||
input.y:13.1-20: previous declaration
|
input.y:13.1-20: note: previous declaration
|
||||||
fix-it:"input.y":{14:1-16:6}:""
|
fix-it:"input.y":{14:1-16:6}:""
|
||||||
input.y:17.9-27: warning: deprecated directive: '%fixed-output_files', use '%output "y.tab.c"' [-Wdeprecated]
|
input.y:17.9-27: warning: deprecated directive: '%fixed-output_files', use '%output "y.tab.c"' [-Wdeprecated]
|
||||||
fix-it:"input.y":{17:2-17:21}:"%output \"y.tab.c\""
|
fix-it:"input.y":{17:2-17:21}:"%output \"y.tab.c\""
|
||||||
@@ -2770,10 +2786,10 @@ fix-it:"input.y":{25:1-25:13}:"%define api.pure"
|
|||||||
input.y:26.1-12: warning: deprecated directive: '%token_table', use '%token-table' [-Wdeprecated]
|
input.y:26.1-12: warning: deprecated directive: '%token_table', use '%token-table' [-Wdeprecated]
|
||||||
fix-it:"input.y":{26:1-26:13}:"%token-table"
|
fix-it:"input.y":{26:1-26:13}:"%token-table"
|
||||||
input.y:27.1-14: warning: %define variable 'parse.error' redefined [-Wother]
|
input.y:27.1-14: warning: %define variable 'parse.error' redefined [-Wother]
|
||||||
input.y:11.1-14: previous definition
|
input.y:11.1-14: note: previous definition
|
||||||
fix-it:"input.y":{27:1-27:15}:""
|
fix-it:"input.y":{27:1-27:15}:""
|
||||||
input.y:29.1-18: warning: duplicate directive: '%name-prefix "bar"' [-Wother]
|
input.y:29.1-18: warning: duplicate directive: '%name-prefix "bar"' [-Wother]
|
||||||
input.y:13.1-20: previous declaration
|
input.y:13.1-20: note: previous declaration
|
||||||
fix-it:"input.y":{29:1-29:19}:""
|
fix-it:"input.y":{29:1-29:19}:""
|
||||||
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
@@ -2856,9 +2872,9 @@ input.y:11.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr'
|
|||||||
input.y:12.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
|
input.y:12.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
|
||||||
input.y:13.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
|
input.y:13.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
|
||||||
input.y:13.16-29: warning: %define variable 'parse.error' redefined [-Wother]
|
input.y:13.16-29: warning: %define variable 'parse.error' redefined [-Wother]
|
||||||
input.y:13.1-14: previous definition
|
input.y:13.1-14: note: previous definition
|
||||||
input.y:14.16-29: warning: %define variable 'parse.error' redefined [-Wother]
|
input.y:14.16-29: warning: %define variable 'parse.error' redefined [-Wother]
|
||||||
input.y:13.16-29: previous definition
|
input.y:13.16-29: note: previous definition
|
||||||
input.y: error: reduce/reduce conflicts: 0 found, 42 expected
|
input.y: error: reduce/reduce conflicts: 0 found, 42 expected
|
||||||
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
@@ -2893,7 +2909,7 @@ AT_DATA_GRAMMAR([[input.y]],
|
|||||||
|
|
||||||
AT_BISON_CHECK([[input.y]], [[0]], [[]],
|
AT_BISON_CHECK([[input.y]], [[0]], [[]],
|
||||||
[[input.y:14.1-15.5: warning: duplicate directive: '%file-prefix' [-Wother]
|
[[input.y:14.1-15.5: warning: duplicate directive: '%file-prefix' [-Wother]
|
||||||
input.y:13.1-18: previous declaration
|
input.y:13.1-18: note: previous declaration
|
||||||
input.y: warning: %expect-rr applies only to GLR parsers [-Wother]
|
input.y: warning: %expect-rr applies only to GLR parsers [-Wother]
|
||||||
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
|
||||||
]])
|
]])
|
||||||
@@ -2943,16 +2959,44 @@ AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
|
|||||||
[[input.y:10.8-10: error: character literals cannot be used together with api.token.raw
|
[[input.y:10.8-10: error: character literals cannot be used together with api.token.raw
|
||||||
10 | %token 'a'
|
10 | %token 'a'
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:9.1-21: definition of api.token.raw
|
input.y:9.1-21: note: definition of api.token.raw
|
||||||
9 | %define api.token.raw
|
9 | %define api.token.raw
|
||||||
| ^~~~~~~~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~~~~~~~
|
||||||
input.y:12.6-8: error: character literals cannot be used together with api.token.raw
|
input.y:12.6-8: error: character literals cannot be used together with api.token.raw
|
||||||
12 | exp: 'b' "c" {}
|
12 | exp: 'b' "c" {}
|
||||||
| ^~~
|
| ^~~
|
||||||
input.y:9.1-21: definition of api.token.raw
|
input.y:9.1-21: note: definition of api.token.raw
|
||||||
9 | %define api.token.raw
|
9 | %define api.token.raw
|
||||||
| ^~~~~~~~~~~~~~~~~~~~~
|
| ^~~~~~~~~~~~~~~~~~~~~
|
||||||
]])
|
]])
|
||||||
|
|
||||||
AT_BISON_OPTION_POPDEFS
|
AT_BISON_OPTION_POPDEFS
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## ------------------------------ ##
|
||||||
|
## %token-table and parse.error. ##
|
||||||
|
## ------------------------------ ##
|
||||||
|
|
||||||
|
AT_SETUP([[%token-table and parse.error]])
|
||||||
|
|
||||||
|
# AT_TEST(DIRECTIVES, ERROR-LOCATION)
|
||||||
|
# -----------------------------------
|
||||||
|
m4_pushdef([AT_TEST],
|
||||||
|
[AT_DATA([[input.y]],
|
||||||
|
[[$1
|
||||||
|
%%
|
||||||
|
exp: %empty;
|
||||||
|
]])
|
||||||
|
AT_BISON_CHECK([[input.y]], [[1]], [[]],
|
||||||
|
[$2: error: '%token-table' and '%define parse.error (custom|detailed)' cannot be used together
|
||||||
|
])
|
||||||
|
])
|
||||||
|
|
||||||
|
AT_TEST([%define parse.error custom %token-table], [[input.y:1.1-26]])
|
||||||
|
AT_TEST([%define parse.error detailed %token-table],[[input.y:1.1-28]])
|
||||||
|
|
||||||
|
m4_popdef([AT_TEST])
|
||||||
|
|
||||||
|
AT_CLEANUP
|
||||||
|
|||||||
+34
-302
@@ -47,320 +47,52 @@ AT_CLEANUP
|
|||||||
# ------------------------- #
|
# ------------------------- #
|
||||||
|
|
||||||
|
|
||||||
# _AT_DATA_JAVA_CALC_Y($1, $2, $3, [BISON-DIRECTIVES])
|
# AT_JAVA_POSITION_DEFINE_OLD
|
||||||
# ----------------------------------------------------
|
# -----------------------
|
||||||
# Produce 'calc.y'. Don't call this macro directly, because it contains
|
m4_define([AT_JAVA_POSITION_DEFINE_OLD],
|
||||||
# some occurrences of '$1' etc. which will be interpreted by m4. So
|
[[class Position {
|
||||||
# you should call it with $1, $2, and $3 as arguments, which is what
|
public int line;
|
||||||
# AT_DATA_JAVA_CALC_Y does.
|
public int token;
|
||||||
m4_define([_AT_DATA_JAVA_CALC_Y],
|
|
||||||
[m4_if([$1$2$3], $[1]$[2]$[3], [],
|
|
||||||
[m4_fatal([$0: Invalid arguments: $@])])dnl
|
|
||||||
AT_BISON_OPTION_PUSHDEFS([%language "Java" $4])
|
|
||||||
AT_DATA_GRAMMAR([Calc.y],
|
|
||||||
[[/* Infix notation calculator--calc */
|
|
||||||
%language "Java"
|
|
||||||
%define api.prefix {Calc}
|
|
||||||
%define api.parser.class {Calc}
|
|
||||||
%define public
|
|
||||||
|
|
||||||
]$4[
|
public Position ()
|
||||||
|
|
||||||
%code imports {
|
|
||||||
import java.io.StreamTokenizer;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.IOException;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Bison Declarations */
|
|
||||||
%token <Integer> NUM "number"
|
|
||||||
%type <Integer> exp
|
|
||||||
|
|
||||||
%nonassoc '=' /* comparison */
|
|
||||||
%left '-' '+'
|
|
||||||
%left '*' '/'
|
|
||||||
%precedence NEG /* negation--unary minus */
|
|
||||||
%right '^' /* exponentiation */
|
|
||||||
|
|
||||||
/* Grammar follows */
|
|
||||||
%%
|
|
||||||
input:
|
|
||||||
line
|
|
||||||
| input line
|
|
||||||
;
|
|
||||||
|
|
||||||
line:
|
|
||||||
'\n'
|
|
||||||
| exp '\n'
|
|
||||||
| error '\n'
|
|
||||||
;
|
|
||||||
|
|
||||||
exp:
|
|
||||||
NUM { $$ = $1; }
|
|
||||||
| exp '=' exp
|
|
||||||
{
|
{
|
||||||
if ($1.intValue () != $3.intValue ())
|
line = 0;
|
||||||
yyerror (]AT_LOCATION_IF([[@$,]])[ "calc: error: " + $1 + " != " + $3);
|
token = 0;
|
||||||
}
|
}
|
||||||
| exp '+' exp { $$ = new Integer ($1.intValue () + $3.intValue ()); }
|
|
||||||
| exp '-' exp { $$ = new Integer ($1.intValue () - $3.intValue ()); }
|
|
||||||
| exp '*' exp { $$ = new Integer ($1.intValue () * $3.intValue ()); }
|
|
||||||
| exp '/' exp { $$ = new Integer ($1.intValue () / $3.intValue ()); }
|
|
||||||
| '-' exp %prec NEG { $$ = new Integer (-$2.intValue ()); }
|
|
||||||
| exp '^' exp { $$ = new Integer ((int)
|
|
||||||
Math.pow ($1.intValue (),
|
|
||||||
$3.intValue ())); }
|
|
||||||
| '(' exp ')' { $$ = $2; }
|
|
||||||
| '(' error ')' { $$ = new Integer (1111); }
|
|
||||||
| '!' { $$ = new Integer (0); return YYERROR; }
|
|
||||||
| '-' error { $$ = new Integer (0); return YYERROR; }
|
|
||||||
;
|
|
||||||
|
|
||||||
]AT_LEXPARAM_IF([[
|
public Position (int l, int t)
|
||||||
%code lexer {
|
|
||||||
]],
|
|
||||||
[[
|
|
||||||
%%
|
|
||||||
class CalcLexer implements Calc.Lexer {
|
|
||||||
]])[
|
|
||||||
StreamTokenizer st;
|
|
||||||
|
|
||||||
public ]AT_LEXPARAM_IF([[YYLexer]], [[CalcLexer]])[ (InputStream is)
|
|
||||||
{
|
{
|
||||||
st = new StreamTokenizer (new InputStreamReader (is));
|
line = l;
|
||||||
st.resetSyntax ();
|
token = t;
|
||||||
st.eolIsSignificant (true);
|
|
||||||
st.whitespaceChars ('\t', '\t');
|
|
||||||
st.whitespaceChars (' ', ' ');
|
|
||||||
st.wordChars ('0', '9');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
]AT_LOCATION_IF([[
|
public boolean equals (Position l)
|
||||||
Position yypos = new Position (1, 0);
|
|
||||||
|
|
||||||
public Position getStartPos() {
|
|
||||||
return yypos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Position getEndPos() {
|
|
||||||
return yypos;
|
|
||||||
}
|
|
||||||
]])[
|
|
||||||
]AT_YYERROR_DEFINE[
|
|
||||||
|
|
||||||
Integer yylval;
|
|
||||||
|
|
||||||
public Object getLVal() {
|
|
||||||
return yylval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int yylex () throws IOException {
|
|
||||||
int ttype = st.nextToken ();]AT_LOCATION_IF([[
|
|
||||||
yypos = new Position (yypos.lineno (), yypos.token () + 1);]])[
|
|
||||||
if (ttype == st.TT_EOF)
|
|
||||||
return EOF;
|
|
||||||
|
|
||||||
else if (ttype == st.TT_EOL)
|
|
||||||
{]AT_LOCATION_IF([[
|
|
||||||
yypos = new Position (yypos.lineno () + 1, 0);]])[
|
|
||||||
return (int) '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (ttype == st.TT_WORD)
|
|
||||||
{
|
|
||||||
yylval = new Integer (st.sval);
|
|
||||||
return NUM;
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
return st.ttype;
|
|
||||||
}
|
|
||||||
]AT_LEXPARAM_IF([[
|
|
||||||
};
|
|
||||||
%%]], [[
|
|
||||||
}]])[
|
|
||||||
]AT_JAVA_POSITION_DEFINE[
|
|
||||||
]])
|
|
||||||
|
|
||||||
AT_BISON_OPTION_POPDEFS
|
|
||||||
])# _AT_DATA_JAVA_CALC_Y
|
|
||||||
|
|
||||||
|
|
||||||
# AT_DATA_CALC_Y([BISON-OPTIONS])
|
|
||||||
# -------------------------------
|
|
||||||
# Produce 'calc.y'.
|
|
||||||
m4_define([AT_DATA_JAVA_CALC_Y],
|
|
||||||
[_AT_DATA_JAVA_CALC_Y($[1], $[2], $[3], [$1])
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
# _AT_CHECK_JAVA_CALC_ERROR(BISON-OPTIONS, INPUT,
|
|
||||||
# [VERBOSE-AND-LOCATED-ERROR-MESSAGE])
|
|
||||||
# --------------------------------------------------------------
|
|
||||||
# Run 'calc' on INPUT, and expect a 'syntax error' message.
|
|
||||||
#
|
|
||||||
# If INPUT starts with a slash, it is used as absolute input file name,
|
|
||||||
# otherwise as contents.
|
|
||||||
#
|
|
||||||
# The VERBOSE-AND-LOCATED-ERROR-MESSAGE is stripped of locations
|
|
||||||
# and expected tokens if necessary, and compared with the output.
|
|
||||||
m4_define([_AT_CHECK_JAVA_CALC_ERROR],
|
|
||||||
[m4_bmatch([$2], [^/],
|
|
||||||
[AT_JAVA_PARSER_CHECK([Calc < $2], 0, [], [stderr])],
|
|
||||||
[AT_DATA([[input]],
|
|
||||||
[[$2
|
|
||||||
]])
|
|
||||||
AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr])])
|
|
||||||
|
|
||||||
# Normalize the observed and expected error messages, depending upon the
|
|
||||||
# options.
|
|
||||||
# 1. Create the reference error message.
|
|
||||||
AT_DATA([[expout]],
|
|
||||||
[$3
|
|
||||||
])
|
|
||||||
# 2. If locations are not used, remove them.
|
|
||||||
AT_YYERROR_SEES_LOC_IF([],
|
|
||||||
[[sed 's/^[-0-9.]*: //' expout >at-expout
|
|
||||||
mv at-expout expout]])
|
|
||||||
# 3. If error-verbose is not used, strip the', unexpected....' part.
|
|
||||||
m4_bmatch([$1], [%define parse.error verbose], [],
|
|
||||||
[[sed 's/syntax error, .*$/syntax error/' expout >at-expout
|
|
||||||
mv at-expout expout]])
|
|
||||||
# 4. Check
|
|
||||||
AT_CHECK([cat stderr], 0, [expout])
|
|
||||||
])
|
|
||||||
|
|
||||||
# _AT_CHECK_JAVA_CALC([BISON-DIRECTIVES], [BISON-CODE])
|
|
||||||
# -----------------------------------------------------
|
|
||||||
# Start a testing chunk which compiles 'calc' grammar with
|
|
||||||
# BISON-DIRECTIVES, and performs several tests over the parser.
|
|
||||||
m4_define([_AT_CHECK_JAVA_CALC],
|
|
||||||
[# We use integers to avoid dependencies upon the precision of doubles.
|
|
||||||
AT_SETUP([Calculator $1])
|
|
||||||
|
|
||||||
AT_BISON_OPTION_PUSHDEFS([$1])
|
|
||||||
|
|
||||||
AT_DATA_JAVA_CALC_Y([$1
|
|
||||||
%code {
|
|
||||||
$2
|
|
||||||
}])
|
|
||||||
|
|
||||||
AT_BISON_CHECK([-Wno-deprecated -o Calc.java Calc.y])
|
|
||||||
AT_JAVA_COMPILE([Calc.java])
|
|
||||||
|
|
||||||
# Test the precedences.
|
|
||||||
AT_DATA([[input]],
|
|
||||||
[[1 + 2 * 3 = 7
|
|
||||||
1 + 2 * -3 = -5
|
|
||||||
|
|
||||||
-1^2 = -1
|
|
||||||
(-1)^2 = 1
|
|
||||||
|
|
||||||
---1 = -1
|
|
||||||
|
|
||||||
1 - 2 - 3 = -4
|
|
||||||
1 - (2 - 3) = 2
|
|
||||||
|
|
||||||
2^2^3 = 256
|
|
||||||
(2^2)^3 = 64
|
|
||||||
]])
|
|
||||||
AT_JAVA_PARSER_CHECK([Calc < input], 0, [], [stderr])
|
|
||||||
|
|
||||||
|
|
||||||
# Some syntax errors.
|
|
||||||
_AT_CHECK_JAVA_CALC_ERROR([$1], [0 0],
|
|
||||||
[1.2: syntax error, unexpected number])
|
|
||||||
_AT_CHECK_JAVA_CALC_ERROR([$1], [1//2],
|
|
||||||
[1.3: syntax error, unexpected '/', expecting number or '-' or '(' or '!'])
|
|
||||||
_AT_CHECK_JAVA_CALC_ERROR([$1], [error],
|
|
||||||
[1.1: syntax error, unexpected $undefined])
|
|
||||||
_AT_CHECK_JAVA_CALC_ERROR([$1], [1 = 2 = 3],
|
|
||||||
[1.4: syntax error, unexpected '='])
|
|
||||||
_AT_CHECK_JAVA_CALC_ERROR([$1], [
|
|
||||||
+1],
|
|
||||||
[2.1: syntax error, unexpected '+'])
|
|
||||||
# Exercise error messages with EOF: work on an empty file.
|
|
||||||
_AT_CHECK_JAVA_CALC_ERROR([$1], [/dev/null],
|
|
||||||
[1.1: syntax error, unexpected end of input])
|
|
||||||
|
|
||||||
# Exercise the error token: without it, we die at the first error,
|
|
||||||
# hence be sure to
|
|
||||||
#
|
|
||||||
# - have several errors which exercise different shift/discardings
|
|
||||||
# - (): nothing to pop, nothing to discard
|
|
||||||
# - (1 + 1 + 1 +): a lot to pop, nothing to discard
|
|
||||||
# - (* * *): nothing to pop, a lot to discard
|
|
||||||
# - (1 + 2 * *): some to pop and discard
|
|
||||||
#
|
|
||||||
# - test the action associated to 'error'
|
|
||||||
#
|
|
||||||
# - check the lookahead that triggers an error is not discarded
|
|
||||||
# when we enter error recovery. Below, the lookahead causing the
|
|
||||||
# first error is ")", which is needed to recover from the error and
|
|
||||||
# produce the "0" that triggers the "0 != 1" error.
|
|
||||||
#
|
|
||||||
_AT_CHECK_JAVA_CALC_ERROR([$1],
|
|
||||||
[() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
|
|
||||||
[1.2: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
|
|
||||||
1.11: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
|
|
||||||
1.14: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
|
||||||
1.24: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
|
||||||
1.1-1.27: calc: error: 4444 != 1])
|
|
||||||
|
|
||||||
# The same, but this time exercising explicitly triggered syntax errors.
|
|
||||||
# POSIX says the lookahead causing the error should not be discarded.
|
|
||||||
_AT_CHECK_JAVA_CALC_ERROR([$1], [(!) + (0 0) = 1],
|
|
||||||
[1.7: syntax error, unexpected number
|
|
||||||
1.1-1.10: calc: error: 2222 != 1])
|
|
||||||
_AT_CHECK_JAVA_CALC_ERROR([$1], [(- *) + (0 0) = 1],
|
|
||||||
[1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
|
||||||
1.8: syntax error, unexpected number
|
|
||||||
1.1-1.11: calc: error: 2222 != 1])
|
|
||||||
AT_BISON_OPTION_POPDEFS
|
|
||||||
|
|
||||||
AT_CLEANUP
|
|
||||||
])# _AT_CHECK_JAVA_CALC
|
|
||||||
|
|
||||||
|
|
||||||
# AT_CHECK_JAVA_CALC([BISON-DIRECTIVES])
|
|
||||||
# --------------------------------------
|
|
||||||
# Start a testing chunk which compiles 'calc' grammar with
|
|
||||||
# BISON-DIRECTIVES, and performs several tests over the parser.
|
|
||||||
# Run the test with and without %define parse.error verbose.
|
|
||||||
m4_define([AT_CHECK_JAVA_CALC],
|
|
||||||
[_AT_CHECK_JAVA_CALC([$1], [$2])
|
|
||||||
_AT_CHECK_JAVA_CALC([%define parse.error verbose $1], [$2])
|
|
||||||
_AT_CHECK_JAVA_CALC([%locations $1], [$2])
|
|
||||||
_AT_CHECK_JAVA_CALC([%define parse.error verbose %locations $1], [$2])
|
|
||||||
])# AT_CHECK_JAVA_CALC
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------ #
|
|
||||||
# Simple LALR Calculator. #
|
|
||||||
# ------------------------ #
|
|
||||||
|
|
||||||
AT_CHECK_JAVA_CALC([], [[
|
|
||||||
public static void main (String args[]) throws IOException
|
|
||||||
{
|
{
|
||||||
CalcLexer l = new CalcLexer (System.in);
|
return l.line == line && l.token == token;
|
||||||
Calc p = new Calc (l);
|
|
||||||
p.parse ();
|
|
||||||
}
|
}
|
||||||
]])
|
|
||||||
|
|
||||||
AT_CHECK_JAVA_CALC([%lex-param { InputStream is } ], [[
|
public String toString ()
|
||||||
public static void main (String args[]) throws IOException
|
|
||||||
{
|
{
|
||||||
new Calc (System.in).parse ();
|
return Integer.toString (line) + "." + Integer.toString (token);
|
||||||
}
|
}
|
||||||
]])
|
|
||||||
|
public int lineno ()
|
||||||
|
{
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int token ()
|
||||||
|
{
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
}]])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# -----------------#
|
# -----------------#
|
||||||
# Java Directives. #
|
# Java Parameters. #
|
||||||
# -----------------#
|
# -----------------#
|
||||||
|
|
||||||
AT_BANNER([Java Parameters.])
|
AT_BANNER([Java Parameters.])
|
||||||
@@ -746,8 +478,8 @@ AT_CHECK_JAVA_MINIMAL([[
|
|||||||
%define api.position.type {MyPos}
|
%define api.position.type {MyPos}
|
||||||
%code { class MyPos {} }]], [[$$ = $<java.awt.Color>1;]], [[MyPos]])
|
%code { class MyPos {} }]], [[$$ = $<java.awt.Color>1;]], [[MyPos]])
|
||||||
AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore])
|
AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore])
|
||||||
AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore])
|
AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep -w 'Position']], [1], [ignore])
|
||||||
AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])
|
AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep -w 'Location']], [1], [ignore])
|
||||||
|
|
||||||
AT_CHECK_JAVA_MINIMAL_W_LEXER([[
|
AT_CHECK_JAVA_MINIMAL_W_LEXER([[
|
||||||
%define api.value.type {java.awt.Color}
|
%define api.value.type {java.awt.Color}
|
||||||
@@ -758,8 +490,8 @@ AT_CHECK_JAVA_MINIMAL_W_LEXER([[
|
|||||||
[[$$ = $<java.awt.Color>1;]],
|
[[$$ = $<java.awt.Color>1;]],
|
||||||
[[java.awt.Color]], [[MyPos]], [[MyLoc]])
|
[[java.awt.Color]], [[MyPos]], [[MyLoc]])
|
||||||
AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore])
|
AT_CHECK([[grep 'java.awt.Color' YYParser.java]], [0], [ignore])
|
||||||
AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore])
|
AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep -w 'Position']], [1], [ignore])
|
||||||
AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])
|
AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep -w 'Location']], [1], [ignore])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|
||||||
|
|||||||
+2
-632
@@ -36,6 +36,7 @@ m4_define([AT_CHECK_JAVA_GREP],
|
|||||||
[AT_CHECK_UNQUOTED([grep -c '^$2$' $1], [ignore], [m4_default([$3], [1])
|
[AT_CHECK_UNQUOTED([grep -c '^$2$' $1], [ignore], [m4_default([$3], [1])
|
||||||
])])
|
])])
|
||||||
|
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
|
|
||||||
AT_BANNER([[Java Push Parsing Tests]])
|
AT_BANNER([[Java Push Parsing Tests]])
|
||||||
@@ -61,7 +62,7 @@ start: 'a' 'b' 'c' ;
|
|||||||
%%
|
%%
|
||||||
]])
|
]])
|
||||||
|
|
||||||
# Define comon code across to be included in
|
# Define common code across to be included in
|
||||||
# class Main for the trivial parser tests.
|
# class Main for the trivial parser tests.
|
||||||
m4_define([AT_TRIVIAL_COMMON],[[
|
m4_define([AT_TRIVIAL_COMMON],[[
|
||||||
static class YYerror implements YYParser.Lexer
|
static class YYerror implements YYParser.Lexer
|
||||||
@@ -234,634 +235,3 @@ AT_CHECK_JAVA_GREP(
|
|||||||
[[Initial action invoked]],
|
[[Initial action invoked]],
|
||||||
[1])
|
[1])
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|
||||||
# Define a single copy of the Calculator grammar.
|
|
||||||
m4_define([AT_CALC_BODY],[
|
|
||||||
%code imports {
|
|
||||||
import java.io.*;
|
|
||||||
}
|
|
||||||
|
|
||||||
%code {
|
|
||||||
static StringReader
|
|
||||||
getinput(String filename) throws IOException
|
|
||||||
{
|
|
||||||
// Yes, there are better alternatives to StringBuffer. But we
|
|
||||||
// don't really care about performances here, while portability
|
|
||||||
// to older Java matters.
|
|
||||||
StringBuffer buf = new StringBuffer();
|
|
||||||
FileReader file = new FileReader(filename);
|
|
||||||
int c;
|
|
||||||
while (0 < (c = file.read()))
|
|
||||||
buf.append((char)c);
|
|
||||||
file.close();
|
|
||||||
return new StringReader(buf.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Bison Declarations */
|
|
||||||
%token <Integer> NUM "number"
|
|
||||||
%type <Integer> exp
|
|
||||||
|
|
||||||
%nonassoc '=' /* comparison */
|
|
||||||
%left '-' '+'
|
|
||||||
%left '*' '/'
|
|
||||||
%left NEG /* negation--unary minus */
|
|
||||||
%right '^' /* exponentiation */
|
|
||||||
|
|
||||||
/* Grammar follows */
|
|
||||||
%%
|
|
||||||
input:
|
|
||||||
line
|
|
||||||
| input line
|
|
||||||
;
|
|
||||||
|
|
||||||
line:
|
|
||||||
'\n'
|
|
||||||
| exp '\n' { System.out.println("total = "+$[]1); }
|
|
||||||
| error '\n'
|
|
||||||
;
|
|
||||||
|
|
||||||
exp:
|
|
||||||
NUM { $[]$ = $[]1;}
|
|
||||||
| exp '=' exp
|
|
||||||
{
|
|
||||||
if ($[]1.intValue() != $[]3.intValue())
|
|
||||||
yyerror (]AT_LOCATION_IF([[@$,]])[ "calc: error: " + $[]1 + " != " + $[]3);
|
|
||||||
}
|
|
||||||
| exp '+' exp
|
|
||||||
{ $[]$ = new Integer ($[]1.intValue () + $[]3.intValue ()); }
|
|
||||||
| exp '-' exp
|
|
||||||
{ $[]$ = new Integer ($[]1.intValue () - $[]3.intValue ()); }
|
|
||||||
| exp '*' exp
|
|
||||||
{ $[]$ = new Integer ($[]1.intValue () * $[]3.intValue ()); }
|
|
||||||
| exp '/' exp
|
|
||||||
{ $[]$ = new Integer ($[]1.intValue () / $[]3.intValue ()); }
|
|
||||||
| '-' exp %prec NEG
|
|
||||||
{ $[]$ = new Integer (-$[]2.intValue ()); }
|
|
||||||
| exp '^' exp
|
|
||||||
{ $[]$ = new Integer ((int)Math.pow ($[]1.intValue (),
|
|
||||||
$[]3.intValue ())); }
|
|
||||||
| '(' exp ')' { $[]$ = $[]2;}
|
|
||||||
| '(' error ')' { $[]$ = new Integer (1111);}
|
|
||||||
| '!' { $[]$ = new Integer (0); return YYERROR;}
|
|
||||||
| '-' error { $[]$ = new Integer (0); return YYERROR;}
|
|
||||||
;
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## ------------------------------------- ##
|
|
||||||
## Calc parser with api.push-pull both. ##
|
|
||||||
## ------------------------------------- ##
|
|
||||||
|
|
||||||
|
|
||||||
# Test that the states transitioned by the push parser are the
|
|
||||||
# same as for the pull parser. This test is assumed to work
|
|
||||||
# if it produces the same partial trace of stack states as is
|
|
||||||
# produced when using pull parsing. The output is verbose,
|
|
||||||
# but seems essential for verifying push parsing.
|
|
||||||
|
|
||||||
AT_SETUP([Calc parser with api.push-pull both])
|
|
||||||
AT_BISON_OPTION_PUSHDEFS
|
|
||||||
|
|
||||||
# Define the calculator input.
|
|
||||||
# Warning: if you changes the input file
|
|
||||||
# then the locations test file position numbers
|
|
||||||
# may be incorrect and you will have
|
|
||||||
# to modify that file as well.
|
|
||||||
|
|
||||||
AT_DATA([input],
|
|
||||||
[[1 + 2 * 3 = 7
|
|
||||||
1 + 2 * -3 = -5
|
|
||||||
|
|
||||||
-1^2 = -1
|
|
||||||
(-1)^2 = 1
|
|
||||||
|
|
||||||
---1 = -1
|
|
||||||
|
|
||||||
1 - 2 - 3 = -4
|
|
||||||
1 - (2 - 3) = 2
|
|
||||||
|
|
||||||
2^2^3 = 256
|
|
||||||
(2^2)^3 = 64
|
|
||||||
]])
|
|
||||||
|
|
||||||
# Compose pieces to build the actual .y file.
|
|
||||||
AT_DATA([Calc.y],
|
|
||||||
[[/* Infix notation calculator--calc */
|
|
||||||
%language "Java"
|
|
||||||
|
|
||||||
%define api.parser.class {Calc}
|
|
||||||
%define parse.trace
|
|
||||||
|
|
||||||
%code {
|
|
||||||
static class UserLexer implements Calc.Lexer
|
|
||||||
{
|
|
||||||
StreamTokenizer st;
|
|
||||||
StringReader rdr;
|
|
||||||
|
|
||||||
public UserLexer(StringReader reader)
|
|
||||||
{
|
|
||||||
rdr = reader;
|
|
||||||
st = new StreamTokenizer(rdr);
|
|
||||||
st.resetSyntax();
|
|
||||||
st.eolIsSignificant(true);
|
|
||||||
st.whitespaceChars('\t', '\t');
|
|
||||||
st.whitespaceChars(' ', ' ');
|
|
||||||
st.wordChars('0', '9');
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer yylval;
|
|
||||||
|
|
||||||
public Object getLVal() { return yylval; }
|
|
||||||
|
|
||||||
public void yyerror(String msg) { System.err.println(msg); }
|
|
||||||
|
|
||||||
public int yylex () throws IOException
|
|
||||||
{
|
|
||||||
switch (st.nextToken()) {
|
|
||||||
case StreamTokenizer.TT_EOF: return EOF;
|
|
||||||
case StreamTokenizer.TT_EOL: return (int) '\n';
|
|
||||||
case StreamTokenizer.TT_WORD:
|
|
||||||
yylval = new Integer (st.sval);
|
|
||||||
return NUM;
|
|
||||||
default: return st.ttype;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
%code {
|
|
||||||
public static void main (String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
StringReader reader = getinput(args[0]);
|
|
||||||
UserLexer lexer = new UserLexer(reader);
|
|
||||||
Calc calc = new Calc(lexer);
|
|
||||||
calc.setDebugLevel(1);
|
|
||||||
calc.parse();
|
|
||||||
}//main
|
|
||||||
}
|
|
||||||
|
|
||||||
]AT_CALC_BODY[
|
|
||||||
|
|
||||||
]])
|
|
||||||
|
|
||||||
# This data was captured from running a pull parser.
|
|
||||||
AT_DATA([[expout]],[[Stack now 0
|
|
||||||
Stack now 0 2
|
|
||||||
Stack now 0 9
|
|
||||||
Stack now 0 9 19
|
|
||||||
Stack now 0 9 19 2
|
|
||||||
Stack now 0 9 19 28
|
|
||||||
Stack now 0 9 19 28 20
|
|
||||||
Stack now 0 9 19 28 20 2
|
|
||||||
Stack now 0 9 19 28 20 29
|
|
||||||
Stack now 0 9 19 28
|
|
||||||
Stack now 0 9
|
|
||||||
Stack now 0 9 17
|
|
||||||
Stack now 0 9 17 2
|
|
||||||
Stack now 0 9 17 26
|
|
||||||
Stack now 0 9
|
|
||||||
Stack now 0 9 23
|
|
||||||
Stack now 0 8
|
|
||||||
Stack now 0 7
|
|
||||||
Stack now 0 7 2
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 19
|
|
||||||
Stack now 0 7 9 19 2
|
|
||||||
Stack now 0 7 9 19 28
|
|
||||||
Stack now 0 7 9 19 28 20
|
|
||||||
Stack now 0 7 9 19 28 20 3
|
|
||||||
Stack now 0 7 9 19 28 20 3 2
|
|
||||||
Stack now 0 7 9 19 28 20 3 12
|
|
||||||
Stack now 0 7 9 19 28 20 29
|
|
||||||
Stack now 0 7 9 19 28
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 17
|
|
||||||
Stack now 0 7 9 17 3
|
|
||||||
Stack now 0 7 9 17 3 2
|
|
||||||
Stack now 0 7 9 17 3 12
|
|
||||||
Stack now 0 7 9 17 26
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 23
|
|
||||||
Stack now 0 7 16
|
|
||||||
Stack now 0 7
|
|
||||||
Stack now 0 7 4
|
|
||||||
Stack now 0 7 16
|
|
||||||
Stack now 0 7
|
|
||||||
Stack now 0 7 3
|
|
||||||
Stack now 0 7 3 2
|
|
||||||
Stack now 0 7 3 12
|
|
||||||
Stack now 0 7 3 12 22
|
|
||||||
Stack now 0 7 3 12 22 2
|
|
||||||
Stack now 0 7 3 12 22 31
|
|
||||||
Stack now 0 7 3 12
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 17
|
|
||||||
Stack now 0 7 9 17 3
|
|
||||||
Stack now 0 7 9 17 3 2
|
|
||||||
Stack now 0 7 9 17 3 12
|
|
||||||
Stack now 0 7 9 17 26
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 23
|
|
||||||
Stack now 0 7 16
|
|
||||||
Stack now 0 7
|
|
||||||
Stack now 0 7 5
|
|
||||||
Stack now 0 7 5 3
|
|
||||||
Stack now 0 7 5 3 2
|
|
||||||
Stack now 0 7 5 3 12
|
|
||||||
Stack now 0 7 5 14
|
|
||||||
Stack now 0 7 5 14 25
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 22
|
|
||||||
Stack now 0 7 9 22 2
|
|
||||||
Stack now 0 7 9 22 31
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 17
|
|
||||||
Stack now 0 7 9 17 2
|
|
||||||
Stack now 0 7 9 17 26
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 23
|
|
||||||
Stack now 0 7 16
|
|
||||||
Stack now 0 7
|
|
||||||
Stack now 0 7 4
|
|
||||||
Stack now 0 7 16
|
|
||||||
Stack now 0 7
|
|
||||||
Stack now 0 7 3
|
|
||||||
Stack now 0 7 3 3
|
|
||||||
Stack now 0 7 3 3 3
|
|
||||||
Stack now 0 7 3 3 3 2
|
|
||||||
Stack now 0 7 3 3 3 12
|
|
||||||
Stack now 0 7 3 3 12
|
|
||||||
Stack now 0 7 3 12
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 17
|
|
||||||
Stack now 0 7 9 17 3
|
|
||||||
Stack now 0 7 9 17 3 2
|
|
||||||
Stack now 0 7 9 17 3 12
|
|
||||||
Stack now 0 7 9 17 26
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 23
|
|
||||||
Stack now 0 7 16
|
|
||||||
Stack now 0 7
|
|
||||||
Stack now 0 7 4
|
|
||||||
Stack now 0 7 16
|
|
||||||
Stack now 0 7
|
|
||||||
Stack now 0 7 2
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 18
|
|
||||||
Stack now 0 7 9 18 2
|
|
||||||
Stack now 0 7 9 18 27
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 18
|
|
||||||
Stack now 0 7 9 18 2
|
|
||||||
Stack now 0 7 9 18 27
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 17
|
|
||||||
Stack now 0 7 9 17 3
|
|
||||||
Stack now 0 7 9 17 3 2
|
|
||||||
Stack now 0 7 9 17 3 12
|
|
||||||
Stack now 0 7 9 17 26
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 23
|
|
||||||
Stack now 0 7 16
|
|
||||||
Stack now 0 7
|
|
||||||
Stack now 0 7 2
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 18
|
|
||||||
Stack now 0 7 9 18 5
|
|
||||||
Stack now 0 7 9 18 5 2
|
|
||||||
Stack now 0 7 9 18 5 14
|
|
||||||
Stack now 0 7 9 18 5 14 18
|
|
||||||
Stack now 0 7 9 18 5 14 18 2
|
|
||||||
Stack now 0 7 9 18 5 14 18 27
|
|
||||||
Stack now 0 7 9 18 5 14
|
|
||||||
Stack now 0 7 9 18 5 14 25
|
|
||||||
Stack now 0 7 9 18 27
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 17
|
|
||||||
Stack now 0 7 9 17 2
|
|
||||||
Stack now 0 7 9 17 26
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 23
|
|
||||||
Stack now 0 7 16
|
|
||||||
Stack now 0 7
|
|
||||||
Stack now 0 7 4
|
|
||||||
Stack now 0 7 16
|
|
||||||
Stack now 0 7
|
|
||||||
Stack now 0 7 2
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 22
|
|
||||||
Stack now 0 7 9 22 2
|
|
||||||
Stack now 0 7 9 22 31
|
|
||||||
Stack now 0 7 9 22 31 22
|
|
||||||
Stack now 0 7 9 22 31 22 2
|
|
||||||
Stack now 0 7 9 22 31 22 31
|
|
||||||
Stack now 0 7 9 22 31
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 17
|
|
||||||
Stack now 0 7 9 17 2
|
|
||||||
Stack now 0 7 9 17 26
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 23
|
|
||||||
Stack now 0 7 16
|
|
||||||
Stack now 0 7
|
|
||||||
Stack now 0 7 5
|
|
||||||
Stack now 0 7 5 2
|
|
||||||
Stack now 0 7 5 14
|
|
||||||
Stack now 0 7 5 14 22
|
|
||||||
Stack now 0 7 5 14 22 2
|
|
||||||
Stack now 0 7 5 14 22 31
|
|
||||||
Stack now 0 7 5 14
|
|
||||||
Stack now 0 7 5 14 25
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 22
|
|
||||||
Stack now 0 7 9 22 2
|
|
||||||
Stack now 0 7 9 22 31
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 17
|
|
||||||
Stack now 0 7 9 17 2
|
|
||||||
Stack now 0 7 9 17 26
|
|
||||||
Stack now 0 7 9
|
|
||||||
Stack now 0 7 9 23
|
|
||||||
Stack now 0 7 16
|
|
||||||
Stack now 0 7
|
|
||||||
Stack now 0 7 15
|
|
||||||
]])
|
|
||||||
|
|
||||||
AT_BISON_CHECK([PUSHPULLFLAG [-o Calc.java Calc.y]])
|
|
||||||
|
|
||||||
AT_JAVA_COMPILE([[Calc.java]])
|
|
||||||
# Verify that this is a push parser.
|
|
||||||
AT_CHECK_JAVA_GREP([[Calc.java]],
|
|
||||||
[[.*public void push_parse_initialize().*]])
|
|
||||||
# Capture stderr output for comparison purposes.
|
|
||||||
AT_JAVA_PARSER_CHECK([Calc input], 0, [ignore-nolog], [stderr-nolog])
|
|
||||||
# Extract the "Stack Now" lines from the error output,
|
|
||||||
# send them to stdout (via the sed command) and compare to expout.
|
|
||||||
# NOTE: because the target is "expout", this macro automatically
|
|
||||||
# compares the output of the sed command with the contents of
|
|
||||||
# the file "expout" (defined above).
|
|
||||||
AT_CHECK([[sed -e '/^Stack now.*$/p' -e d ./stderr]],
|
|
||||||
[ignore], [expout], [ignore-nolog])
|
|
||||||
AT_BISON_OPTION_POPDEFS
|
|
||||||
AT_CLEANUP
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## ---------------------------------------------------------------- ##
|
|
||||||
## Calc parser with %locations %code lexer and api.push-pull both. ##
|
|
||||||
## ---------------------------------------------------------------- ##
|
|
||||||
|
|
||||||
|
|
||||||
# This test looks for location reporting by looking
|
|
||||||
# at the lexer output with locations enabled.
|
|
||||||
# It defines a lexer that reports location info.
|
|
||||||
AT_SETUP([Calc parser with %locations %code lexer and api.push-pull both])
|
|
||||||
AT_BISON_OPTION_PUSHDEFS
|
|
||||||
|
|
||||||
AT_DATA([Calc.y],
|
|
||||||
[[/* Infix notation calculator--calc. */
|
|
||||||
%language "Java"
|
|
||||||
|
|
||||||
%define api.parser.class {Calc}
|
|
||||||
%define parse.trace
|
|
||||||
%lex-param { Reader rdr }
|
|
||||||
%locations
|
|
||||||
|
|
||||||
%code imports {
|
|
||||||
import java.io.*;
|
|
||||||
}
|
|
||||||
|
|
||||||
%code lexer {
|
|
||||||
StreamTokenizer st;
|
|
||||||
Integer yylval;
|
|
||||||
|
|
||||||
public YYLexer(Reader rdr)
|
|
||||||
{
|
|
||||||
st = new StreamTokenizer(rdr);
|
|
||||||
st.resetSyntax();
|
|
||||||
st.eolIsSignificant(true);
|
|
||||||
st.whitespaceChars('\t', '\t');
|
|
||||||
st.whitespaceChars(' ', ' ');
|
|
||||||
st.wordChars('0', '9');
|
|
||||||
}
|
|
||||||
|
|
||||||
Position yypos = new Position (1, 0);
|
|
||||||
|
|
||||||
public Position getStartPos() { return yypos; }
|
|
||||||
|
|
||||||
public Position getEndPos() { return yypos; }
|
|
||||||
|
|
||||||
public Object getLVal() { return yylval; }
|
|
||||||
|
|
||||||
public void yyerror(Location loc, String msg)
|
|
||||||
{
|
|
||||||
System.err.println(loc+":"+msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int yylex () throws IOException
|
|
||||||
{
|
|
||||||
yypos = new Position (yypos.lineno (),yypos.token () + 1);
|
|
||||||
switch (st.nextToken()) {
|
|
||||||
case StreamTokenizer.TT_EOF:
|
|
||||||
return EOF;
|
|
||||||
case StreamTokenizer.TT_EOL:
|
|
||||||
yypos = new Position (yypos.lineno () + 1, 0);
|
|
||||||
return (int) '\n';
|
|
||||||
case StreamTokenizer.TT_WORD:
|
|
||||||
yylval = new Integer (st.sval);
|
|
||||||
return NUM;
|
|
||||||
default:
|
|
||||||
return st.ttype;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
%code { ]AT_JAVA_POSITION_DEFINE[ }
|
|
||||||
|
|
||||||
%code {
|
|
||||||
public static void main (String[] args)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
StringReader reader = getinput(args[0]);
|
|
||||||
Calc calc = new Calc(reader);
|
|
||||||
calc.setDebugLevel(1);
|
|
||||||
calc.parse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
]AT_CALC_BODY[
|
|
||||||
|
|
||||||
]])
|
|
||||||
|
|
||||||
# Define the expected calculator output.
|
|
||||||
# This should match the output from a pull parser.
|
|
||||||
AT_DATA([output],[[total = 7
|
|
||||||
total = -5
|
|
||||||
total = -1
|
|
||||||
total = 1
|
|
||||||
total = -1
|
|
||||||
total = -4
|
|
||||||
total = 2
|
|
||||||
total = 256
|
|
||||||
total = 64
|
|
||||||
]])
|
|
||||||
|
|
||||||
AT_DATA([locations],[[Next token is token "number" (1.1: 1)
|
|
||||||
Next token is token '+' (1.2: 1)
|
|
||||||
Next token is token "number" (1.3: 2)
|
|
||||||
Next token is token '*' (1.4: 2)
|
|
||||||
Next token is token "number" (1.5: 3)
|
|
||||||
Next token is token '=' (1.6: 3)
|
|
||||||
Next token is token '=' (1.6: 3)
|
|
||||||
Next token is token '=' (1.6: 3)
|
|
||||||
Next token is token "number" (1.7: 7)
|
|
||||||
Next token is token '\n' (2.0: 7)
|
|
||||||
Next token is token '\n' (2.0: 7)
|
|
||||||
Next token is token "number" (2.1: 1)
|
|
||||||
Next token is token '+' (2.2: 1)
|
|
||||||
Next token is token "number" (2.3: 2)
|
|
||||||
Next token is token '*' (2.4: 2)
|
|
||||||
Next token is token '-' (2.5: 2)
|
|
||||||
Next token is token "number" (2.6: 3)
|
|
||||||
Next token is token '=' (2.7: 3)
|
|
||||||
Next token is token '=' (2.7: 3)
|
|
||||||
Next token is token '=' (2.7: 3)
|
|
||||||
Next token is token '=' (2.7: 3)
|
|
||||||
Next token is token '-' (2.8: 3)
|
|
||||||
Next token is token "number" (2.9: 5)
|
|
||||||
Next token is token '\n' (3.0: 5)
|
|
||||||
Next token is token '\n' (3.0: 5)
|
|
||||||
Next token is token '\n' (3.0: 5)
|
|
||||||
Next token is token '\n' (4.0: 5)
|
|
||||||
Next token is token '-' (4.1: 5)
|
|
||||||
Next token is token "number" (4.2: 1)
|
|
||||||
Next token is token '^' (4.3: 1)
|
|
||||||
Next token is token "number" (4.4: 2)
|
|
||||||
Next token is token '=' (4.5: 2)
|
|
||||||
Next token is token '=' (4.5: 2)
|
|
||||||
Next token is token '=' (4.5: 2)
|
|
||||||
Next token is token '-' (4.6: 2)
|
|
||||||
Next token is token "number" (4.7: 1)
|
|
||||||
Next token is token '\n' (5.0: 1)
|
|
||||||
Next token is token '\n' (5.0: 1)
|
|
||||||
Next token is token '\n' (5.0: 1)
|
|
||||||
Next token is token '(' (5.1: 1)
|
|
||||||
Next token is token '-' (5.2: 1)
|
|
||||||
Next token is token "number" (5.3: 1)
|
|
||||||
Next token is token ')' (5.4: 1)
|
|
||||||
Next token is token ')' (5.4: 1)
|
|
||||||
Next token is token '^' (5.5: 1)
|
|
||||||
Next token is token "number" (5.6: 2)
|
|
||||||
Next token is token '=' (5.7: 2)
|
|
||||||
Next token is token '=' (5.7: 2)
|
|
||||||
Next token is token "number" (5.8: 1)
|
|
||||||
Next token is token '\n' (6.0: 1)
|
|
||||||
Next token is token '\n' (6.0: 1)
|
|
||||||
Next token is token '\n' (7.0: 1)
|
|
||||||
Next token is token '-' (7.1: 1)
|
|
||||||
Next token is token '-' (7.2: 1)
|
|
||||||
Next token is token '-' (7.3: 1)
|
|
||||||
Next token is token "number" (7.4: 1)
|
|
||||||
Next token is token '=' (7.5: 1)
|
|
||||||
Next token is token '=' (7.5: 1)
|
|
||||||
Next token is token '=' (7.5: 1)
|
|
||||||
Next token is token '=' (7.5: 1)
|
|
||||||
Next token is token '-' (7.6: 1)
|
|
||||||
Next token is token "number" (7.7: 1)
|
|
||||||
Next token is token '\n' (8.0: 1)
|
|
||||||
Next token is token '\n' (8.0: 1)
|
|
||||||
Next token is token '\n' (8.0: 1)
|
|
||||||
Next token is token '\n' (9.0: 1)
|
|
||||||
Next token is token "number" (9.1: 1)
|
|
||||||
Next token is token '-' (9.2: 1)
|
|
||||||
Next token is token "number" (9.3: 2)
|
|
||||||
Next token is token '-' (9.4: 2)
|
|
||||||
Next token is token '-' (9.4: 2)
|
|
||||||
Next token is token "number" (9.5: 3)
|
|
||||||
Next token is token '=' (9.6: 3)
|
|
||||||
Next token is token '=' (9.6: 3)
|
|
||||||
Next token is token '-' (9.7: 3)
|
|
||||||
Next token is token "number" (9.8: 4)
|
|
||||||
Next token is token '\n' (10.0: 4)
|
|
||||||
Next token is token '\n' (10.0: 4)
|
|
||||||
Next token is token '\n' (10.0: 4)
|
|
||||||
Next token is token "number" (10.1: 1)
|
|
||||||
Next token is token '-' (10.2: 1)
|
|
||||||
Next token is token '(' (10.3: 1)
|
|
||||||
Next token is token "number" (10.4: 2)
|
|
||||||
Next token is token '-' (10.5: 2)
|
|
||||||
Next token is token "number" (10.6: 3)
|
|
||||||
Next token is token ')' (10.7: 3)
|
|
||||||
Next token is token ')' (10.7: 3)
|
|
||||||
Next token is token '=' (10.8: 3)
|
|
||||||
Next token is token '=' (10.8: 3)
|
|
||||||
Next token is token "number" (10.9: 2)
|
|
||||||
Next token is token '\n' (11.0: 2)
|
|
||||||
Next token is token '\n' (11.0: 2)
|
|
||||||
Next token is token '\n' (12.0: 2)
|
|
||||||
Next token is token "number" (12.1: 2)
|
|
||||||
Next token is token '^' (12.2: 2)
|
|
||||||
Next token is token "number" (12.3: 2)
|
|
||||||
Next token is token '^' (12.4: 2)
|
|
||||||
Next token is token "number" (12.5: 3)
|
|
||||||
Next token is token '=' (12.6: 3)
|
|
||||||
Next token is token '=' (12.6: 3)
|
|
||||||
Next token is token '=' (12.6: 3)
|
|
||||||
Next token is token "number" (12.7: 256)
|
|
||||||
Next token is token '\n' (13.0: 256)
|
|
||||||
Next token is token '\n' (13.0: 256)
|
|
||||||
Next token is token '(' (13.1: 256)
|
|
||||||
Next token is token "number" (13.2: 2)
|
|
||||||
Next token is token '^' (13.3: 2)
|
|
||||||
Next token is token "number" (13.4: 2)
|
|
||||||
Next token is token ')' (13.5: 2)
|
|
||||||
Next token is token ')' (13.5: 2)
|
|
||||||
Next token is token '^' (13.6: 2)
|
|
||||||
Next token is token "number" (13.7: 3)
|
|
||||||
Next token is token '=' (13.8: 3)
|
|
||||||
Next token is token '=' (13.8: 3)
|
|
||||||
Next token is token "number" (13.9: 64)
|
|
||||||
Next token is token '\n' (14.0: 64)
|
|
||||||
Next token is token '\n' (14.0: 64)
|
|
||||||
Next token is token $end (14.1: 64)
|
|
||||||
]])
|
|
||||||
|
|
||||||
# Define the calculator input.
|
|
||||||
# Warning: if you changes the input file
|
|
||||||
# then the locations test file position numbers
|
|
||||||
# may be incorrect and you will have
|
|
||||||
# to modify that file as well.
|
|
||||||
|
|
||||||
AT_DATA([input],
|
|
||||||
[[1 + 2 * 3 = 7
|
|
||||||
1 + 2 * -3 = -5
|
|
||||||
|
|
||||||
-1^2 = -1
|
|
||||||
(-1)^2 = 1
|
|
||||||
|
|
||||||
---1 = -1
|
|
||||||
|
|
||||||
1 - 2 - 3 = -4
|
|
||||||
1 - (2 - 3) = 2
|
|
||||||
|
|
||||||
2^2^3 = 256
|
|
||||||
(2^2)^3 = 64
|
|
||||||
]])
|
|
||||||
|
|
||||||
AT_BISON_CHECK([PUSHPULLFLAG [-o Calc.java Calc.y]])
|
|
||||||
AT_JAVA_COMPILE([[Calc.java]])
|
|
||||||
# Verify that this is a push parser
|
|
||||||
AT_CHECK_JAVA_GREP([[Calc.java]],
|
|
||||||
[[.*public void push_parse_initialize().*]])
|
|
||||||
# Capture the stdout and stderr output for comparison purposes.
|
|
||||||
AT_JAVA_PARSER_CHECK([Calc input], 0, [stdout-nolog], [stderr-nolog])
|
|
||||||
# 1. Check that the token locations are correct
|
|
||||||
AT_CHECK([[cp -f ./locations ./expout]],[ignore],[ignore-nolog],[ignore-nolog])
|
|
||||||
AT_CHECK([[sed -e '/^Next token.*$/p' -e d ./stderr]],[ignore],[expout],[ignore-nolog])
|
|
||||||
# 2. Check that the calculator output matches that of a pull parser
|
|
||||||
AT_CHECK([[rm -f ./expout; cp -f ./output ./expout]],[ignore],[ignore-nolog],[ignore-nolog])
|
|
||||||
AT_CHECK([[cat ./stdout]],[ignore],[expout],[ignore-nolog])
|
|
||||||
AT_CLEANUP
|
|
||||||
|
|||||||
+238
-40
@@ -30,6 +30,18 @@ m4_define([m4_null_if],
|
|||||||
[$3])])
|
[$3])])
|
||||||
|
|
||||||
|
|
||||||
|
# m4_rpatsubst(STRING, PATTERN, REPLACEMENT)
|
||||||
|
# ------------------------------------------
|
||||||
|
# As long as PATTERN matches STRING, replace occurrences of PATTERN by
|
||||||
|
# REPLACEMENT.
|
||||||
|
#
|
||||||
|
# Contrary to m4_bpatsubst, matches PATTERN from previous replacements.
|
||||||
|
m4_define([m4_rpatsubst],
|
||||||
|
[m4_if(m4_bregexp([$1], [$2]),
|
||||||
|
[-1], [$1],
|
||||||
|
[m4_rpatsubst(m4_quote(m4_bpatsubst([$1], [$2], [$3])), [$2], [$3])])])
|
||||||
|
|
||||||
|
|
||||||
# AT_SETUP_STRIP(TITLE)
|
# AT_SETUP_STRIP(TITLE)
|
||||||
# ---------------------
|
# ---------------------
|
||||||
# Abbreviate the TITLE to be passed to AT_SETUP. Remove new-lines
|
# Abbreviate the TITLE to be passed to AT_SETUP. Remove new-lines
|
||||||
@@ -191,7 +203,15 @@ m4_pushdef([AT_AUTOMOVE_IF],
|
|||||||
m4_pushdef([AT_DEFINES_IF],
|
m4_pushdef([AT_DEFINES_IF],
|
||||||
[m4_bmatch([$3], [%defines], [$1], [$2])])
|
[m4_bmatch([$3], [%defines], [$1], [$2])])
|
||||||
m4_pushdef([AT_DEBUG_IF],
|
m4_pushdef([AT_DEBUG_IF],
|
||||||
[m4_bmatch([$3], [%debug\|%define parse.trace], [$1], [$2])])
|
[m4_bmatch([$3], [%debug\|%define parse.trace], [$1], [$2])])
|
||||||
|
m4_pushdef([AT_ERROR_CUSTOM_IF],
|
||||||
|
[m4_bmatch([$3], [%define parse\.error custom], [$1], [$2])])
|
||||||
|
m4_pushdef([AT_ERROR_DETAILED_IF],
|
||||||
|
[m4_bmatch([$3], [%define parse\.error detailed], [$1], [$2])])
|
||||||
|
m4_pushdef([AT_ERROR_VERBOSE_IF],
|
||||||
|
[m4_bmatch([$3], [%define parse\.error verbose], [$1], [$2])])
|
||||||
|
m4_pushdef([AT_ERROR_SIMPLE_IF],
|
||||||
|
[AT_ERROR_CUSTOM_IF([$2], [AT_ERROR_DETAILED_IF([$2], [AT_ERROR_VERBOSE_IF([$2], [$1])], [$1])], [$1])])
|
||||||
m4_pushdef([AT_CXX_IF],
|
m4_pushdef([AT_CXX_IF],
|
||||||
[m4_bmatch([$3], [%language "[Cc]\+\+"\|%skeleton "[a-z0-9]+\.cc"], [$1], [$2])])
|
[m4_bmatch([$3], [%language "[Cc]\+\+"\|%skeleton "[a-z0-9]+\.cc"], [$1], [$2])])
|
||||||
m4_pushdef([AT_D_IF],
|
m4_pushdef([AT_D_IF],
|
||||||
@@ -215,6 +235,8 @@ m4_pushdef([AT_GLR_CC_IF],
|
|||||||
# Using yacc.c?
|
# Using yacc.c?
|
||||||
m4_pushdef([AT_YACC_IF],
|
m4_pushdef([AT_YACC_IF],
|
||||||
[m4_bmatch([$3], [%language\|%glr-parser\|%skeleton], [$2], [$1])])
|
[m4_bmatch([$3], [%language\|%glr-parser\|%skeleton], [$2], [$1])])
|
||||||
|
m4_pushdef([AT_LAC_IF],
|
||||||
|
[m4_bmatch([$3], [%define parse.lac full], [$1], [$2])])
|
||||||
m4_pushdef([AT_LEXPARAM_IF],
|
m4_pushdef([AT_LEXPARAM_IF],
|
||||||
[m4_bmatch([$3], [%lex-param], [$1], [$2])])
|
[m4_bmatch([$3], [%lex-param], [$1], [$2])])
|
||||||
m4_pushdef([AT_LOCATION_IF],
|
m4_pushdef([AT_LOCATION_IF],
|
||||||
@@ -226,12 +248,22 @@ m4_pushdef([AT_LOCATION_TYPE_SPAN_IF],
|
|||||||
[m4_bmatch([$3], [%define \(api\.location\.type\|location_type\) \{Span\}], [$1], [$2])])
|
[m4_bmatch([$3], [%define \(api\.location\.type\|location_type\) \{Span\}], [$1], [$2])])
|
||||||
m4_pushdef([AT_PARAM_IF],
|
m4_pushdef([AT_PARAM_IF],
|
||||||
[m4_bmatch([$3], [%parse-param], [$1], [$2])])
|
[m4_bmatch([$3], [%parse-param], [$1], [$2])])
|
||||||
|
|
||||||
# Comma-terminated list of formals parse-parameters.
|
# Comma-terminated list of formals parse-parameters.
|
||||||
# E.g., %parse-param { int x } %parse-param {int y} -> "int x, int y, ".
|
# E.g., %parse-param { int x } %parse-param {int y} -> "int x, int y, ".
|
||||||
# FIXME: Support grouped parse-param.
|
m4_bpatsubst([$3], [%parse-param { *\([^{}]*[^{} ]\) *}{ *\([^{}]*[^{} ]\) *}{ *\([^{}]*[^{} ]\) *}],
|
||||||
m4_pushdef([AT_PARSE_PARAMS])
|
[m4_append([AT_PARSE_PARAMS], [\1, \2, \3], [, ])])
|
||||||
m4_bpatsubst([$3], [%parse-param { *\([^{}]*[^{} ]\) *}],
|
m4_bpatsubst([$3], [%parse-param { *\([^{}]*[^{} ]\) *}{ *\([^{}]*[^{} ]\) *}\([^{].*\)?$],
|
||||||
[m4_append([AT_PARSE_PARAMS], [\1, ])])
|
[m4_append([AT_PARSE_PARAMS], [\1, \2], [, ])])
|
||||||
|
m4_rpatsubst([$3], [%parse-param { *\([^{}]*[^{} ]\) *}\([^{}].*\)?$],
|
||||||
|
[m4_append([AT_PARSE_PARAMS], [\1], [, ])\2])
|
||||||
|
m4_ifndef([AT_PARSE_PARAMS],
|
||||||
|
[m4_define([AT_PARSE_PARAMS])])
|
||||||
|
|
||||||
|
m4_pushdef([AT_PARSER_CLASS],
|
||||||
|
[m4_bmatch([$3], [%define *api\.parser\.class {\([^\}]*\)}],
|
||||||
|
[m4_bregexp([$3], [%define *api\.parser\.class {\([^\}]*\)}], [\1])],
|
||||||
|
[AT_API_PREFIX[]Parser])])
|
||||||
|
|
||||||
m4_pushdef([AT_PURE_IF],
|
m4_pushdef([AT_PURE_IF],
|
||||||
[m4_bmatch([$3], [%define *api\.pure\|%pure-parser],
|
[m4_bmatch([$3], [%define *api\.pure\|%pure-parser],
|
||||||
@@ -379,11 +411,13 @@ m4_popdef([AT_NAMESPACE])
|
|||||||
m4_popdef([AT_NAME_PREFIX])
|
m4_popdef([AT_NAME_PREFIX])
|
||||||
m4_popdef([AT_LOCATION_TYPE_SPAN_IF])
|
m4_popdef([AT_LOCATION_TYPE_SPAN_IF])
|
||||||
m4_popdef([AT_LOCATION_IF])
|
m4_popdef([AT_LOCATION_IF])
|
||||||
m4_popdef([AT_PARSE_PARAMS])
|
m4_undefine([AT_PARSE_PARAMS])
|
||||||
m4_popdef([AT_PUSH_IF])
|
m4_popdef([AT_PUSH_IF])
|
||||||
m4_popdef([AT_PURE_IF])
|
m4_popdef([AT_PURE_IF])
|
||||||
|
m4_popdef([AT_PARSER_CLASS])
|
||||||
m4_popdef([AT_PARAM_IF])
|
m4_popdef([AT_PARAM_IF])
|
||||||
m4_popdef([AT_LEXPARAM_IF])
|
m4_popdef([AT_LEXPARAM_IF])
|
||||||
|
m4_popdef([AT_LAC_IF])
|
||||||
m4_popdef([AT_YACC_IF])
|
m4_popdef([AT_YACC_IF])
|
||||||
m4_popdef([AT_GLR_IF])
|
m4_popdef([AT_GLR_IF])
|
||||||
m4_popdef([AT_CXX_IF])
|
m4_popdef([AT_CXX_IF])
|
||||||
@@ -392,8 +426,13 @@ m4_popdef([AT_LANG])
|
|||||||
m4_popdef([AT_JAVA_IF])
|
m4_popdef([AT_JAVA_IF])
|
||||||
m4_popdef([AT_GLR_CC_IF])
|
m4_popdef([AT_GLR_CC_IF])
|
||||||
m4_popdef([AT_LALR1_CC_IF])
|
m4_popdef([AT_LALR1_CC_IF])
|
||||||
m4_popdef([AT_DEFINES_IF])
|
m4_popdef([AT_ERROR_SIMPLE_IF])
|
||||||
|
m4_popdef([AT_ERROR_VERBOSE_IF])
|
||||||
|
m4_popdef([AT_ERROR_DETAILED_IF])
|
||||||
|
m4_popdef([AT_ERROR_CUSTOM_IF])
|
||||||
m4_popdef([AT_DEBUG_IF])
|
m4_popdef([AT_DEBUG_IF])
|
||||||
|
m4_popdef([AT_DEFINES_IF])
|
||||||
|
m4_popdef([AT_AUTOMOVE_IF])
|
||||||
AT_LOC_POPDEF])dnl
|
AT_LOC_POPDEF])dnl
|
||||||
])# AT_BISON_OPTION_POPDEFS
|
])# AT_BISON_OPTION_POPDEFS
|
||||||
|
|
||||||
@@ -409,6 +448,12 @@ m4_define([AT_LANG_CASE],
|
|||||||
[m4_case(AT_LANG, $@)])
|
[m4_case(AT_LANG, $@)])
|
||||||
|
|
||||||
|
|
||||||
|
# AT_LANG_MATCH(LANG1, IF-LANG1, LANG2, IF-LANG2, ..., DEFAULT)
|
||||||
|
# ------------------------------------------------------------
|
||||||
|
m4_define([AT_LANG_MATCH],
|
||||||
|
[m4_bmatch(AT_LANG, $@)])
|
||||||
|
|
||||||
|
|
||||||
# _AT_LANG_DISPATCH(LANG, MACRO, ARGS)
|
# _AT_LANG_DISPATCH(LANG, MACRO, ARGS)
|
||||||
# ------------------------------------
|
# ------------------------------------
|
||||||
# Call the specialization of MACRO for LANG with ARGS. Complain if
|
# Call the specialization of MACRO for LANG with ARGS. Complain if
|
||||||
@@ -474,7 +519,7 @@ m4_define([AT_DATA_GRAMMAR], [AT_LANG_DISPATCH([$0], $@)])
|
|||||||
# AT_YYLEX_DEFINE([INPUT], [ACTION])
|
# AT_YYLEX_DEFINE([INPUT], [ACTION])
|
||||||
# ----------------------------------
|
# ----------------------------------
|
||||||
# INPUT can be empty, or in double quotes, or a list (in braces).
|
# INPUT can be empty, or in double quotes, or a list (in braces).
|
||||||
# ACTION may compute yylval for instance, using "res" as token type,
|
# ACTION may compute yylval for instance, using "res" as token kind,
|
||||||
# and "toknum" as the number of calls to yylex (starting at 0).
|
# and "toknum" as the number of calls to yylex (starting at 0).
|
||||||
m4_define([AT_YYLEX_PROTOTYPE],
|
m4_define([AT_YYLEX_PROTOTYPE],
|
||||||
[AT_YYLEX_RETURN AT_NAME_PREFIX[]lex (]AT_YYLEX_FORMALS[)[]dnl
|
[AT_YYLEX_RETURN AT_NAME_PREFIX[]lex (]AT_YYLEX_FORMALS[)[]dnl
|
||||||
@@ -526,7 +571,7 @@ $2])
|
|||||||
])
|
])
|
||||||
|
|
||||||
m4_define([AT_YYERROR_FORMALS(c)],
|
m4_define([AT_YYERROR_FORMALS(c)],
|
||||||
[AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE const * const llocp, ])AT_PARSE_PARAMS[const char *msg]])
|
[AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE const * const llocp, ])AT_PARAM_IF([AT_PARSE_PARAMS, ])[const char *msg]])
|
||||||
|
|
||||||
m4_define([AT_YYERROR_PROTOTYPE(c)],
|
m4_define([AT_YYERROR_PROTOTYPE(c)],
|
||||||
[[void ]AT_NAME_PREFIX[error (]AT_YYERROR_FORMALS[)]])
|
[[void ]AT_NAME_PREFIX[error (]AT_YYERROR_FORMALS[)]])
|
||||||
@@ -535,7 +580,7 @@ m4_define([AT_YYERROR_DECLARE_EXTERN(c)],
|
|||||||
[AT_YYERROR_PROTOTYPE;])
|
[AT_YYERROR_PROTOTYPE;])
|
||||||
|
|
||||||
m4_define([AT_YYERROR_DECLARE(c)],
|
m4_define([AT_YYERROR_DECLARE(c)],
|
||||||
[#include <stdio.h>
|
[[#include <stdio.h>
|
||||||
]AT_LOCATION_IF([[
|
]AT_LOCATION_IF([[
|
||||||
#if defined ]AT_YYLTYPE[_IS_TRIVIAL && ]AT_YYLTYPE[_IS_TRIVIAL
|
#if defined ]AT_YYLTYPE[_IS_TRIVIAL && ]AT_YYLTYPE[_IS_TRIVIAL
|
||||||
static int location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp);
|
static int location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp);
|
||||||
@@ -544,12 +589,13 @@ static int location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp);
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
]])[
|
]])[
|
||||||
static AT_YYERROR_DECLARE_EXTERN])
|
static ]AT_YYERROR_DECLARE_EXTERN])
|
||||||
|
|
||||||
|
|
||||||
|
# "%define parse.error custom" uses a different format, easy to check.
|
||||||
|
# The "verbose" one can be computed from it (see _AT_CHECK_CALC_ERROR).
|
||||||
m4_define([AT_YYERROR_DEFINE(c)],
|
m4_define([AT_YYERROR_DEFINE(c)],
|
||||||
[[
|
[AT_LOCATION_IF([[
|
||||||
]AT_LOCATION_IF([[
|
|
||||||
# if defined ]AT_YYLTYPE[_IS_TRIVIAL && ]AT_YYLTYPE[_IS_TRIVIAL
|
# if defined ]AT_YYLTYPE[_IS_TRIVIAL && ]AT_YYLTYPE[_IS_TRIVIAL
|
||||||
/* Print *YYLOCP on YYO. */
|
/* Print *YYLOCP on YYO. */
|
||||||
__attribute__((__unused__))
|
__attribute__((__unused__))
|
||||||
@@ -579,17 +625,57 @@ location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
]])[
|
]])[
|
||||||
|
|
||||||
|
]AT_ERROR_CUSTOM_IF([[
|
||||||
|
int
|
||||||
|
yyreport_syntax_error (const yypcontext_t *ctx]AT_PARAM_IF([, AT_PARSE_PARAMS])[)
|
||||||
|
{
|
||||||
|
int res = 0;]AT_PARAM_IF([m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
|
||||||
|
[[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\),* *], [
|
||||||
|
YYUSE (\1);])])[]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs],[[
|
||||||
|
++global_nerrs;
|
||||||
|
++*nerrs;]])[]AT_LOCATION_IF([[
|
||||||
|
LOCATION_PRINT (stderr, *yypcontext_location (ctx));
|
||||||
|
fprintf (stderr, ": ");]])[
|
||||||
|
fprintf (stderr, "syntax error");
|
||||||
|
{
|
||||||
|
yysymbol_kind_t la = yypcontext_token (ctx);
|
||||||
|
if (la != YYSYMBOL_YYEMPTY)
|
||||||
|
fprintf (stderr, " on token [%s]", yysymbol_name (la));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
enum { TOKENMAX = 10 };
|
||||||
|
yysymbol_kind_t expected[TOKENMAX];
|
||||||
|
int n = yypcontext_expected_tokens (ctx, expected, TOKENMAX);
|
||||||
|
/* Forward errors to yyparse. */
|
||||||
|
if (n <= 0)
|
||||||
|
res = n;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf (stderr, " (expected:");
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
fprintf (stderr, " [%s]", yysymbol_name (expected[i]));
|
||||||
|
fprintf (stderr, ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
]])[
|
||||||
|
|
||||||
/* A C error reporting function. */
|
/* A C error reporting function. */
|
||||||
static
|
static
|
||||||
]AT_YYERROR_PROTOTYPE[
|
]AT_YYERROR_PROTOTYPE[
|
||||||
{]m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
|
{]m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
|
||||||
[[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\), *], [
|
[[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\),* *], [
|
||||||
YYUSE(\1);])dnl
|
YYUSE (\1);])dnl
|
||||||
AT_YYERROR_SEES_LOC_IF([[
|
AT_YYERROR_SEES_LOC_IF([[
|
||||||
LOCATION_PRINT (stderr, ]AT_LOC[);
|
LOCATION_PRINT (stderr, ]AT_LOC[);
|
||||||
fprintf (stderr, ": ");]])[
|
fprintf (stderr, ": ");]])[
|
||||||
fprintf (stderr, "%s\n", msg);
|
fprintf (stderr, "%s\n", msg);]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs],[[
|
||||||
}]])
|
++global_nerrs;
|
||||||
|
++*nerrs;]])[
|
||||||
|
}]])])
|
||||||
|
|
||||||
|
|
||||||
m4_define([AT_YYLEX_DEFINE(c)],
|
m4_define([AT_YYLEX_DEFINE(c)],
|
||||||
@@ -654,13 +740,43 @@ m4_define([AT_YYERROR_DEFINE(c++)],
|
|||||||
[[/* A C++ error reporting function. */
|
[[/* A C++ error reporting function. */
|
||||||
void
|
void
|
||||||
]AT_NAMESPACE[::parser::error (]AT_LOCATION_IF([[const location_type& l, ]])[const std::string& m)
|
]AT_NAMESPACE[::parser::error (]AT_LOCATION_IF([[const location_type& l, ]])[const std::string& m)
|
||||||
{
|
{]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs],[[
|
||||||
|
++global_nerrs;
|
||||||
|
++*nerrs;]])[
|
||||||
std::cerr << ]AT_LOCATION_IF([l << ": " << ])[m << '\n';
|
std::cerr << ]AT_LOCATION_IF([l << ": " << ])[m << '\n';
|
||||||
}]])
|
}]AT_ERROR_CUSTOM_IF([[
|
||||||
|
void
|
||||||
|
]AT_NAMESPACE[::parser::report_syntax_error (const context& ctx) const
|
||||||
|
{]AT_PARAM_IF([m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
|
||||||
|
[[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\),* *], [
|
||||||
|
YYUSE (\1);])])[]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs],[[
|
||||||
|
++global_nerrs;
|
||||||
|
++*nerrs;]])[]AT_LOCATION_IF([[
|
||||||
|
std::cerr << ctx.location () << ": ";]])[
|
||||||
|
std::cerr << "syntax error";
|
||||||
|
{
|
||||||
|
symbol_kind_type la = ctx.token ();
|
||||||
|
if (la != symbol_kind::S_YYEMPTY)
|
||||||
|
std::cerr << " on token [" << symbol_name (la) << ']';
|
||||||
|
}
|
||||||
|
{
|
||||||
|
enum { TOKENMAX = 10 };
|
||||||
|
symbol_kind_type expected[TOKENMAX];
|
||||||
|
int n = ctx.expected_tokens (expected, TOKENMAX);
|
||||||
|
if (0 < n)
|
||||||
|
{
|
||||||
|
std::cerr << " (expected:";
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
std::cerr << " [" << symbol_name (expected[i]) << ']';
|
||||||
|
std::cerr << ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cerr << '\n';
|
||||||
|
}]])])
|
||||||
|
|
||||||
|
|
||||||
# AT_YYERROR_DEFINE(c++)([INPUT], [ACTION])
|
# AT_YYLEX_DEFINE(c++)([INPUT], [ACTION])
|
||||||
# -----------------------------------------
|
# ---------------------------------------
|
||||||
# Same as in C.
|
# Same as in C.
|
||||||
m4_copy([AT_YYLEX_DEFINE(c)], [AT_YYLEX_DEFINE(c++)])
|
m4_copy([AT_YYLEX_DEFINE(c)], [AT_YYLEX_DEFINE(c++)])
|
||||||
|
|
||||||
@@ -747,61 +863,139 @@ m4_define([AT_MAIN_DEFINE(d)],
|
|||||||
# ------------------------------
|
# ------------------------------
|
||||||
m4_copy([AT_DATA], [AT_DATA_GRAMMAR(java)])
|
m4_copy([AT_DATA], [AT_DATA_GRAMMAR(java)])
|
||||||
|
|
||||||
|
# No need to declare, it's part of the class interface.
|
||||||
|
m4_define([AT_YYERROR_DECLARE(java)], [])
|
||||||
|
m4_define([AT_YYERROR_DECLARE_EXTERN(java)], [])
|
||||||
|
|
||||||
# AT_JAVA_POSITION_DEFINE
|
# AT_JAVA_POSITION_DEFINE
|
||||||
# -----------------------
|
# -----------------------
|
||||||
m4_define([AT_JAVA_POSITION_DEFINE],
|
m4_define([AT_JAVA_POSITION_DEFINE],
|
||||||
[[class Position {
|
[[class Position {
|
||||||
public int line;
|
public int line = 1;
|
||||||
public int token;
|
public int column = 1;
|
||||||
|
|
||||||
public Position ()
|
public Position ()
|
||||||
{
|
{
|
||||||
line = 0;
|
line = 1;
|
||||||
token = 0;
|
column = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Position (int l, int t)
|
public Position (int l, int t)
|
||||||
{
|
{
|
||||||
line = l;
|
line = l;
|
||||||
token = t;
|
column = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Position (Position p)
|
||||||
|
{
|
||||||
|
line = p.line;
|
||||||
|
column = p.column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set (Position p)
|
||||||
|
{
|
||||||
|
line = p.line;
|
||||||
|
column = p.column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals (Position l)
|
public boolean equals (Position l)
|
||||||
{
|
{
|
||||||
return l.line == line && l.token == token;
|
return l.line == line && l.column == column;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString ()
|
public String toString ()
|
||||||
{
|
{
|
||||||
return Integer.toString (line) + "." + Integer.toString(token);
|
return Integer.toString (line) + "." + Integer.toString (column);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int lineno ()
|
public int line ()
|
||||||
{
|
{
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int token ()
|
public int column ()
|
||||||
{
|
{
|
||||||
return token;
|
return column;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PositionReader extends BufferedReader {
|
||||||
|
|
||||||
|
private Position position = new Position ();
|
||||||
|
private Position previousPosition = new Position ();
|
||||||
|
|
||||||
|
public PositionReader (Reader reader) {
|
||||||
|
super (reader);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int read () throws IOException {
|
||||||
|
int res = super.read ();
|
||||||
|
previousPosition.set (position);
|
||||||
|
if (res > -1) {
|
||||||
|
char c = (char)res;
|
||||||
|
if (c == '\r' || c == '\n') {
|
||||||
|
position.line += 1;
|
||||||
|
position.column = 1;
|
||||||
|
} else {
|
||||||
|
position.column += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Position getPosition () {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Position getPreviousPosition () {
|
||||||
|
return previousPosition;
|
||||||
}
|
}
|
||||||
}]])
|
}]])
|
||||||
|
|
||||||
|
|
||||||
|
# AT_YYERROR_DEFINE(java)
|
||||||
|
# -----------------------
|
||||||
|
# FIXME: We should not hard-code "Calc".
|
||||||
m4_define([AT_YYERROR_DEFINE(java)],
|
m4_define([AT_YYERROR_DEFINE(java)],
|
||||||
[AT_LOCATION_IF([[public void yyerror (Calc.Location l, String m)
|
[AT_LOCATION_IF([[public void yyerror (Calc.Location l, String m)
|
||||||
{
|
{]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs], [[
|
||||||
if (l == null)
|
++global_nerrs;
|
||||||
System.err.println (m);
|
++*nerrs;]])[
|
||||||
else
|
if (l == null)
|
||||||
System.err.println (l + ": " + m);
|
System.err.println(m);
|
||||||
|
else
|
||||||
|
System.err.println(l + ": " + m);
|
||||||
}
|
}
|
||||||
]], [[
|
]], [[
|
||||||
public void yyerror (String m)
|
public void yyerror (String m)
|
||||||
{
|
{]m4_bmatch(m4_defn([AT_PARSE_PARAMS]), [nerrs],[[
|
||||||
|
++global_nerrs;
|
||||||
|
++*nerrs;]])[
|
||||||
System.err.println (m);
|
System.err.println (m);
|
||||||
}
|
}
|
||||||
|
]])[
|
||||||
|
|
||||||
|
]AT_ERROR_CUSTOM_IF([[
|
||||||
|
public void reportSyntaxError(Calc.Context ctx) {
|
||||||
|
System.err.print(]AT_LOCATION_IF([[ctx.getLocation() + ": "
|
||||||
|
+ ]])["syntax error");
|
||||||
|
{
|
||||||
|
Calc.SymbolKind token = ctx.getToken();
|
||||||
|
if (token != null)
|
||||||
|
System.err.print(" on token @<:@" + token.getName() + "@:>@");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
Calc.SymbolKind[] arg = new Calc.SymbolKind[ctx.NTOKENS];
|
||||||
|
int n = ctx.getExpectedTokens(arg, ctx.NTOKENS);
|
||||||
|
if (0 < n) {
|
||||||
|
System.err.print(" (expected:");
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
System.err.print(" @<:@" + arg[i].getName() + "@:>@");
|
||||||
|
System.err.print(")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.err.println("");
|
||||||
|
}
|
||||||
]])
|
]])
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -829,16 +1023,20 @@ m4_define([AT_YYLEX_DEFINE(java)],
|
|||||||
m4_define([AT_MAIN_DEFINE(java)],
|
m4_define([AT_MAIN_DEFINE(java)],
|
||||||
[[class input
|
[[class input
|
||||||
{
|
{
|
||||||
public static void main (String args[]) throws IOException
|
public static void main (String[] args) throws IOException
|
||||||
{
|
{
|
||||||
]AT_API_prefix[Parser p = new ]AT_API_prefix[Parser ();
|
]AT_API_prefix[Parser p = new ]AT_API_prefix[Parser ();
|
||||||
System.exit (p.parse () ? 0 : 1);
|
boolean success = p.parse ();
|
||||||
|
if (!success)
|
||||||
|
System.exit (1);
|
||||||
}
|
}
|
||||||
}]])
|
}]])
|
||||||
|
|
||||||
m4_define([AT_LANG_FOR_EACH_STD(java)],
|
m4_define([AT_LANG_FOR_EACH_STD(java)],
|
||||||
[$1])
|
[$1])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## --------------- ##
|
## --------------- ##
|
||||||
## Running Bison. ##
|
## Running Bison. ##
|
||||||
## --------------- ##
|
## --------------- ##
|
||||||
@@ -974,7 +1172,7 @@ m4_define([AT_BISON_CHECK_XML],
|
|||||||
# AT_SET_ENV_IF(EXIT-STATUS)
|
# AT_SET_ENV_IF(EXIT-STATUS)
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Put this before a Bison invocation to set the environment to:
|
# Put this before a Bison invocation to set the environment to:
|
||||||
# - define COLUMNS to make the test suite independant of the user's
|
# - define COLUMNS to make the test suite independent of the user's
|
||||||
# environment;
|
# environment;
|
||||||
# - keep Valgrind from complaining about reachable memory (when
|
# - keep Valgrind from complaining about reachable memory (when
|
||||||
# EXIT-STATUS is not 0).
|
# EXIT-STATUS is not 0).
|
||||||
|
|||||||
+4
-4
@@ -96,10 +96,10 @@ clean-local-tests:
|
|||||||
|
|
||||||
.PHONY: recheck
|
.PHONY: recheck
|
||||||
recheck: $(RUN_TESTSUITE_deps)
|
recheck: $(RUN_TESTSUITE_deps)
|
||||||
$(RUN_TESTSUITE) \
|
$(RUN_TESTSUITE) \
|
||||||
$$(perl -n \
|
$$(perl -n \
|
||||||
-e 'if (/Summary of the failures/../Detailed failed tests/)' \
|
-e 'eof && /^(\d+).*: FAILED/ && print "$$1 "' \
|
||||||
-e '{ /^ *[0-9]+:/ && s/:.*//s && print }' %D%/testsuite.log)
|
%D%/testsuite.dir/*/testsuite.log)
|
||||||
|
|
||||||
check-local: $(RUN_TESTSUITE_deps)
|
check-local: $(RUN_TESTSUITE_deps)
|
||||||
$(RUN_TESTSUITE)
|
$(RUN_TESTSUITE)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user