mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-08-09 10:45:15 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fb8b11152 | ||
|
|
2a1aefbf76 | ||
|
|
734b0ce45d | ||
|
|
59bcaebfae | ||
|
|
680b715518 | ||
|
|
2eb1ad9ef3 | ||
|
|
0360a35228 | ||
|
|
2e053317c8 | ||
|
|
33c788d37b | ||
|
|
c03d0d9625 | ||
|
|
bf7abf4849 | ||
|
|
2731332150 | ||
|
|
554a12102e | ||
|
|
b590ad0292 | ||
|
|
05e70adf22 | ||
|
|
7efe0b5da3 | ||
|
|
351e3630bb | ||
|
|
4fd1fc70e0 | ||
|
|
e02ce4c7f0 | ||
|
|
7cab285eda | ||
|
|
86efe28222 | ||
|
|
cf1446dc9e | ||
|
|
e93c40b33d | ||
|
|
eff6739124 | ||
|
|
5a0d7802f4 | ||
|
|
f1e0839c9e | ||
|
|
3bf429aed8 | ||
|
|
f8cadc731b | ||
|
|
bd7aebb8b0 | ||
|
|
ca8039e612 | ||
|
|
5d07f4f726 | ||
|
|
e605ad9679 | ||
|
|
50fac71d46 | ||
|
|
a8455b072a | ||
|
|
a9d6e16e0a | ||
|
|
bd0cf11e00 | ||
|
|
c8512e09e7 | ||
|
|
96f503e197 | ||
|
|
9912dd28ca | ||
|
|
22aaad0c45 | ||
|
|
a45ed4ecc1 | ||
|
|
fef272bdf3 | ||
|
|
d1f57a4ae5 | ||
|
|
5d5f12fb0d | ||
|
|
9f6013a0fd | ||
|
|
fad0f9231b | ||
|
|
81df326649 | ||
|
|
01c5b6ab0f | ||
|
|
c45f86d286 | ||
|
|
1664d1c5ed | ||
|
|
71758d854a | ||
|
|
3751d50e70 | ||
|
|
3f5e6905da | ||
|
|
719782e6ba | ||
|
|
ee175dfd00 | ||
|
|
f3110c9b9a | ||
|
|
18743948b5 | ||
|
|
849d91bc02 | ||
|
|
73a822e636 | ||
|
|
5b879c8980 | ||
|
|
8fd5f0d5a5 | ||
|
|
a4dce889a4 | ||
|
|
7c4b40de61 | ||
|
|
f9bba892bd | ||
|
|
facfd9c406 | ||
|
|
0308dfb039 | ||
|
|
9d8fc7fd3e | ||
|
|
b5515215c1 | ||
|
|
ab3dc5415c | ||
|
|
06f3245fa4 | ||
|
|
05d702422a | ||
|
|
121da2cbdb | ||
|
|
7a45fc35bf | ||
|
|
ae1e65a285 | ||
|
|
ba9db64745 | ||
|
|
b4b8666e4a | ||
|
|
0021bc3e28 | ||
|
|
4b0efdeb28 | ||
|
|
73917e9e6f | ||
|
|
ba29791773 | ||
|
|
a7842d1bc0 | ||
|
|
81a9580622 | ||
|
|
85f7c08036 | ||
|
|
098f5084a0 | ||
|
|
07a4b32f4d | ||
|
|
3ead69b1c1 | ||
|
|
42f0b949ec | ||
|
|
e7b709ab0b | ||
|
|
35068fbe66 | ||
|
|
16d34d8036 | ||
|
|
bfbd73f3e0 | ||
|
|
602f8e2a77 | ||
|
|
ace93397c1 | ||
|
|
d2192653db | ||
|
|
83a832618d | ||
|
|
0e0d7d2975 | ||
|
|
5abbc66fe4 | ||
|
|
bf338b7cd2 | ||
|
|
3967e46a2d | ||
|
|
b994c3bf78 | ||
|
|
03a13ce793 | ||
|
|
f5fc21240f |
+1
-1
@@ -1 +1 @@
|
||||
3.1
|
||||
3.2.1
|
||||
|
||||
+64
-40
@@ -12,9 +12,70 @@ env:
|
||||
|
||||
matrix:
|
||||
include:
|
||||
## ------- ##
|
||||
## First. ##
|
||||
## ------- ##
|
||||
|
||||
# Start with three completely different environments, to get
|
||||
# errors asap.
|
||||
|
||||
- name: "GCC 7 -O3"
|
||||
os: linux
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-7
|
||||
env:
|
||||
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7 && CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'"
|
||||
|
||||
# ASAN is time consuming, and we timeout the 50min granted by
|
||||
# Travis if we run all the tests in on go. Run in two parts.
|
||||
- name: "Clang 7 libc++ and ASAN part 1"
|
||||
os: linux
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- llvm-toolchain-trusty-7
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- clang-7
|
||||
- libc++-7-dev
|
||||
- libc++abi-7-dev
|
||||
env:
|
||||
# Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379
|
||||
- MATRIX_EVAL="PART=1 CC='clang-7 -fsanitize=address' CXX='clang++-7 -fsanitize=address -stdlib=libc++'"
|
||||
|
||||
- name: "Clang 7 libc++ and ASAN part 2"
|
||||
os: linux
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- llvm-toolchain-trusty-7
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- clang-7
|
||||
- libc++-7-dev
|
||||
- libc++abi-7-dev
|
||||
env:
|
||||
# Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379
|
||||
- MATRIX_EVAL="PART=2 CC='clang-7 -fsanitize=address' CXX='clang++-7 -fsanitize=address -stdlib=libc++'"
|
||||
|
||||
- name: "ICC"
|
||||
os: linux
|
||||
env:
|
||||
# ICC's warnings are often very wrong (e.g., it thinks foo ?
|
||||
# "bar" : "baz" is char* instead of const char*), so don't try
|
||||
# to work around the, and obviously, don't die on them.
|
||||
- MATRIX_EVAL="CC=icc && CXX=icpc"
|
||||
- MAKE_ARGS='WERROR_CFLAGS= WERROR_CXXFLAGS='
|
||||
|
||||
|
||||
## ----- ##
|
||||
## GCC. ##
|
||||
## ----- ##
|
||||
|
||||
#- name: "GCC 8 with sanitizers"
|
||||
# os: linux
|
||||
# addons:
|
||||
@@ -29,17 +90,6 @@ matrix:
|
||||
# # /usr/bin/ld: unrecognized option '--push-state'
|
||||
# - MATRIX_EVAL="CC='gcc-8 -fsanitize=undefined,address -fno-omit-frame-pointer' CXX='g++-8 -fsanitize=undefined,address -fno-omit-frame-pointer'"
|
||||
|
||||
- name: "GCC 7 -O3"
|
||||
os: linux
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-7
|
||||
env:
|
||||
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7 && CONFIGUREFLAGS='CPPFLAGS=-DNDEBUG CFLAGS=-O3 CXXFLAGS=-O3'"
|
||||
|
||||
- name: "GCC 6"
|
||||
os: linux
|
||||
addons:
|
||||
@@ -110,21 +160,6 @@ matrix:
|
||||
## Clang. ##
|
||||
## ------- ##
|
||||
|
||||
- name: "Clang 7 libc++ and ASAN"
|
||||
os: linux
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- llvm-toolchain-trusty-7
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- clang-7
|
||||
- libc++-7-dev
|
||||
- libc++abi-7-dev
|
||||
env:
|
||||
# Do not use ASAN with ubuntu's libc++: https://bugs.llvm.org/show_bug.cgi?id=17379
|
||||
- MATRIX_EVAL="CC='clang-7 -fsanitize=address' CXX='clang++-7 -fsanitize=address -stdlib=libc++'"
|
||||
|
||||
- name: "Clang 6 -O3 and libc++"
|
||||
os: linux
|
||||
addons:
|
||||
@@ -242,17 +277,6 @@ matrix:
|
||||
# See comment for 3.4.
|
||||
- MATRIX_EVAL='CC=/usr/bin/clang && CXX=/usr/bin/clang++'
|
||||
|
||||
## ----- ##
|
||||
## ICC. ##
|
||||
## ----- ##
|
||||
- name: "ICC"
|
||||
os: linux
|
||||
env:
|
||||
# ICC's warnings are often very wrong (e.g., it thinks foo ?
|
||||
# "bar" : "baz" is char* instead of const char*), so don't try
|
||||
# to work around the, and obviously, don't die on them.
|
||||
- MATRIX_EVAL="CC=icc && CXX=icpc"
|
||||
- MAKE_ARGS='WERROR_CFLAGS= WERROR_CXXFLAGS='
|
||||
|
||||
before_install:
|
||||
- eval "$MATRIX_EVAL"
|
||||
@@ -285,9 +309,9 @@ script:
|
||||
- if [[ -f ~/.bashrc ]]; then source ~/.bashrc; fi
|
||||
- ./configure --enable-gcc-warnings CC="$CC" CXX="$CXX" $CONFIGUREFLAGS || { cat config.log && false; }
|
||||
- make -j2 $MAKE_ARGS
|
||||
- make check VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat tests/testsuite.log && false; }
|
||||
- make maintainer-check-posix VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat tests/testsuite.log && false; }
|
||||
- make maintainer-check-g++ VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat tests/testsuite.log && false; }
|
||||
- if test ${PART-1} = 1; then make check VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat tests/testsuite.log && false; }; fi
|
||||
- if test ${PART-1} = 1; then make maintainer-check-posix VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat tests/testsuite.log && false; }; fi
|
||||
- if test ${PART-2} = 2; then make maintainer-check-g++ VERBOSE=1 TESTSUITEFLAGS=-j2 || { cat tests/testsuite.log && false; }; fi
|
||||
|
||||
after_script:
|
||||
- if [[ $CC == "icc" ]]; then uninstall_intel_software; fi
|
||||
|
||||
@@ -1,12 +1,41 @@
|
||||
GNU Bison NEWS
|
||||
|
||||
* Noteworthy changes in release 3.1.90 (2018-10-17) [beta]
|
||||
* Noteworthy changes in release 3.2.2 (2018-11-21) [stable]
|
||||
|
||||
** Bug fixes
|
||||
|
||||
C++ portability issues.
|
||||
|
||||
* Noteworthy changes in release 3.2.1 (2018-11-09) [stable]
|
||||
|
||||
** Bug fixes
|
||||
|
||||
Several portability issues have been fixed in the build system, in the
|
||||
test suite, and in the generated parsers in C++.
|
||||
|
||||
* Noteworthy changes in release 3.2 (2018-10-29) [stable]
|
||||
|
||||
** Backward incompatible changes
|
||||
|
||||
Support for DJGPP, which have been unmaintained and untested for years, is
|
||||
obsolete. Unless there is activity to revive it, it will be removed.
|
||||
|
||||
** Changes
|
||||
|
||||
%printers should use yyo rather than yyoutput to denote the output stream.
|
||||
|
||||
Variant-based symbols in C++ should use emplace() rather than build().
|
||||
|
||||
In C++ parsers, parser::operator() is now a synonym for the parser::parse.
|
||||
|
||||
** Documentation
|
||||
|
||||
A new section, "A Simple C++ Example", is a tutorial for parsers in C++.
|
||||
|
||||
A comment in the generated code now emphasizes that users should not
|
||||
depend upon non-documented implementation details, such as macros starting
|
||||
with YY_.
|
||||
|
||||
** New features
|
||||
|
||||
*** C++: Support for move semantics (lalr1.cc)
|
||||
@@ -66,7 +95,7 @@ GNU Bison NEWS
|
||||
Enabling api.value.automove does not require support for modern C++. The
|
||||
generated code is valid C++98/03, but will use copies instead of moves.
|
||||
|
||||
The new examples/variant-11.yy shows these features in action.
|
||||
The new examples/c++/variant-11.yy shows these features in action.
|
||||
|
||||
*** C++: The implicit default semantic action is always run
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ Bison requires GNU m4 1.4.6 or later. See:
|
||||
https://ftp.gnu.org/gnu/m4/m4-1.4.6.tar.gz
|
||||
|
||||
** Internationalization
|
||||
Bison supports two catalogues: one for Bison itself (i.e., for the
|
||||
Bison supports two catalogs: one for Bison itself (i.e., for the
|
||||
maintainer-side parser generation), and one for the generated parsers
|
||||
(i.e., for the user-side parser execution). The requirements between
|
||||
both differ: bison needs ngettext, the generated parsers do not. To
|
||||
@@ -29,9 +29,9 @@ If you have questions about using Bison and the documentation does
|
||||
not answer them, please send mail to <[email protected]>.
|
||||
|
||||
* Bug reports
|
||||
Please send bug reports to <[email protected]>. Please include the
|
||||
version number from 'bison --version', and a complete, self-contained
|
||||
test case in each bug report.
|
||||
Please send bug reports to <[email protected]>. Be sure to include the
|
||||
version number from 'bison --version', and a complete, self-contained test
|
||||
case in each bug report.
|
||||
|
||||
* Copyright statements
|
||||
For any copyright year range specified as YYYY-ZZZZ in this package,
|
||||
@@ -42,6 +42,7 @@ note that the range specifies every single year in that closed interval.
|
||||
Local Variables:
|
||||
mode: outline
|
||||
fill-column: 76
|
||||
ispell-dictionary: "american"
|
||||
End:
|
||||
|
||||
Copyright (C) 1992, 1998-1999, 2003-2005, 2008-2015, 2018 Free Software
|
||||
@@ -61,3 +62,6 @@ 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/>.
|
||||
|
||||
# LocalWords: parsers ngettext Texinfo pdf html YYYY ZZZZ ispell american
|
||||
# LocalWords: MERCHANTABILITY
|
||||
|
||||
@@ -3,11 +3,13 @@ it is today without the invaluable help of these people:
|
||||
|
||||
Aaro Koskinen [email protected]
|
||||
Аскар Сафин [email protected]
|
||||
Adam Sampson [email protected]
|
||||
Airy Andre [email protected]
|
||||
Akim Demaille [email protected]
|
||||
Albert Chin-A-Young [email protected]
|
||||
Alexander Belopolsky [email protected]
|
||||
Alexandre Duret-Lutz [email protected]
|
||||
Andre da Costa Barros [email protected]
|
||||
Andreas Schwab [email protected]
|
||||
Andrew Suffield [email protected]
|
||||
Angelo Borsotti [email protected]
|
||||
@@ -42,6 +44,7 @@ David J. MacKenzie [email protected]
|
||||
David Kastrup [email protected]
|
||||
David Michael [email protected]
|
||||
Dengke Du [email protected]
|
||||
Denis Excoffier [email protected]
|
||||
Dennis Clarke [email protected]
|
||||
Derek Clegg [email protected]
|
||||
Derek M. Jones [email protected]
|
||||
@@ -67,6 +70,7 @@ Goran Uddeborg [email protected]
|
||||
Guido Trentalancia [email protected]
|
||||
H. Merijn Brand [email protected]
|
||||
Hans Åberg [email protected]
|
||||
Horst Von Brand [email protected]
|
||||
Jan Nieuwenhuizen [email protected]
|
||||
Jannick [email protected]
|
||||
Jerry Quinn [email protected]
|
||||
@@ -83,6 +87,7 @@ Juan Manuel Guerrero [email protected]
|
||||
Kees Zeelenberg [email protected]
|
||||
Keith Browne [email protected]
|
||||
Ken Moffat [email protected]
|
||||
Kiyoshi Kanazawa [email protected]
|
||||
Laurent Mascherpa [email protected]
|
||||
Lie Yan [email protected]
|
||||
Magnus Fromreide [email protected]
|
||||
@@ -103,6 +108,7 @@ Michel d'Hooge [email protected]
|
||||
Michiel De Wilde [email protected]
|
||||
Mickael Labau [email protected]
|
||||
Mike Castle [email protected]
|
||||
Mike Frysinger [email protected]
|
||||
Mike Sullivan [email protected]
|
||||
Nate Guerin [email protected]
|
||||
Neil Booth [email protected]
|
||||
@@ -145,6 +151,7 @@ Roland Levillain [email protected]
|
||||
Satya Kiran Popuri [email protected]
|
||||
Sebastian Setzer [email protected]
|
||||
Sebastien Fricker [email protected]
|
||||
Sébastien Villemot [email protected]
|
||||
Sergei Steshenko [email protected]
|
||||
Shura [email protected]
|
||||
Simon Sobisch [email protected]
|
||||
|
||||
@@ -1,4 +1,20 @@
|
||||
* Short term
|
||||
** yacc.c
|
||||
Now that ylwrap is fixed, we should include foo.tab.h from foo.tab.c rather
|
||||
than duplicating it.
|
||||
|
||||
** C++
|
||||
Move to int everywhere instead of unsigned? stack_size, etc. The parser
|
||||
itself uses int (for yylen for instance), yet stack is based on size_t.
|
||||
|
||||
Maybe locations should also move to ints.
|
||||
|
||||
** C
|
||||
Introduce state_type rather than spreading yytype_int16 everywhere?
|
||||
|
||||
** glr.c
|
||||
yyspaceLeft should probably be a pointer diff.
|
||||
|
||||
** Graphviz display code thoughts
|
||||
The code for the --graph option is over two files: print_graph, and
|
||||
graphviz. This is because Bison used to also produce VCG graphs, but since
|
||||
@@ -204,10 +220,17 @@ 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
|
||||
This is a popular demand. We already made many changes in the parser that
|
||||
should make this reasonably easy to implement.
|
||||
|
||||
Bruce Mardle <[email protected]>
|
||||
https://lists.gnu.org/archive/html/bison-patches/2015-09/msg00000.html
|
||||
|
||||
** Push parsers
|
||||
There is demand for push parsers in Java and C++. And GLR I guess.
|
||||
|
||||
|
||||
+14
-14
@@ -1,17 +1,17 @@
|
||||
# Copyright (C) 2000-2015, 2018 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/>.
|
||||
## Copyright (C) 2000-2015, 2018 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/>.
|
||||
|
||||
EXTRA_DIST += \
|
||||
build-aux/Darwin.valgrind \
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
# Customize maint.mk -*- makefile -*-
|
||||
# Copyright (C) 2008-2015, 2018 Free Software Foundation, Inc.
|
||||
## Customize maint.mk -*- makefile -*-
|
||||
## Copyright (C) 2008-2015, 2018 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 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.
|
||||
## 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/>.
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Update version, then recompile so that tests/bison --version be
|
||||
# up-to-date, then compile our parser again with our up-to-date bison.
|
||||
@@ -163,12 +163,9 @@ $(call exclude,
|
||||
preprocessor_indentation=^data/|^lib/|^src/parse-gram.[ch]$$ \
|
||||
program_name=^lib/main.c$$ \
|
||||
prohibit_always-defined_macros=^data/yacc.c$$|^djgpp/ \
|
||||
prohibit_always-defined_macros+=?|^lib/timevar.c$$ \
|
||||
prohibit_always-defined_macros+=?|^src/(parse-gram.c|system.h)$$ \
|
||||
prohibit_always-defined_macros+=?|^tests/regression.at$$ \
|
||||
prohibit_always_true_header_tests=^djgpp/subpipe.h$$|^lib/timevar.c$$ \
|
||||
prohibit_always_true_header_tests+=?|^m4/timevar.m4$$ \
|
||||
prohibit_defined_have_decl_tests=?|^lib/timevar.c$$ \
|
||||
prohibit_always_true_header_tests=^djgpp/subpipe.h$$ \
|
||||
prohibit_doubled_word=^tests/named-refs.at$$ \
|
||||
prohibit_magic_number_exit=^doc/bison.texi$$ \
|
||||
prohibit_magic_number_exit+=?|^tests/(conflicts|regression).at$$ \
|
||||
|
||||
+8
-9
@@ -80,6 +80,7 @@ BISON_CXXSTD([14])
|
||||
BISON_CXXSTD([17])
|
||||
BISON_CXXSTD([2a])
|
||||
AM_CONDITIONAL([ENABLE_CXX11], [test x"$CXX11_CXXFLAGS" != x])
|
||||
AM_CONDITIONAL([ENABLE_CXX14], [test x"$CXX14_CXXFLAGS" != x])
|
||||
AC_LANG_POP([C++])
|
||||
|
||||
AC_ARG_ENABLE([gcc-warnings],
|
||||
@@ -107,7 +108,9 @@ if test "$enable_gcc_warnings" = yes; then
|
||||
# -Wno-keyword-macro: We use the "#define private public" dirty
|
||||
# trick in the test suite to check some private implementation
|
||||
# details for lalr1.cc.
|
||||
warn_tests='-Wundef -pedantic -Wdeprecated -Wsign-compare -fno-color-diagnostics
|
||||
warn_tests='-Wundef -pedantic -Wconversion
|
||||
-Wdeprecated -Wsign-compare -Wsign-conversion
|
||||
-fno-color-diagnostics
|
||||
-Wno-keyword-macro'
|
||||
|
||||
AC_LANG_PUSH([C])
|
||||
@@ -137,7 +140,7 @@ if test "$enable_gcc_warnings" = yes; then
|
||||
AS_VAR_APPEND([WARN_CFLAGS], [" $WARN_CFLAGS_TEST"])
|
||||
|
||||
# Warnings for the test suite only.
|
||||
for i in $warn_tests;
|
||||
for i in $warn_tests -Wincompatible-pointer-types;
|
||||
do
|
||||
gl_WARN_ADD([$i], [WARN_CFLAGS_TEST])
|
||||
done
|
||||
@@ -159,15 +162,11 @@ if test "$enable_gcc_warnings" = yes; then
|
||||
do
|
||||
gl_WARN_ADD([$i], [WARN_CXXFLAGS_TEST])
|
||||
done
|
||||
# Clang++ 3.2+ reject C code generated by Flex.
|
||||
gl_WARN_ADD([-Wno-null-conversion], [FLEX_SCANNER_CXXFLAGS])
|
||||
# So does G++ 4.8...
|
||||
gl_WARN_ADD([-Wno-sign-compare], [FLEX_SCANNER_CXXFLAGS])
|
||||
# ... possibly in std=c++11 mode.
|
||||
gl_WARN_ADD([-Wno-zero-as-null-pointer-constant], [FLEX_SCANNER_CXXFLAGS])
|
||||
CXXFLAGS=$save_CXXFLAGS
|
||||
# Too many compilers complain about Flex generated code.
|
||||
gl_WARN_ADD([-Wno-error], [FLEX_SCANNER_CXXFLAGS])
|
||||
# Clang++ deprecates compiling C.
|
||||
gl_WARN_ADD([-Wno-deprecated], [WNO_DEPRECATED_CXXFLAGS])
|
||||
CXXFLAGS=$save_CXXFLAGS
|
||||
AC_LANG_POP([C++])
|
||||
fi
|
||||
|
||||
|
||||
+29
-13
@@ -22,12 +22,17 @@
|
||||
## Identification. ##
|
||||
## ---------------- ##
|
||||
|
||||
# b4_generated_by
|
||||
# ---------------
|
||||
m4_define([b4_generated_by],
|
||||
[b4_comment([A Bison parser, made by GNU Bison b4_version.])
|
||||
])
|
||||
|
||||
# b4_copyright(TITLE, [YEARS])
|
||||
# ----------------------------
|
||||
# If YEARS are not defined, use b4_copyright_years.
|
||||
m4_define([b4_copyright],
|
||||
[b4_comment([A Bison parser, made by GNU Bison b4_version.])
|
||||
|
||||
[b4_generated_by
|
||||
b4_comment([$1
|
||||
|
||||
]m4_dquote(m4_text_wrap([Copyright (C)
|
||||
@@ -58,7 +63,18 @@ Bison output files to be licensed under the GNU General Public
|
||||
License without this special exception.
|
||||
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison.])])
|
||||
version 2.2 of Bison.])
|
||||
])
|
||||
|
||||
|
||||
# b4_disclaimer
|
||||
# -------------
|
||||
# Issue a warning about private implementation details.
|
||||
m4_define([b4_disclaimer],
|
||||
[b4_comment([Undocumented macros, especially those whose name start with YY_,
|
||||
are private implementation details. Do not rely on them.])
|
||||
])
|
||||
|
||||
|
||||
|
||||
# b4_required_version_if(VERSION, IF_NEWER, IF_OLDER)
|
||||
@@ -613,13 +629,15 @@ m4_define([b4_user_code],
|
||||
b4_syncline([@oline@], [@ofile@])])
|
||||
|
||||
|
||||
# b4_define_user_code(MACRO)
|
||||
# --------------------------
|
||||
# From b4_MACRO, build b4_user_MACRO that includes the synclines.
|
||||
# b4_define_user_code(MACRO, COMMENT)
|
||||
# -----------------------------------
|
||||
# From b4_MACRO, if defined, build b4_user_MACRO that includes the synclines.
|
||||
m4_define([b4_define_user_code],
|
||||
[m4_define([b4_user_$1],
|
||||
[b4_user_code([b4_$1])])])
|
||||
|
||||
[m4_ifdef([b4_$1],
|
||||
[m4_ifval([$2],
|
||||
[b4_comment([$2])
|
||||
])b4_user_code([b4_$1])])])])
|
||||
|
||||
# b4_user_actions
|
||||
# b4_user_initial_action
|
||||
@@ -629,9 +647,9 @@ m4_define([b4_define_user_code],
|
||||
# ----------------------
|
||||
# Macros that issue user code, ending with synclines.
|
||||
b4_define_user_code([actions])
|
||||
b4_define_user_code([initial_action])
|
||||
b4_define_user_code([post_prologue])
|
||||
b4_define_user_code([pre_prologue])
|
||||
b4_define_user_code([initial_action], [User initialization code.])
|
||||
b4_define_user_code([post_prologue], [Second part of user prologue.])
|
||||
b4_define_user_code([pre_prologue], [First part of user prologue.])
|
||||
b4_define_user_code([union_members])
|
||||
|
||||
|
||||
@@ -1056,8 +1074,6 @@ b4_check_user_names_wrap([[code]], [[qualifier]])
|
||||
## ---------------- ##
|
||||
|
||||
# m4_define_default([b4_lex_param], []) dnl breaks other skeletons
|
||||
m4_define_default([b4_pre_prologue], [])
|
||||
m4_define_default([b4_post_prologue], [])
|
||||
m4_define_default([b4_epilogue], [])
|
||||
m4_define_default([b4_parse_param], [])
|
||||
|
||||
|
||||
+9
-3
@@ -53,8 +53,14 @@ m4_define([b4_inline],
|
||||
# b4_cxx_portability
|
||||
# ------------------
|
||||
m4_define([b4_cxx_portability],
|
||||
[// Support move semantics when possible.
|
||||
#if defined __cplusplus && 201103L <= __cplusplus
|
||||
[#if defined __cplusplus
|
||||
# define YY_CPLUSPLUS __cplusplus
|
||||
#else
|
||||
# define YY_CPLUSPLUS 199711L
|
||||
#endif
|
||||
|
||||
// Support move semantics when possible.
|
||||
#if 201103L <= YY_CPLUSPLUS
|
||||
# define YY_MOVE std::move
|
||||
# define YY_MOVE_OR_COPY move
|
||||
# define YY_MOVE_REF(Type) Type&&
|
||||
@@ -272,7 +278,7 @@ m4_define([b4_symbol_type_declare],
|
||||
location_type location;])[
|
||||
|
||||
private:
|
||||
#if defined __cplusplus && __cplusplus < 201103L
|
||||
#if YY_CPLUSPLUS < 201103L
|
||||
/// Assignment operator.
|
||||
basic_symbol& operator= (const basic_symbol& other);
|
||||
#endif
|
||||
|
||||
@@ -204,11 +204,12 @@ m4_define([b4_table_value_equals],
|
||||
## Compiler issues. ##
|
||||
## ----------------- ##
|
||||
|
||||
# b4_attribute_define
|
||||
# -------------------
|
||||
# Provide portable compiler "attributes".
|
||||
# b4_attribute_define([noreturn])
|
||||
# -------------------------------
|
||||
# Provide portable compiler "attributes". If "noreturn" is passed, define
|
||||
# _Noreturn.
|
||||
m4_define([b4_attribute_define],
|
||||
[#ifndef YY_ATTRIBUTE
|
||||
[[#ifndef YY_ATTRIBUTE
|
||||
# if (defined __GNUC__ \
|
||||
&& (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
|
||||
|| defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
|
||||
@@ -226,16 +227,23 @@ m4_define([b4_attribute_define],
|
||||
# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
|
||||
#endif
|
||||
|
||||
#if !defined _Noreturn \
|
||||
&& (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
|
||||
# if defined _MSC_VER && 1200 <= _MSC_VER
|
||||
# define _Noreturn __declspec (noreturn)
|
||||
# else
|
||||
# define _Noreturn YY_ATTRIBUTE ((__noreturn__))
|
||||
]m4_bmatch([$1], [\bnoreturn\b], [[/* The _Noreturn keyword of C11. */
|
||||
#if ! defined _Noreturn
|
||||
# if defined __cplusplus && 201103L <= __cplusplus
|
||||
# define _Noreturn [[noreturn]]
|
||||
# elif !(defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__)
|
||||
# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \
|
||||
|| 0x5110 <= __SUNPRO_C)
|
||||
# define _Noreturn __attribute__ ((__noreturn__))
|
||||
# elif defined _MSC_VER && 1200 <= _MSC_VER
|
||||
# define _Noreturn __declspec (noreturn)
|
||||
# else
|
||||
# define _Noreturn
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Suppress unused-variable warnings by "using" E. */
|
||||
]])[/* Suppress unused-variable warnings by "using" E. */
|
||||
#if ! defined lint || defined __GNUC__
|
||||
# define YYUSE(E) ((void) (E))
|
||||
#else
|
||||
@@ -260,7 +268,7 @@ m4_define([b4_attribute_define],
|
||||
#ifndef YY_INITIAL_VALUE
|
||||
# define YY_INITIAL_VALUE(Value) /* Nothing. */
|
||||
#endif
|
||||
])
|
||||
]])
|
||||
|
||||
|
||||
# b4_null_define
|
||||
@@ -506,54 +514,54 @@ m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
||||
# Define the "yy_symbol_print" function.
|
||||
m4_define_default([b4_yy_symbol_print_define],
|
||||
[[
|
||||
/*----------------------------------------.
|
||||
| Print this symbol's value on YYOUTPUT. |
|
||||
`----------------------------------------*/
|
||||
/*-----------------------------------.
|
||||
| Print this symbol's value on YYO. |
|
||||
`-----------------------------------*/
|
||||
|
||||
]b4_function_define([yy_symbol_value_print],
|
||||
[static void],
|
||||
[[FILE *yyoutput], [yyoutput]],
|
||||
[[FILE *yyo], [yyo]],
|
||||
[[int yytype], [yytype]],
|
||||
[[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
|
||||
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
|
||||
m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
||||
{
|
||||
FILE *yyo = yyoutput;
|
||||
]b4_parse_param_use([yyo], [yylocationp])dnl
|
||||
FILE *yyoutput = yyo;
|
||||
]b4_parse_param_use([yyoutput], [yylocationp])dnl
|
||||
[ if (!yyvaluep)
|
||||
return;]
|
||||
dnl glr.c does not feature yytoknum.
|
||||
m4_if(b4_skeleton, ["yacc.c"],
|
||||
[[# ifdef YYPRINT
|
||||
if (yytype < YYNTOKENS)
|
||||
YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
|
||||
YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
|
||||
# endif
|
||||
]])dnl
|
||||
b4_symbol_actions([printer])[
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------.
|
||||
| Print this symbol on YYOUTPUT. |
|
||||
`--------------------------------*/
|
||||
/*---------------------------.
|
||||
| Print this symbol on YYO. |
|
||||
`---------------------------*/
|
||||
|
||||
]b4_function_define([yy_symbol_print],
|
||||
[static void],
|
||||
[[FILE *yyoutput], [yyoutput]],
|
||||
[[FILE *yyo], [yyo]],
|
||||
[[int yytype], [yytype]],
|
||||
[[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
|
||||
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
|
||||
m4_ifset([b4_parse_param], [, b4_parse_param]))[
|
||||
{
|
||||
YYFPRINTF (yyoutput, "%s %s (",
|
||||
YYFPRINTF (yyo, "%s %s (",
|
||||
yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
|
||||
|
||||
]b4_locations_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp);
|
||||
YYFPRINTF (yyoutput, ": ");
|
||||
]b4_locations_if([ YY_LOCATION_PRINT (yyo, *yylocationp);
|
||||
YYFPRINTF (yyo, ": ");
|
||||
])dnl
|
||||
[ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl
|
||||
[ yy_symbol_value_print (yyo, yytype, yyvaluep]dnl
|
||||
b4_locations_if([, yylocationp])[]b4_user_args[);
|
||||
YYFPRINTF (yyoutput, ")");
|
||||
YYFPRINTF (yyo, ")");
|
||||
}]dnl
|
||||
])
|
||||
|
||||
@@ -815,11 +823,11 @@ m4_define([b4_yy_location_print_define],
|
||||
|
||||
YY_ATTRIBUTE_UNUSED
|
||||
]b4_function_define([yy_location_print_],
|
||||
[static unsigned],
|
||||
[static int],
|
||||
[[FILE *yyo], [yyo]],
|
||||
[[YYLTYPE const * const yylocp], [yylocp]])[
|
||||
{
|
||||
unsigned res = 0;
|
||||
int res = 0;
|
||||
int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
|
||||
if (0 <= yylocp->first_line)
|
||||
{
|
||||
|
||||
+31
-34
@@ -199,7 +199,6 @@ m4_if(b4_skeleton, ["glr.c"],
|
||||
[b4_output_begin([b4_spec_defines_file])
|
||||
b4_copyright([Skeleton interface for Bison GLR parsers in C],
|
||||
[2002-2015, 2018])[
|
||||
|
||||
]b4_cpp_guard_open([b4_spec_defines_file])[
|
||||
]b4_shared_declarations[
|
||||
]b4_cpp_guard_close([b4_spec_defines_file])[
|
||||
@@ -214,9 +213,9 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C],
|
||||
b4_output_begin([b4_parser_file_name])
|
||||
b4_copyright([Skeleton implementation for Bison GLR parsers in C],
|
||||
[2002-2015, 2018])[
|
||||
|
||||
/* C GLR parser skeleton written by Paul Hilfinger. */
|
||||
|
||||
]b4_disclaimer[
|
||||
]b4_identification[
|
||||
|
||||
]b4_percent_code_get([[top]])[
|
||||
@@ -236,7 +235,6 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C],
|
||||
#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
|
||||
#define yylloc ]b4_prefix[lloc]])]))[
|
||||
|
||||
/* First part of user declarations. */
|
||||
]b4_user_pre_prologue[
|
||||
|
||||
]b4_null_define[
|
||||
@@ -259,9 +257,8 @@ b4_copyright([Skeleton implementation for Bison GLR parsers in C],
|
||||
static YYSTYPE yyval_default;]b4_locations_if([[
|
||||
static YYLTYPE yyloc_default][]b4_yyloc_default;])[
|
||||
|
||||
/* Copy the second part of user declarations. */
|
||||
]b4_user_post_prologue
|
||||
b4_percent_code_get[]dnl
|
||||
]b4_user_post_prologue[
|
||||
]b4_percent_code_get[]dnl
|
||||
|
||||
[#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -296,6 +293,7 @@ b4_percent_code_get[]dnl
|
||||
# define yytrue true
|
||||
# define yyfalse false
|
||||
#else
|
||||
/* When we move to stdbool, get rid of the various casts to yybool. */
|
||||
typedef unsigned char yybool;
|
||||
# define yytrue 1
|
||||
# define yyfalse 0
|
||||
@@ -313,7 +311,7 @@ b4_percent_code_get[]dnl
|
||||
} while (yyfalse)
|
||||
#endif
|
||||
|
||||
]b4_attribute_define[
|
||||
]b4_attribute_define([noreturn])[
|
||||
|
||||
#ifndef YYASSERT
|
||||
# define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0)))
|
||||
@@ -603,7 +601,7 @@ yytnamerr (char *yyres, const char *yystr)
|
||||
if (! yyres)
|
||||
return strlen (yystr);
|
||||
|
||||
return yystpcpy (yyres, yystr) - yyres;
|
||||
return (size_t) (yystpcpy (yyres, yystr) - yyres);
|
||||
}
|
||||
# endif
|
||||
|
||||
@@ -708,7 +706,7 @@ struct yyGLRStack {
|
||||
static void yyexpandGLRStack (yyGLRStack* yystackp);
|
||||
#endif
|
||||
|
||||
static _Noreturn void
|
||||
_Noreturn static void
|
||||
yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
|
||||
{
|
||||
if (yymsg != YY_NULLPTR)
|
||||
@@ -716,7 +714,7 @@ yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg)
|
||||
YYLONGJMP (yystackp->yyexception_buffer, 1);
|
||||
}
|
||||
|
||||
static _Noreturn void
|
||||
_Noreturn static void
|
||||
yyMemoryExhausted (yyGLRStack* yystackp)
|
||||
{
|
||||
YYLONGJMP (yystackp->yyexception_buffer, 2);
|
||||
@@ -782,11 +780,11 @@ yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
|
||||
* (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
|
||||
* yyerr for YYERROR, yyabort for YYABORT. */
|
||||
static YYRESULTTAG
|
||||
yyuserAction (yyRuleNum yyn, size_t yyrhslen, yyGLRStackItem* yyvsp,
|
||||
yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
|
||||
yyGLRStack* yystackp,
|
||||
YYSTYPE* yyvalp]b4_locuser_formals[)
|
||||
{
|
||||
yybool yynormal YY_ATTRIBUTE_UNUSED = (yystackp->yysplitPoint == YY_NULLPTR);
|
||||
yybool yynormal YY_ATTRIBUTE_UNUSED = (yybool) (yystackp->yysplitPoint == YY_NULLPTR);
|
||||
int yylow;
|
||||
]b4_parse_param_use([yyvalp], [yylocp])dnl
|
||||
[ YYUSE (yyrhslen);
|
||||
@@ -803,7 +801,7 @@ yyuserAction (yyRuleNum yyn, size_t yyrhslen, yyGLRStackItem* yyvsp,
|
||||
# undef yyclearin
|
||||
# define yyclearin (yychar = YYEMPTY)
|
||||
# undef YYFILL
|
||||
# define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
|
||||
# define YYFILL(N) yyfill (yyvsp, &yylow, (N), yynormal)
|
||||
# undef YYBACKUP
|
||||
# define YYBACKUP(Token, Value) \
|
||||
return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \
|
||||
@@ -820,7 +818,7 @@ yyuserAction (yyRuleNum yyn, size_t yyrhslen, yyGLRStackItem* yyvsp,
|
||||
]])[
|
||||
switch (yyn)
|
||||
{
|
||||
]b4_user_actions[
|
||||
]b4_user_actions[
|
||||
default: break;
|
||||
}
|
||||
|
||||
@@ -906,7 +904,7 @@ yylhsNonterm (yyRuleNum yyrule)
|
||||
static inline yybool
|
||||
yyisDefaultedState (yyStateNum yystate)
|
||||
{
|
||||
return yypact_value_is_default (yypact[yystate]);
|
||||
return (yybool) yypact_value_is_default (yypact[yystate]);
|
||||
}
|
||||
|
||||
/** The default reduction for YYSTATE, assuming it has one. */
|
||||
@@ -932,7 +930,7 @@ yygetLRActions (yyStateNum yystate, int yytoken,
|
||||
int* yyaction, const short** yyconflicts)
|
||||
{
|
||||
int yyindex = yypact[yystate] + yytoken;
|
||||
if (yypact_value_is_default (yypact[yystate])
|
||||
if (yyisDefaultedState (yystate)
|
||||
|| yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
|
||||
{
|
||||
*yyaction = -yydefact[yystate];
|
||||
@@ -967,13 +965,13 @@ yyLRgotoState (yyStateNum yystate, yySymbol yysym)
|
||||
static inline yybool
|
||||
yyisShiftAction (int yyaction)
|
||||
{
|
||||
return 0 < yyaction;
|
||||
return (yybool) (0 < yyaction);
|
||||
}
|
||||
|
||||
static inline yybool
|
||||
yyisErrorAction (int yyaction)
|
||||
{
|
||||
return yyaction == 0;
|
||||
return (yybool) (yyaction == 0);
|
||||
}
|
||||
|
||||
/* GLRStates */
|
||||
@@ -1083,7 +1081,7 @@ yyexpandGLRStack (yyGLRStack* yystackp)
|
||||
yyGLRStackItem* yyp0, *yyp1;
|
||||
size_t yynewSize;
|
||||
size_t yyn;
|
||||
size_t yysize = yystackp->yynextFree - yystackp->yyitems;
|
||||
size_t yysize = (size_t) (yystackp->yynextFree - yystackp->yyitems);
|
||||
if (YYMAXDEPTH - YYHEADROOM < yysize)
|
||||
yyMemoryExhausted (yystackp);
|
||||
yynewSize = 2*yysize;
|
||||
@@ -1266,7 +1264,7 @@ do { \
|
||||
`----------------------------------------------------------------------*/
|
||||
|
||||
static inline void
|
||||
yy_reduce_print (int yynormal, yyGLRStackItem* yyvsp, size_t yyk,
|
||||
yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, size_t yyk,
|
||||
yyRuleNum yyrule]b4_user_formals[)
|
||||
{
|
||||
int yynrhs = yyrhsLength (yyrule);]b4_locations_if([
|
||||
@@ -1283,8 +1281,8 @@ yy_reduce_print (int yynormal, yyGLRStackItem* yyvsp, size_t yyk,
|
||||
YYFPRINTF (stderr, " $%d = ", yyi + 1);
|
||||
yy_symbol_print (stderr,
|
||||
yystos[yyvsp[yyi - yynrhs + 1].yystate.yylrState],
|
||||
&yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yysval
|
||||
]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl
|
||||
&yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yysval]b4_locations_if([,
|
||||
&]b4_rhs_location(yynrhs, yyi + 1))[]dnl
|
||||
b4_user_args[);
|
||||
if (!yyvsp[yyi - yynrhs + 1].yystate.yyresolved)
|
||||
YYFPRINTF (stderr, " (unresolved)");
|
||||
@@ -1311,9 +1309,9 @@ yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
|
||||
yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
|
||||
YYASSERT (yyk == 0);
|
||||
yystackp->yynextFree -= yynrhs;
|
||||
yystackp->yyspaceLeft += yynrhs;
|
||||
yystackp->yyspaceLeft += (size_t) yynrhs;
|
||||
yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate;
|
||||
YY_REDUCE_PRINT ((1, yyrhs, yyk, yyrule]b4_user_args[));
|
||||
YY_REDUCE_PRINT ((yytrue, yyrhs, yyk, yyrule]b4_user_args[));
|
||||
return yyuserAction (yyrule, yynrhs, yyrhs, yystackp,
|
||||
yyvalp]b4_locuser_args[);
|
||||
}
|
||||
@@ -1334,7 +1332,7 @@ yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
|
||||
}
|
||||
yyupdateSplit (yystackp, yys);
|
||||
yystackp->yytops.yystates[yyk] = yys;
|
||||
YY_REDUCE_PRINT ((0, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule]b4_user_args[));
|
||||
YY_REDUCE_PRINT ((yyfalse, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule]b4_user_args[));
|
||||
return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
|
||||
yystackp, yyvalp]b4_locuser_args[);
|
||||
}
|
||||
@@ -1430,11 +1428,9 @@ yysplitStack (yyGLRStack* yystackp, size_t yyk)
|
||||
}
|
||||
if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity)
|
||||
{
|
||||
yyGLRState** yynewStates;
|
||||
yyGLRState** yynewStates = YY_NULLPTR;
|
||||
yybool* yynewLookaheadNeeds;
|
||||
|
||||
yynewStates = YY_NULLPTR;
|
||||
|
||||
if (yystackp->yytops.yycapacity
|
||||
> (YYSIZEMAX / (2 * sizeof yynewStates[0])))
|
||||
yyMemoryExhausted (yystackp);
|
||||
@@ -1862,9 +1858,9 @@ yycompressStack (yyGLRStack* yystackp)
|
||||
yyr = yyp, yyp = yyq, yyq = yyp->yypred)
|
||||
yyp->yypred = yyr;
|
||||
|
||||
yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems;
|
||||
yystackp->yyspaceLeft += (size_t) (yystackp->yynextFree - yystackp->yyitems);
|
||||
yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1;
|
||||
yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems;
|
||||
yystackp->yyspaceLeft -= (size_t) (yystackp->yynextFree - yystackp->yyitems);
|
||||
yystackp->yysplitPoint = YY_NULLPTR;
|
||||
yystackp->yylastDeleted = YY_NULLPTR;
|
||||
|
||||
@@ -2068,7 +2064,8 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
|
||||
yyarg[yycount++] = yytokenName (yyx);
|
||||
{
|
||||
size_t yysz = yysize + yytnamerr (YY_NULLPTR, yytokenName (yyx));
|
||||
yysize_overflow |= yysz < yysize;
|
||||
if (yysz < yysize)
|
||||
yysize_overflow = yytrue;
|
||||
yysize = yysz;
|
||||
}
|
||||
}
|
||||
@@ -2093,7 +2090,8 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
|
||||
|
||||
{
|
||||
size_t yysz = yysize + strlen (yyformat);
|
||||
yysize_overflow |= yysz < yysize;
|
||||
if (yysz < yysize)
|
||||
yysize_overflow = yytrue;
|
||||
yysize = yysz;
|
||||
}
|
||||
|
||||
@@ -2266,7 +2264,6 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
|
||||
yylloc = yyloc_default;])[
|
||||
]m4_ifdef([b4_initial_action], [
|
||||
b4_dollar_pushdef([yylval], [], [yylloc])dnl
|
||||
/* User initialization code. */
|
||||
b4_user_initial_action
|
||||
b4_dollar_popdef])[]dnl
|
||||
[
|
||||
@@ -2358,7 +2355,7 @@ b4_dollar_popdef])[]dnl
|
||||
size_t yys;
|
||||
|
||||
for (yys = 0; yys < yystack.yytops.yysize; yys += 1)
|
||||
yystackp->yytops.yylookaheadNeeds[yys] = yychar != YYEMPTY;
|
||||
yystackp->yytops.yylookaheadNeeds[yys] = (yybool) (yychar != YYEMPTY);
|
||||
|
||||
/* yyprocessOneStack returns one of three things:
|
||||
|
||||
|
||||
+15
-5
@@ -44,7 +44,7 @@
|
||||
# filename member).
|
||||
|
||||
# We require a pure interface.
|
||||
m4_define([b4_pure_flag], [1])
|
||||
m4_define([b4_pure_flag], [1])
|
||||
|
||||
m4_include(b4_pkgdatadir/[c++.m4])
|
||||
b4_bison_locations_if([m4_include(b4_pkgdatadir/[location.cc])])
|
||||
@@ -166,6 +166,12 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
]b4_parser_class_name[::operator() ()
|
||||
{
|
||||
return parse ();
|
||||
}
|
||||
|
||||
int
|
||||
]b4_parser_class_name[::parse ()
|
||||
{
|
||||
@@ -184,9 +190,9 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl
|
||||
{]b4_locations_if([[
|
||||
YYUSE (yylocationp);]])[
|
||||
YYUSE (yyvaluep);
|
||||
std::ostream& yyoutput = debug_stream ();
|
||||
std::ostream& yyo = yyoutput;
|
||||
YYUSE (yyo);
|
||||
std::ostream& yyo = debug_stream ();
|
||||
std::ostream& yyoutput = yyo;
|
||||
YYUSE (yyoutput);
|
||||
]b4_symbol_actions([printer])[
|
||||
}
|
||||
|
||||
@@ -267,6 +273,10 @@ b4_percent_code_get([[requires]])[
|
||||
]b4_parser_class_name[ (]b4_parse_param_decl[);
|
||||
virtual ~]b4_parser_class_name[ ();
|
||||
|
||||
/// Parse. An alias for parse ().
|
||||
/// \returns 0 iff parsing succeeded.
|
||||
int operator() ();
|
||||
|
||||
/// Parse.
|
||||
/// \returns 0 iff parsing succeeded.
|
||||
virtual int parse ();
|
||||
@@ -333,9 +343,9 @@ b4_defines_if(
|
||||
[b4_output_begin([b4_spec_defines_file])
|
||||
b4_copyright([Skeleton interface for Bison GLR parsers in C++],
|
||||
[2002-2015, 2018])[
|
||||
|
||||
// C++ GLR parser skeleton written by Akim Demaille.
|
||||
|
||||
]b4_disclaimer[
|
||||
]b4_cpp_guard_open([b4_spec_defines_file])[
|
||||
]b4_shared_declarations[
|
||||
]b4_cpp_guard_close([b4_spec_defines_file])[
|
||||
|
||||
+41
-20
@@ -190,6 +190,10 @@ m4_define([b4_shared_declarations],
|
||||
]b4_parser_class_name[ (]b4_parse_param_decl[);
|
||||
virtual ~]b4_parser_class_name[ ();
|
||||
|
||||
/// Parse. An alias for parse ().
|
||||
/// \returns 0 iff parsing succeeded.
|
||||
int operator() ();
|
||||
|
||||
/// Parse.
|
||||
/// \returns 0 iff parsing succeeded.
|
||||
virtual int parse ();
|
||||
@@ -268,8 +272,9 @@ m4_define([b4_shared_declarations],
|
||||
/// Print the state stack on the debug stream.
|
||||
virtual void yystack_print_ ();
|
||||
|
||||
// Debugging.
|
||||
/// Debugging level.
|
||||
int yydebug_;
|
||||
/// Debug stream.
|
||||
std::ostream* yycdebug_;
|
||||
|
||||
/// \brief Display a symbol type, value and location.
|
||||
@@ -331,9 +336,10 @@ m4_define([b4_shared_declarations],
|
||||
stack_symbol_type (YY_RVREF (stack_symbol_type) that);
|
||||
/// Steal the contents from \a sym to build this.
|
||||
stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) sym);
|
||||
#if defined __cplusplus && __cplusplus < 201103L
|
||||
#if YY_CPLUSPLUS < 201103L
|
||||
/// Assignment, needed by push_back by some old implementations.
|
||||
stack_symbol_type& operator= (YY_MOVE_REF (stack_symbol_type) that);
|
||||
/// Moves the contents of that.
|
||||
stack_symbol_type& operator= (stack_symbol_type& that);
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -358,8 +364,8 @@ m4_define([b4_shared_declarations],
|
||||
/// \warning the contents of \a sym.value is stolen.
|
||||
void yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym);
|
||||
|
||||
/// Pop \a n symbols the three stacks.
|
||||
void yypop_ (unsigned n = 1);
|
||||
/// Pop \a n symbols from the stack.
|
||||
void yypop_ (int n = 1);
|
||||
|
||||
/// Constants.
|
||||
enum
|
||||
@@ -391,6 +397,10 @@ m4_define([b4_shared_declarations],
|
||||
]b4_percent_code_get([[provides]])[
|
||||
]])
|
||||
|
||||
## -------------- ##
|
||||
## Output files. ##
|
||||
## -------------- ##
|
||||
|
||||
b4_defines_if(
|
||||
[b4_output_begin([b4_spec_defines_file])
|
||||
b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
|
||||
@@ -402,6 +412,7 @@ b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
|
||||
|
||||
// C++ LALR(1) parser skeleton written by Akim Demaille.
|
||||
|
||||
]b4_disclaimer[
|
||||
]b4_cpp_guard_open([b4_spec_defines_file])[
|
||||
]b4_shared_declarations(hh)[
|
||||
]b4_cpp_guard_close([b4_spec_defines_file])
|
||||
@@ -409,21 +420,20 @@ b4_output_end
|
||||
])
|
||||
|
||||
|
||||
b4_output_begin([b4_parser_file_name])
|
||||
b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])
|
||||
b4_percent_code_get([[top]])[]dnl
|
||||
b4_output_begin([b4_parser_file_name])[
|
||||
]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])[
|
||||
]b4_disclaimer[
|
||||
]b4_percent_code_get([[top]])[]dnl
|
||||
m4_if(b4_prefix, [yy], [],
|
||||
[
|
||||
// Take the name prefix into account.
|
||||
[#]define yylex b4_prefix[]lex])[
|
||||
|
||||
// First part of user declarations.
|
||||
]b4_user_pre_prologue[
|
||||
|
||||
]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]],
|
||||
[b4_shared_declarations([cc])])[
|
||||
|
||||
// User implementation prologue.
|
||||
]b4_user_post_prologue[
|
||||
]b4_percent_code_get[
|
||||
|
||||
@@ -602,6 +612,10 @@ m4_if(b4_prefix, [yy], [],
|
||||
{]b4_variant_if([
|
||||
b4_symbol_variant([that.type_get ()],
|
||||
[value], [YY_MOVE_OR_COPY], [YY_MOVE (that.value)])])[
|
||||
#if 201103L <= YY_CPLUSPLUS
|
||||
// that is emptied.
|
||||
that.state = empty_state;
|
||||
#endif
|
||||
}
|
||||
|
||||
]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) that)
|
||||
@@ -613,15 +627,17 @@ m4_if(b4_prefix, [yy], [],
|
||||
that.type = empty_symbol;
|
||||
}
|
||||
|
||||
#if defined __cplusplus && __cplusplus < 201103L
|
||||
#if YY_CPLUSPLUS < 201103L
|
||||
]b4_parser_class_name[::stack_symbol_type&
|
||||
]b4_parser_class_name[::stack_symbol_type::operator= (YY_MOVE_REF (stack_symbol_type) that)
|
||||
]b4_parser_class_name[::stack_symbol_type::operator= (stack_symbol_type& that)
|
||||
{
|
||||
state = that.state;
|
||||
]b4_variant_if([b4_symbol_variant([that.type_get ()],
|
||||
[value], [move], [YY_MOVE (that.value)])],
|
||||
[[value = YY_MOVE (that.value);]])[]b4_locations_if([
|
||||
location = YY_MOVE (that.location);])[
|
||||
[value], [move], [that.value])],
|
||||
[[value = that.value;]])[]b4_locations_if([
|
||||
location = that.location;])[
|
||||
// that is emptied.
|
||||
that.state = empty_state;
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
@@ -669,8 +685,8 @@ m4_if(b4_prefix, [yy], [],
|
||||
void
|
||||
]b4_parser_class_name[::yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym)
|
||||
{
|
||||
#if defined __cplusplus && 201103L <= __cplusplus
|
||||
yypush_ (m, stack_symbol_type (s, YY_MOVE (sym)));
|
||||
#if 201103L <= YY_CPLUSPLUS
|
||||
yypush_ (m, stack_symbol_type (s, std::move (sym)));
|
||||
#else
|
||||
stack_symbol_type ss (s, sym);
|
||||
yypush_ (m, ss);
|
||||
@@ -678,7 +694,7 @@ m4_if(b4_prefix, [yy], [],
|
||||
}
|
||||
|
||||
void
|
||||
]b4_parser_class_name[::yypop_ (unsigned n)
|
||||
]b4_parser_class_name[::yypop_ (int n)
|
||||
{
|
||||
yystack_.pop (n);
|
||||
}
|
||||
@@ -732,6 +748,12 @@ m4_if(b4_prefix, [yy], [],
|
||||
return yyvalue == yytable_ninf_;
|
||||
}
|
||||
|
||||
int
|
||||
]b4_parser_class_name[::operator() ()
|
||||
{
|
||||
return parse ();
|
||||
}
|
||||
|
||||
int
|
||||
]b4_parser_class_name[::parse ()
|
||||
{
|
||||
@@ -761,7 +783,6 @@ m4_if(b4_prefix, [yy], [],
|
||||
|
||||
]m4_ifdef([b4_initial_action], [
|
||||
b4_dollar_pushdef([yyla.value], [], [yyla.location])dnl
|
||||
// User initialization code.
|
||||
b4_user_initial_action
|
||||
b4_dollar_popdef])[]dnl
|
||||
|
||||
@@ -855,7 +876,7 @@ b4_dollar_popdef])[]dnl
|
||||
/* Variants are always initialized to an empty instance of the
|
||||
correct type. The default '$$ = $1' action is NOT applied
|
||||
when using variants. */
|
||||
b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])], [
|
||||
b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [emplace])], [
|
||||
/* If YYLEN is nonzero, implement the default value of the
|
||||
action: '$$ = $1'. Otherwise, use the top of the stack.
|
||||
|
||||
|
||||
+8
-11
@@ -82,15 +82,14 @@ m4_define([b4_define_state],[[
|
||||
]b4_yystype[ yylval = null;
|
||||
]])
|
||||
|
||||
b4_output_begin([b4_parser_file_name])
|
||||
b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
|
||||
[2007-2015, 2018])
|
||||
|
||||
b4_percent_define_ifdef([package], [package b4_percent_define_get([package]);
|
||||
])[/* First part of user declarations. */
|
||||
]b4_user_pre_prologue
|
||||
b4_user_post_prologue
|
||||
b4_percent_code_get([[imports]])
|
||||
b4_output_begin([b4_parser_file_name])[
|
||||
]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
|
||||
[2007-2015, 2018])[
|
||||
]b4_percent_define_ifdef([package], [package b4_percent_define_get([package]);[
|
||||
]])[
|
||||
]b4_user_pre_prologue[
|
||||
]b4_user_post_prologue[
|
||||
]b4_percent_code_get([[imports]])
|
||||
[/**
|
||||
* A Bison parser, automatically generated from <tt>]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[</tt>.
|
||||
*
|
||||
@@ -586,7 +585,6 @@ b4_define_state])[
|
||||
yystack.push (yystate, yylval ]b4_locations_if([, yylloc])[);
|
||||
]m4_ifdef([b4_initial_action], [
|
||||
b4_dollar_pushdef([yylval], [], [yylloc])dnl
|
||||
/* User initialization code. */
|
||||
b4_user_initial_action
|
||||
b4_dollar_popdef[]dnl
|
||||
])[
|
||||
@@ -597,7 +595,6 @@ b4_dollar_popdef[]dnl
|
||||
push_parse_initialize ();
|
||||
]m4_ifdef([b4_initial_action], [
|
||||
b4_dollar_pushdef([yylval], [], [yylloc])dnl
|
||||
/* User initialization code. */
|
||||
b4_user_initial_action
|
||||
b4_dollar_popdef[]dnl
|
||||
])[
|
||||
|
||||
+3
-3
@@ -59,7 +59,7 @@ m4_ifdef([b4_location_file],
|
||||
# ------------------
|
||||
# Define the position and location classes.
|
||||
m4_define([b4_location_define],
|
||||
[[ /// Abstract a position.
|
||||
[[ /// A point in a source file.
|
||||
class position
|
||||
{
|
||||
public:]m4_ifdef([b4_location_constructors], [[
|
||||
@@ -178,7 +178,7 @@ m4_define([b4_location_define],
|
||||
return ostr << pos.line << '.' << pos.column;
|
||||
}
|
||||
|
||||
/// Abstract a location.
|
||||
/// Two points in a source file.
|
||||
class location
|
||||
{
|
||||
public:
|
||||
@@ -322,6 +322,7 @@ m4_define([b4_location_define],
|
||||
|
||||
m4_ifdef([b4_position_file], [[
|
||||
]b4_output_begin([b4_dir_prefix], [b4_position_file])[
|
||||
]b4_generated_by[
|
||||
// Starting with Bison 3.2, this file is useless: the structure it
|
||||
// used to define is now defined in "]b4_location_file[".
|
||||
//
|
||||
@@ -338,7 +339,6 @@ m4_ifdef([b4_position_file], [[
|
||||
m4_ifdef([b4_location_file], [[
|
||||
]b4_output_begin([b4_dir_prefix], [b4_location_file])[
|
||||
]b4_copyright([Locations for Bison parsers in C++])[
|
||||
|
||||
/**
|
||||
** \file ]b4_location_path[
|
||||
** Define the ]b4_namespace_ref[::location class.
|
||||
|
||||
+29
-16
@@ -27,7 +27,7 @@ b4_defines_if([b4_required_version_if([302], [],
|
||||
# ---------------
|
||||
m4_define([b4_stack_define],
|
||||
[[ /// A stack with random access from its top.
|
||||
template <class T, class S = std::vector<T> >
|
||||
template <typename T, typename S = std::vector<T> >
|
||||
class stack
|
||||
{
|
||||
public:
|
||||
@@ -36,12 +36,7 @@ m4_define([b4_stack_define],
|
||||
typedef typename S::const_reverse_iterator const_iterator;
|
||||
typedef typename S::size_type size_type;
|
||||
|
||||
stack ()
|
||||
{
|
||||
seq_.reserve (200);
|
||||
}
|
||||
|
||||
stack (size_type n)
|
||||
stack (size_type n = 200)
|
||||
: seq_ (n)
|
||||
{}
|
||||
|
||||
@@ -51,7 +46,16 @@ m4_define([b4_stack_define],
|
||||
T&
|
||||
operator[] (size_type i)
|
||||
{
|
||||
return seq_[seq_.size () - 1 - i];
|
||||
return seq_[size () - 1 - i];
|
||||
}
|
||||
|
||||
/// Random access.
|
||||
///
|
||||
/// Index 0 returns the topmost element.
|
||||
T&
|
||||
operator[] (int i)
|
||||
{
|
||||
return operator[] (size_type (i));
|
||||
}
|
||||
|
||||
/// Random access.
|
||||
@@ -60,7 +64,16 @@ m4_define([b4_stack_define],
|
||||
const T&
|
||||
operator[] (size_type i) const
|
||||
{
|
||||
return seq_[seq_.size () - 1 - i];
|
||||
return seq_[size () - 1 - i];
|
||||
}
|
||||
|
||||
/// Random access.
|
||||
///
|
||||
/// Index 0 returns the topmost element.
|
||||
const T&
|
||||
operator[] (int i) const
|
||||
{
|
||||
return operator[] (size_type (i));
|
||||
}
|
||||
|
||||
/// Steal the contents of \a t.
|
||||
@@ -74,9 +87,9 @@ m4_define([b4_stack_define],
|
||||
}
|
||||
|
||||
void
|
||||
pop (size_type n = 1)
|
||||
pop (int n = 1)
|
||||
{
|
||||
for (; n; --n)
|
||||
for (; 0 < n; --n)
|
||||
seq_.pop_back ();
|
||||
}
|
||||
|
||||
@@ -112,30 +125,30 @@ m4_define([b4_stack_define],
|
||||
};
|
||||
|
||||
/// Present a slice of the top of a stack.
|
||||
template <class T, class S = stack<T> >
|
||||
template <typename T, typename S = stack<T> >
|
||||
class slice
|
||||
{
|
||||
public:
|
||||
typedef typename S::size_type size_type;
|
||||
slice (const S& stack, size_type range)
|
||||
slice (const S& stack, int range)
|
||||
: stack_ (stack)
|
||||
, range_ (range)
|
||||
{}
|
||||
|
||||
const T&
|
||||
operator[] (size_type i) const
|
||||
operator[] (int i) const
|
||||
{
|
||||
return stack_[range_ - i];
|
||||
}
|
||||
|
||||
private:
|
||||
const S& stack_;
|
||||
size_type range_;
|
||||
int range_;
|
||||
};
|
||||
]])
|
||||
|
||||
m4_ifdef([b4_stack_file],
|
||||
[b4_output_begin([b4_dir_prefix], [b4_stack_file])[
|
||||
]b4_generated_by[
|
||||
// Starting with Bison 3.2, this file is useless: the structure it
|
||||
// used to define is now defined with the parser itself.
|
||||
//
|
||||
|
||||
+66
-18
@@ -117,7 +117,7 @@ m4_define([b4_variant_define],
|
||||
/// Instantiate an empty \a T in here.
|
||||
template <typename T>
|
||||
T&
|
||||
build ()
|
||||
emplace ()
|
||||
{]b4_parse_assert_if([
|
||||
YYASSERT (!yytypeid_);
|
||||
YYASSERT (sizeof (T) <= S);
|
||||
@@ -125,16 +125,47 @@ m4_define([b4_variant_define],
|
||||
return *new (yyas_<T> ()) T ();
|
||||
}
|
||||
|
||||
# if 201103L <= YY_CPLUSPLUS
|
||||
/// Instantiate a \a T in here from \a t.
|
||||
template <typename T, typename U>
|
||||
T&
|
||||
emplace (U&& u)
|
||||
{]b4_parse_assert_if([
|
||||
YYASSERT (!yytypeid_);
|
||||
YYASSERT (sizeof (T) <= S);
|
||||
yytypeid_ = & typeid (T);])[
|
||||
return *new (yyas_<T> ()) T (std::forward <U>(u));
|
||||
}
|
||||
# else
|
||||
/// Instantiate a \a T in here from \a t.
|
||||
template <typename T>
|
||||
T&
|
||||
build (const T& t)
|
||||
emplace (const T& t)
|
||||
{]b4_parse_assert_if([
|
||||
YYASSERT (!yytypeid_);
|
||||
YYASSERT (sizeof (T) <= S);
|
||||
yytypeid_ = & typeid (T);])[
|
||||
return *new (yyas_<T> ()) T (t);
|
||||
}
|
||||
# endif
|
||||
|
||||
/// Instantiate an empty \a T in here.
|
||||
/// Obsolete, use emplace.
|
||||
template <typename T>
|
||||
T&
|
||||
build ()
|
||||
{
|
||||
return emplace<T> ();
|
||||
}
|
||||
|
||||
/// Instantiate a \a T in here from \a t.
|
||||
/// Obsolete, use emplace.
|
||||
template <typename T>
|
||||
T&
|
||||
build (const T& t)
|
||||
{
|
||||
return emplace<T> (t);
|
||||
}
|
||||
|
||||
/// Accessor to a built \a T.
|
||||
template <typename T>
|
||||
@@ -182,23 +213,22 @@ m4_define([b4_variant_define],
|
||||
void
|
||||
move (self_type& other)
|
||||
{
|
||||
build<T> ();
|
||||
# if defined __cplusplus && 201103L <= __cplusplus
|
||||
as<T> () = YY_MOVE (other.as<T> ());
|
||||
# if 201103L <= YY_CPLUSPLUS
|
||||
emplace<T> (std::move (other.as<T> ()));
|
||||
# else
|
||||
emplace<T> ();
|
||||
swap<T> (other);
|
||||
# endif
|
||||
other.destroy<T> ();
|
||||
}
|
||||
|
||||
# if defined __cplusplus && 201103L <= __cplusplus
|
||||
# if 201103L <= YY_CPLUSPLUS
|
||||
/// Move the content of \a other to this.
|
||||
template <typename T>
|
||||
void
|
||||
move (self_type&& other)
|
||||
{
|
||||
build<T> ();
|
||||
as<T> () = YY_MOVE (other.as<T> ());
|
||||
emplace<T> (std::move (other.as<T> ()));
|
||||
other.destroy<T> ();
|
||||
}
|
||||
#endif
|
||||
@@ -208,7 +238,7 @@ m4_define([b4_variant_define],
|
||||
void
|
||||
copy (const self_type& other)
|
||||
{
|
||||
build<T> (other.as<T> ());
|
||||
emplace<T> (other.as<T> ());
|
||||
}
|
||||
|
||||
/// Destroy the stored \a T.
|
||||
@@ -349,26 +379,44 @@ b4_join(b4_symbol_if([$1], [has_type],
|
||||
# -----------------------------------
|
||||
# Generate a constructor declaration for basic_symbol from given type.
|
||||
m4_define([b4_basic_symbol_constructor_declare],
|
||||
[[ basic_symbol (]b4_join(
|
||||
[[# if 201103L <= YY_CPLUSPLUS
|
||||
basic_symbol (]b4_join(
|
||||
[typename Base::kind_type t],
|
||||
b4_symbol_if([$1], [has_type], [YY_RVREF (b4_symbol([$1], [type])) v]),
|
||||
b4_locations_if([YY_RVREF (location_type) l]))[);
|
||||
b4_symbol_if([$1], [has_type], [b4_symbol([$1], [type])&& v]),
|
||||
b4_locations_if([location_type&& l]))[);
|
||||
#else
|
||||
basic_symbol (]b4_join(
|
||||
[typename Base::kind_type t],
|
||||
b4_symbol_if([$1], [has_type], [const b4_symbol([$1], [type])& v]),
|
||||
b4_locations_if([const location_type& l]))[);
|
||||
#endif
|
||||
]])
|
||||
|
||||
# b4_basic_symbol_constructor_define
|
||||
# ----------------------------------
|
||||
# Generate a constructor implementation for basic_symbol from given type.
|
||||
m4_define([b4_basic_symbol_constructor_define],
|
||||
[[ template <typename Base>
|
||||
[[# if 201103L <= YY_CPLUSPLUS
|
||||
template <typename Base>
|
||||
]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join(
|
||||
[typename Base::kind_type t],
|
||||
b4_symbol_if([$1], [has_type], [YY_RVREF (b4_symbol([$1], [type])) v]),
|
||||
b4_locations_if([YY_RVREF (location_type) l]))[)
|
||||
b4_symbol_if([$1], [has_type], [b4_symbol([$1], [type])&& v]),
|
||||
b4_locations_if([location_type&& l]))[)
|
||||
: Base (t)]b4_symbol_if([$1], [has_type], [
|
||||
, value (YY_MOVE (v))])[]b4_locations_if([
|
||||
, location (YY_MOVE (l))])[
|
||||
, value (std::move (v))])[]b4_locations_if([
|
||||
, location (std::move (l))])[
|
||||
{}
|
||||
|
||||
#else
|
||||
template <typename Base>
|
||||
]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join(
|
||||
[typename Base::kind_type t],
|
||||
b4_symbol_if([$1], [has_type], [const b4_symbol([$1], [type])& v]),
|
||||
b4_locations_if([const location_type& l]))[)
|
||||
: Base (t)]b4_symbol_if([$1], [has_type], [
|
||||
, value (v)])[]b4_locations_if([
|
||||
, location (l)])[
|
||||
{}
|
||||
#endif
|
||||
]])
|
||||
|
||||
# b4_symbol_constructor_define
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
<xsl:param name="staten"/>
|
||||
<xsl:for-each select='reduction'>
|
||||
<!-- These variables are needed because the current context can't be
|
||||
refered to directly in XPath expressions. -->
|
||||
referred to directly in XPath expressions. -->
|
||||
<xsl:variable name="rul">
|
||||
<xsl:value-of select="@rule"/>
|
||||
</xsl:variable>
|
||||
@@ -95,7 +95,7 @@
|
||||
<xsl:if test='not(preceding-sibling::*[@rule=$rul and @enabled=$ena])'>
|
||||
<xsl:variable name="rule">
|
||||
<xsl:choose>
|
||||
<!-- The acceptation state is refered to as 'accept' in the XML, but
|
||||
<!-- The acceptation state is referred to as 'accept' in the XML, but
|
||||
just as '0' in the DOT. -->
|
||||
<xsl:when test="@rule='accept'">
|
||||
<xsl:text>0</xsl:text>
|
||||
|
||||
+35
-42
@@ -299,9 +299,8 @@ m4_define([b4_shared_declarations],
|
||||
## Output files. ##
|
||||
## -------------- ##
|
||||
|
||||
b4_output_begin([b4_parser_file_name])
|
||||
b4_copyright([Bison implementation for Yacc-like parsers in C])[
|
||||
|
||||
b4_output_begin([b4_parser_file_name])[
|
||||
]b4_copyright([Bison implementation for Yacc-like parsers in C])[
|
||||
/* C LALR(1) parser skeleton written by Richard Stallman, by
|
||||
simplifying the original so-called "semantic" parser. */
|
||||
|
||||
@@ -312,8 +311,9 @@ b4_copyright([Bison implementation for Yacc-like parsers in C])[
|
||||
define necessary library symbols; they are noted "INFRINGES ON
|
||||
USER NAME SPACE" below. */
|
||||
|
||||
]b4_identification
|
||||
b4_percent_code_get([[top]])[]dnl
|
||||
]b4_disclaimer[
|
||||
]b4_identification[
|
||||
]b4_percent_code_get([[top]])[]dnl
|
||||
m4_if(b4_api_prefix, [yy], [],
|
||||
[[/* Substitute the type names. */
|
||||
#define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[
|
||||
@@ -335,9 +335,7 @@ m4_if(b4_api_prefix, [yy], [],
|
||||
#define yychar ]b4_prefix[char]b4_locations_if([[
|
||||
#define yylloc ]b4_prefix[lloc]])]))[
|
||||
|
||||
/* Copy the first part of user declarations. */
|
||||
]b4_user_pre_prologue[
|
||||
|
||||
]b4_null_define[
|
||||
|
||||
/* Enabling verbose error messages. */
|
||||
@@ -354,9 +352,8 @@ m4_if(b4_api_prefix, [yy], [],
|
||||
]])dnl
|
||||
b4_shared_declarations[
|
||||
|
||||
/* Copy the second part of user declarations. */
|
||||
]b4_user_post_prologue
|
||||
b4_percent_code_get[]dnl
|
||||
]b4_user_post_prologue[
|
||||
]b4_percent_code_get[]dnl
|
||||
|
||||
[#ifdef short
|
||||
# undef short
|
||||
@@ -791,7 +788,7 @@ yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd,
|
||||
yytype_int16 **yytop, yytype_int16 *yytop_empty)
|
||||
{
|
||||
YYSIZE_T yysize_old =
|
||||
*yytop == yytop_empty ? 0 : *yytop - *yybottom + 1;
|
||||
(YYSIZE_T) (*yytop == yytop_empty ? 0 : *yytop - *yybottom + 1);
|
||||
YYSIZE_T yysize_new = yysize_old + yyadd;
|
||||
if (*yycapacity < yysize_new)
|
||||
{
|
||||
@@ -957,7 +954,7 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes,
|
||||
YYDPRINTF ((stderr, " R%d", yyrule - 1));
|
||||
if (yyesp != yyes_prev)
|
||||
{
|
||||
YYSIZE_T yysize = yyesp - *yyes + 1;
|
||||
YYSIZE_T yysize = (YYSIZE_T) (yyesp - *yyes + 1);
|
||||
if (yylen < yysize)
|
||||
{
|
||||
yyesp -= yylen;
|
||||
@@ -973,15 +970,14 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes,
|
||||
yyesp = yyes_prev -= yylen;
|
||||
}
|
||||
{
|
||||
int yystate;
|
||||
yytype_int16 yystate;
|
||||
{
|
||||
int yylhs = yyr1[yyrule] - YYNTOKENS;
|
||||
yystate = yypgoto[yylhs] + *yyesp;
|
||||
if (yystate < 0 || YYLAST < yystate
|
||||
|| yycheck[yystate] != *yyesp)
|
||||
yystate = yydefgoto[yylhs];
|
||||
else
|
||||
yystate = yytable[yystate];
|
||||
const int yylhs = yyr1[yyrule] - YYNTOKENS;
|
||||
const int yyi = yypgoto[yylhs] + *yyesp;
|
||||
yystate = ((yytype_int16)
|
||||
(0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyesp
|
||||
? yytable[yyi]
|
||||
: yydefgoto[yylhs]));
|
||||
}
|
||||
if (yyesp == yyes_prev)
|
||||
{
|
||||
@@ -1001,7 +997,7 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes,
|
||||
}
|
||||
*++yyesp = yystate;
|
||||
}
|
||||
YYDPRINTF ((stderr, " G%d", yystate));
|
||||
YYDPRINTF ((stderr, " G%d", (int) yystate));
|
||||
}
|
||||
}
|
||||
}]])[
|
||||
@@ -1089,7 +1085,7 @@ yytnamerr (char *yyres, const char *yystr)
|
||||
if (! yyres)
|
||||
return yystrlen (yystr);
|
||||
|
||||
return yystpcpy (yyres, yystr) - yyres;
|
||||
return (YYSIZE_T) (yystpcpy (yyres, yystr) - yyres);
|
||||
}
|
||||
# endif
|
||||
|
||||
@@ -1433,7 +1429,6 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[
|
||||
]m4_ifdef([b4_initial_action], [
|
||||
b4_dollar_pushdef([m4_define([b4_dollar_dollar_used])yylval], [],
|
||||
[b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])])dnl
|
||||
/* User initialization code. */
|
||||
b4_user_initial_action
|
||||
b4_dollar_popdef[]dnl
|
||||
m4_ifdef([b4_dollar_dollar_used],[[ yyvsp[0] = yylval;
|
||||
@@ -1451,12 +1446,12 @@ b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yyllo
|
||||
yyssp++;
|
||||
|
||||
yysetstate:
|
||||
*yyssp = yystate;
|
||||
*yyssp = (yytype_int16) yystate;
|
||||
|
||||
if (yyss + yystacksize - 1 <= yyssp)
|
||||
{
|
||||
/* Get the current used size of the three stacks, in elements. */
|
||||
YYSIZE_T yysize = yyssp - yyss + 1;
|
||||
YYSIZE_T yysize = (YYSIZE_T) (yyssp - yyss + 1);
|
||||
|
||||
#ifdef yyoverflow
|
||||
{
|
||||
@@ -1476,10 +1471,9 @@ b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yyllo
|
||||
&yyvs1, yysize * sizeof (*yyvsp),]b4_locations_if([
|
||||
&yyls1, yysize * sizeof (*yylsp),])[
|
||||
&yystacksize);
|
||||
]b4_locations_if([
|
||||
yyls = yyls1;])[
|
||||
yyss = yyss1;
|
||||
yyvs = yyvs1;
|
||||
yyvs = yyvs1;]b4_locations_if([
|
||||
yyls = yyls1;])[
|
||||
}
|
||||
#else /* no yyoverflow */
|
||||
# ifndef YYSTACK_RELOCATE
|
||||
@@ -1653,7 +1647,7 @@ yyreduce:
|
||||
int yychar_backup = yychar;
|
||||
switch (yyn)
|
||||
{
|
||||
]b4_user_actions[
|
||||
]b4_user_actions[
|
||||
default: break;
|
||||
}
|
||||
if (yychar_backup != yychar)
|
||||
@@ -1687,14 +1681,13 @@ yyreduce:
|
||||
/* Now 'shift' the result of the reduction. Determine what state
|
||||
that goes to, based on the state we popped back to and the rule
|
||||
number reduced by. */
|
||||
|
||||
yyn = yyr1[yyn];
|
||||
|
||||
yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
|
||||
if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
|
||||
yystate = yytable[yystate];
|
||||
else
|
||||
yystate = yydefgoto[yyn - YYNTOKENS];
|
||||
{
|
||||
const int yylhs = yyr1[yyn] - YYNTOKENS;
|
||||
const int yyi = yypgoto[yylhs] + *yyssp;
|
||||
yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
|
||||
? yytable[yyi]
|
||||
: yydefgoto[yylhs]);
|
||||
}
|
||||
|
||||
goto yynewstate;
|
||||
|
||||
@@ -1910,10 +1903,10 @@ yypushreturn:]])[
|
||||
]b4_epilogue[]dnl
|
||||
b4_output_end
|
||||
|
||||
b4_defines_if(
|
||||
[b4_output_begin([b4_spec_defines_file])[
|
||||
b4_defines_if([[
|
||||
]b4_output_begin([b4_spec_defines_file])[
|
||||
]b4_copyright([Bison interface for Yacc-like parsers in C])[
|
||||
|
||||
]b4_disclaimer[
|
||||
]b4_shared_declarations[
|
||||
]b4_output_end
|
||||
])# b4_defines_if
|
||||
]b4_output_end[
|
||||
]])# b4_defines_if
|
||||
|
||||
+12
-10
@@ -1,25 +1,28 @@
|
||||
# Do not ignore these. The release procedure (web-manual-update)
|
||||
# works in the src tree (even when run from the build tree) and leaves
|
||||
# these files around. Since they take precedence over the files in
|
||||
# the build tree, locally built manuals use obsolete auxiliary files.
|
||||
#
|
||||
# So don't hide them, give the maintainer a chance to clean them.
|
||||
#/bison.aux
|
||||
#/bison.cp
|
||||
#/bison.cps
|
||||
#/bison.toc
|
||||
|
||||
/*~
|
||||
/.dirstamp
|
||||
/bison.1
|
||||
/bison.aux
|
||||
/bison.cp
|
||||
/bison.cps
|
||||
/bison.dvi
|
||||
/bison.fn
|
||||
/bison.help
|
||||
/bison.html
|
||||
/bison.info
|
||||
/bison.ky
|
||||
/bison.log
|
||||
/bison.pdf
|
||||
/bison.pg
|
||||
/bison.ps
|
||||
/bison.toc
|
||||
/bison.tp
|
||||
/bison.vr
|
||||
/cross-options.texi
|
||||
/fdl.texi
|
||||
/gendocs_template
|
||||
/gendocs_template_min
|
||||
/gpl-3.0.texi
|
||||
/refcard.dvi
|
||||
/refcard.log
|
||||
@@ -27,4 +30,3 @@
|
||||
/stamp-vti
|
||||
/version.texi
|
||||
/yacc.1
|
||||
/gendocs_template_min
|
||||
|
||||
+437
-169
@@ -338,10 +338,11 @@ Parsers Written In Other Languages
|
||||
|
||||
C++ Parsers
|
||||
|
||||
* A Simple C++ Example:: A short introduction to C++ parsers
|
||||
* C++ Bison Interface:: Asking for C++ parser generation
|
||||
* C++ Parser Interface:: Instantiating and running the parser
|
||||
* C++ Semantic Values:: %union vs. C++
|
||||
* C++ Location Values:: The position and location classes
|
||||
* C++ Parser Interface:: Instantiating and running the parser
|
||||
* C++ Scanner Interface:: Exchanges between yylex and parse
|
||||
* A Complete C++ Example:: Demonstrating their use
|
||||
|
||||
@@ -3193,14 +3194,14 @@ type:
|
||||
%code requires @{ #include "type1.h" @}
|
||||
%union @{ type1 field1; @}
|
||||
%destructor @{ type1_free ($$); @} <field1>
|
||||
%printer @{ type1_print (yyoutput, $$); @} <field1>
|
||||
%printer @{ type1_print (yyo, $$); @} <field1>
|
||||
@end group
|
||||
|
||||
@group
|
||||
%code requires @{ #include "type2.h" @}
|
||||
%union @{ type2 field2; @}
|
||||
%destructor @{ type2_free ($$); @} <field2>
|
||||
%printer @{ type2_print (yyoutput, $$); @} <field2>
|
||||
%printer @{ type2_print (yyo, $$); @} <field2>
|
||||
@end group
|
||||
@end example
|
||||
|
||||
@@ -5166,11 +5167,12 @@ Decl, , Freeing Discarded Symbols}).
|
||||
|
||||
@deffn {Directive} %printer @{ @var{code} @} @var{symbols}
|
||||
@findex %printer
|
||||
@vindex yyo
|
||||
@vindex yyoutput
|
||||
@c This is the same text as for %destructor.
|
||||
Invoke the braced @var{code} whenever the parser displays one of the
|
||||
@var{symbols}. Within @var{code}, @code{yyoutput} denotes the output stream
|
||||
(a @code{FILE*} in C, and an @code{std::ostream&} in C++), @code{$$} (or
|
||||
@var{symbols}. Within @var{code}, @code{yyo} denotes the output stream (a
|
||||
@code{FILE*} in C, and an @code{std::ostream&} in C++), @code{$$} (or
|
||||
@code{$<@var{tag}>$}) designates the semantic value associated with the
|
||||
symbol, and @code{@@$} its location. The additional parser parameters are
|
||||
also available (@pxref{Parser Function, , The Parser Function
|
||||
@@ -5195,10 +5197,10 @@ For example:
|
||||
%type <character> chr
|
||||
%token TAGLESS
|
||||
|
||||
%printer @{ fprintf (yyoutput, "'%c'", $$); @} <character>
|
||||
%printer @{ fprintf (yyoutput, "&%p", $$); @} <*>
|
||||
%printer @{ fprintf (yyoutput, "\"%s\"", $$); @} STRING1 string1
|
||||
%printer @{ fprintf (yyoutput, "<>"); @} <>
|
||||
%printer @{ fprintf (yyo, "'%c'", $$); @} <character>
|
||||
%printer @{ fprintf (yyo, "&%p", $$); @} <*>
|
||||
%printer @{ fprintf (yyo, "\"%s\"", $$); @} STRING1 string1
|
||||
%printer @{ fprintf (yyo, "<>"); @} <>
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
@@ -9861,9 +9863,9 @@ prologue:
|
||||
%define parse.trace
|
||||
|
||||
/* Formatting semantic values. */
|
||||
%printer @{ fprintf (yyoutput, "%s", $$->name); @} VAR;
|
||||
%printer @{ fprintf (yyoutput, "%s()", $$->name); @} FNCT;
|
||||
%printer @{ fprintf (yyoutput, "%g", $$); @} <double>;
|
||||
%printer @{ fprintf (yyo, "%s", $$->name); @} VAR;
|
||||
%printer @{ fprintf (yyo, "%s()", $$->name); @} FNCT;
|
||||
%printer @{ fprintf (yyo, "%g", $$); @} <double>;
|
||||
@end example
|
||||
|
||||
The @code{%define} directive instructs Bison to generate run-time trace
|
||||
@@ -10593,6 +10595,10 @@ int yyparse (void);
|
||||
@node Other Languages
|
||||
@chapter Parsers Written In Other Languages
|
||||
|
||||
In addition to C, Bison can generate parsers in C++ and Java. This chapter
|
||||
is devoted to these languages. The reader is expected to understand how
|
||||
Bison works; read the introductory chapters first if you don't.
|
||||
|
||||
@menu
|
||||
* C++ Parsers:: The interface to generate C++ parser classes
|
||||
* Java Parsers:: The interface to generate Java parser classes
|
||||
@@ -10601,15 +10607,217 @@ int yyparse (void);
|
||||
@node C++ Parsers
|
||||
@section C++ Parsers
|
||||
|
||||
The Bison parser in C++ is an object, an instance of the class
|
||||
@code{yy::parser}.
|
||||
|
||||
@menu
|
||||
* A Simple C++ Example:: A short introduction to C++ parsers
|
||||
* C++ Bison Interface:: Asking for C++ parser generation
|
||||
* C++ Parser Interface:: Instantiating and running the parser
|
||||
* C++ Semantic Values:: %union vs. C++
|
||||
* C++ Location Values:: The position and location classes
|
||||
* C++ Parser Interface:: Instantiating and running the parser
|
||||
* C++ Scanner Interface:: Exchanges between yylex and parse
|
||||
* A Complete C++ Example:: Demonstrating their use
|
||||
@end menu
|
||||
|
||||
@node A Simple C++ Example
|
||||
@subsection A Simple C++ Example
|
||||
|
||||
This tutorial about C++ parsers is based on a simple, self contained
|
||||
example. The following sections are the reference manual for Bison with
|
||||
C++, the last one showing a fully blown example (@pxref{A Complete C++
|
||||
Example}).
|
||||
|
||||
To look nicer, our example will be in C++14. It is not required: Bison
|
||||
supports the original C++98 standard.
|
||||
|
||||
A Bison file has three parts. In the first part, the prologue, we start by
|
||||
making sure we run a version of Bison which is recent enough, and that we
|
||||
generate C++.
|
||||
|
||||
@comment file: c++/simple.yy: 1
|
||||
@example
|
||||
%require "3.2"
|
||||
%language "c++"
|
||||
@end example
|
||||
|
||||
Let's dive directly into the middle part: the grammar. Our input is a
|
||||
simple list of strings, that we display once the parsing is done.
|
||||
|
||||
@comment file: c++/simple.yy: 2
|
||||
@example
|
||||
%%
|
||||
@group
|
||||
result:
|
||||
list @{ std::cout << $1 << '\n'; @}
|
||||
;
|
||||
@end group
|
||||
|
||||
%type <std::vector<std::string>> list;
|
||||
@group
|
||||
list:
|
||||
%empty @{ /* Generates an empty string list */ @}
|
||||
| list item @{ $$ = $1; $$.push_back ($2); @}
|
||||
;
|
||||
@end group
|
||||
@end example
|
||||
|
||||
We used a vector of strings as a semantic value! To use genuine C++ objects
|
||||
as semantic values---not just PODs---we cannot rely on the union that Bison
|
||||
uses by default to store them, we need @emph{variants} (@pxref{C++
|
||||
Variants}):
|
||||
|
||||
@comment file: c++/simple.yy: 1
|
||||
@example
|
||||
%define api.value.type variant
|
||||
@end example
|
||||
|
||||
Obviously, the rule for @code{result} needs to print a vector of strings.
|
||||
In the prologue, we add:
|
||||
|
||||
@comment file: c++/simple.yy: 1
|
||||
@example
|
||||
%code
|
||||
@{
|
||||
// Print a list of strings.
|
||||
auto
|
||||
operator<< (std::ostream& o, const std::vector<std::string>& ss)
|
||||
-> std::ostream&
|
||||
@{
|
||||
o << '@{';
|
||||
const char *sep = "";
|
||||
@group
|
||||
for (const auto& s: ss)
|
||||
@{
|
||||
o << sep << s;
|
||||
sep = ", ";
|
||||
@}
|
||||
@end group
|
||||
return o << '@}';
|
||||
@}
|
||||
@}
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
You may want to move it into the @code{yy} namespace to avoid leaking it in
|
||||
your default namespace. We recommend that you keep the actions simple, and
|
||||
move details into auxiliary functions, as we did with @code{operator<<}.
|
||||
|
||||
Our list of strings will be built from two types of items: numbers and
|
||||
strings:
|
||||
|
||||
@comment file: c++/simple.yy: 2
|
||||
@example
|
||||
%type <std::string> item;
|
||||
%token <std::string> TEXT;
|
||||
%token <int> NUMBER;
|
||||
@group
|
||||
item:
|
||||
TEXT
|
||||
| NUMBER @{ $$ = std::to_string ($1); @}
|
||||
;
|
||||
@end group
|
||||
@end example
|
||||
|
||||
In the case of @code{TEXT}, the implicit default action applies: @w{@code{$$
|
||||
= $1}.}
|
||||
|
||||
@sp 1
|
||||
|
||||
Our scanner deserves some attention. The traditional interface of
|
||||
@code{yylex} is not type safe: since the token type and the token value are
|
||||
not correlated, you may return a @code{NUMBER} with a string as semantic
|
||||
value. To avoid this, we use @emph{token constructors} (@pxref{Complete
|
||||
Symbols}). This directive:
|
||||
|
||||
@comment file: c++/simple.yy: 1
|
||||
@example
|
||||
%define api.token.constructor
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
requests that Bison generates the functions @code{make_TEXT} and
|
||||
@code{make_NUMBER}. As a matter of fact, it is convenient to have also a
|
||||
symbol to mark the end of input, say @code{END_OF_FILE}:
|
||||
|
||||
@comment file: c++/simple.yy: 1
|
||||
@example
|
||||
%token END_OF_FILE 0
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
The @code{0} tells Bison this token is special: when it is reached, parsing
|
||||
finishes.
|
||||
|
||||
Everything is in place for our scanner:
|
||||
|
||||
@comment file: c++/simple.yy: 1
|
||||
@example
|
||||
%code
|
||||
@{
|
||||
namespace yy
|
||||
@{
|
||||
// Return the next token.
|
||||
auto yylex () -> parser::symbol_type
|
||||
@{
|
||||
static int count = 0;
|
||||
switch (int stage = count++)
|
||||
@{
|
||||
@group
|
||||
case 0:
|
||||
return parser::make_TEXT ("I have three numbers for you.");
|
||||
@end group
|
||||
@group
|
||||
case 1: case 2: case 3:
|
||||
return parser::make_NUMBER (stage);
|
||||
@end group
|
||||
@group
|
||||
case 4:
|
||||
return parser::make_TEXT ("And that's all!");
|
||||
@end group
|
||||
@group
|
||||
default:
|
||||
return parser::make_END_OF_FILE ();
|
||||
@end group
|
||||
@}
|
||||
@}
|
||||
@}
|
||||
@}
|
||||
@end example
|
||||
|
||||
In the epilogue, the third part of a Bison grammar file, we leave simple
|
||||
details: the error reporting function, and the main function.
|
||||
|
||||
@comment file: c++/simple.yy: 3
|
||||
@example
|
||||
%%
|
||||
namespace yy
|
||||
@{
|
||||
// Report an error to the user.
|
||||
auto parser::error (const std::string& msg) -> void
|
||||
@{
|
||||
std::cerr << msg << '\n';
|
||||
@}
|
||||
@}
|
||||
|
||||
int main ()
|
||||
@{
|
||||
yy::parser parse;
|
||||
return parse ();
|
||||
@}
|
||||
@end example
|
||||
|
||||
Compile, and run!
|
||||
|
||||
@example
|
||||
$ bison simple.yy -o simple.cc
|
||||
$ g++ -std=c++14 simple.cc -o simple
|
||||
@group
|
||||
$ ./simple
|
||||
@{I have three numbers for you., 1, 2, 3, And that's all!@}
|
||||
@end group
|
||||
@end example
|
||||
|
||||
@node C++ Bison Interface
|
||||
@subsection C++ Bison Interface
|
||||
@c - %skeleton "lalr1.cc"
|
||||
@@ -10617,9 +10825,7 @@ int yyparse (void);
|
||||
@c - initial action
|
||||
|
||||
The C++ deterministic parser is selected using the skeleton directive,
|
||||
@samp{%skeleton "lalr1.cc"}, or the synonymous command-line option
|
||||
@option{--skeleton=lalr1.cc}.
|
||||
@xref{Decl Summary}.
|
||||
@samp{%skeleton "lalr1.cc"}. @xref{Decl Summary}.
|
||||
|
||||
When run, @command{bison} will create several entities in the @samp{yy}
|
||||
namespace.
|
||||
@@ -10629,18 +10835,22 @@ see @ref{%define Summary,,api.namespace}. The various classes are generated
|
||||
in the following files:
|
||||
|
||||
@table @file
|
||||
@item location.hh
|
||||
The definition of the classes @code{position} and @code{location}, used for
|
||||
location tracking when enabled. This file is not generated if user defined
|
||||
locations are used, i.e., if the @code{%define} variable
|
||||
@code{api.location.type} is defined. @xref{C++ Location Values}.
|
||||
|
||||
@item @var{file}.hh
|
||||
@itemx @var{file}.cc
|
||||
(Assuming the extension of the grammar file was @samp{.yy}.) The
|
||||
declaration and implementation of the C++ parser class. The basename and
|
||||
extension of these two files follow the same rules as with regular C parsers
|
||||
(@pxref{Invocation}).
|
||||
declaration of the C++ parser class and auxiliary types. By default, this
|
||||
file is not generated (@pxref{Decl Summary, ,%defines}).
|
||||
|
||||
@item @var{file}.cc
|
||||
The implementation of the C++ parser class. The basename and extension of
|
||||
these two files (@file{@var{file}.hh} and @file{@var{file}.cc}) follow the
|
||||
same rules as with regular C parsers (@pxref{Invocation}).
|
||||
|
||||
@item location.hh
|
||||
Generated when both @code{%defines} and @code{%locations} are enabled, this
|
||||
file contains the definition of the classes @code{position} and
|
||||
@code{location}, used for location tracking. It is not generated if
|
||||
@samp{%define api.location.file none} is specified, or if user defined
|
||||
locations are used. @xref{C++ Location Values}.
|
||||
|
||||
@item position.hh
|
||||
@itemx stack.hh
|
||||
@@ -10651,6 +10861,95 @@ newer.
|
||||
All these files are documented using Doxygen; run @command{doxygen} for a
|
||||
complete and accurate documentation.
|
||||
|
||||
@node C++ Parser Interface
|
||||
@subsection C++ Parser Interface
|
||||
@c - define parser_class_name
|
||||
@c - Ctor
|
||||
@c - parse, error, set_debug_level, debug_level, set_debug_stream,
|
||||
@c debug_stream.
|
||||
@c - Reporting errors
|
||||
|
||||
The output files @file{@var{file}.hh} and @file{@var{file}.cc} declare
|
||||
and define the parser class in the namespace @code{yy}. The class name
|
||||
defaults to @code{parser}, but may be changed using @samp{%define
|
||||
parser_class_name @{@var{name}@}}. The interface of this class is detailed
|
||||
below. It can be extended using the @code{%parse-param} feature: its
|
||||
semantics is slightly changed since it describes an additional member of the
|
||||
parser class, and an additional argument for its constructor.
|
||||
|
||||
@defcv {Type} {parser} {semantic_type}
|
||||
The types for semantic values. @xref{C++ Semantic Values}.
|
||||
@end defcv
|
||||
|
||||
@defcv {Type} {parser} {location_type}
|
||||
The type of locations, if location tracking is enabled. @xref{C++ Location
|
||||
Values}.
|
||||
@end defcv
|
||||
|
||||
@defcv {Type} {parser} {token}
|
||||
A structure that contains (only) the @code{yytokentype} enumeration, which
|
||||
defines the tokens. To refer to the token @code{FOO}, use
|
||||
@code{yy::parser::token::FOO}. The scanner can use @samp{typedef
|
||||
yy::parser::token token;} to ``import'' the token enumeration (@pxref{Calc++
|
||||
Scanner}).
|
||||
@end defcv
|
||||
|
||||
@defcv {Type} {parser} {syntax_error}
|
||||
This class derives from @code{std::runtime_error}. Throw instances of it
|
||||
from the scanner or from the actions to raise parse errors. This is
|
||||
equivalent with first invoking @code{error} to report the location and
|
||||
message of the syntax error, and then to invoke @code{YYERROR} to enter the
|
||||
error-recovery mode. But contrary to @code{YYERROR} which can only be
|
||||
invoked from user actions (i.e., written in the action itself), the
|
||||
exception can be thrown from functions invoked from the user action.
|
||||
@end defcv
|
||||
|
||||
@deftypeop {Constructor} {parser} {} parser ()
|
||||
@deftypeopx {Constructor} {parser} {} parser (@var{type1} @var{arg1}, ...)
|
||||
Build a new parser object. There are no arguments, unless
|
||||
@samp{%parse-param @{@var{type1} @var{arg1}@}} was used.
|
||||
@end deftypeop
|
||||
|
||||
@deftypeop {Constructor} {syntax_error} {} syntax_error (const location_type& @var{l}, const std::string& @var{m})
|
||||
@deftypeopx {Constructor} {syntax_error} {} syntax_error (const std::string& @var{m})
|
||||
Instantiate a syntax-error exception.
|
||||
@end deftypeop
|
||||
|
||||
@deftypemethod {parser} {int} operator() ()
|
||||
@deftypemethodx {parser} {int} parse ()
|
||||
Run the syntactic analysis, and return 0 on success, 1 otherwise. Both
|
||||
routines are equivalent, @code{operator()} being more C++ish.
|
||||
|
||||
@cindex exceptions
|
||||
The whole function is wrapped in a @code{try}/@code{catch} block, so that
|
||||
when an exception is thrown, the @code{%destructor}s are called to release
|
||||
the lookahead symbol, and the symbols pushed on the stack.
|
||||
|
||||
Exception related code in the generated parser is protected by CPP guards
|
||||
(@code{#if}) and disabled when exceptions are not supported (i.e., passing
|
||||
@code{-fno-exceptions} to the C++ compiler).
|
||||
@end deftypemethod
|
||||
|
||||
@deftypemethod {parser} {std::ostream&} debug_stream ()
|
||||
@deftypemethodx {parser} {void} set_debug_stream (std::ostream& @var{o})
|
||||
Get or set the stream used for tracing the parsing. It defaults to
|
||||
@code{std::cerr}.
|
||||
@end deftypemethod
|
||||
|
||||
@deftypemethod {parser} {debug_level_type} debug_level ()
|
||||
@deftypemethodx {parser} {void} set_debug_level (debug_level_type @var{l})
|
||||
Get or set the tracing level (an integral). Currently its value is either
|
||||
0, no trace, or nonzero, full tracing.
|
||||
@end deftypemethod
|
||||
|
||||
@deftypemethod {parser} {void} error (const location_type& @var{l}, const std::string& @var{m})
|
||||
@deftypemethodx {parser} {void} error (const std::string& @var{m})
|
||||
The definition for this member function must be supplied by the user: the
|
||||
parser uses it to report a parser error occurring at @var{l}, described by
|
||||
@var{m}. If location tracking is not enabled, the second signature is used.
|
||||
@end deftypemethod
|
||||
|
||||
|
||||
@node C++ Semantic Values
|
||||
@subsection C++ Semantic Values
|
||||
@c - No objects in unions
|
||||
@@ -10658,9 +10957,9 @@ complete and accurate documentation.
|
||||
@c - Printer and destructor
|
||||
|
||||
Bison supports two different means to handle semantic values in C++. One is
|
||||
alike the C interface, and relies on unions (@pxref{C++ Unions}). As C++
|
||||
practitioners know, unions are inconvenient in C++, therefore another
|
||||
approach is provided, based on variants (@pxref{C++ Variants}).
|
||||
alike the C interface, and relies on unions. As C++ practitioners know,
|
||||
unions are inconvenient in C++, therefore another approach is provided,
|
||||
based on variants.
|
||||
|
||||
@menu
|
||||
* C++ Unions:: Semantic values cannot be objects
|
||||
@@ -10670,18 +10969,18 @@ approach is provided, based on variants (@pxref{C++ Variants}).
|
||||
@node C++ Unions
|
||||
@subsubsection C++ Unions
|
||||
|
||||
The @code{%union} directive works as for C, see @ref{Union Decl, ,The
|
||||
Union Declaration}. In particular it produces a genuine
|
||||
@code{union}, which have a few specific features in C++.
|
||||
The @code{%union} directive works as for C, see @ref{Union Decl, ,The Union
|
||||
Declaration}. In particular it produces a genuine @code{union}, which have
|
||||
a few specific features in C++.
|
||||
@itemize @minus
|
||||
@item
|
||||
The type @code{YYSTYPE} is defined but its use is discouraged: rather
|
||||
you should refer to the parser's encapsulated type
|
||||
@code{yy::parser::semantic_type}.
|
||||
@item
|
||||
Non POD (Plain Old Data) types cannot be used. C++ forbids any
|
||||
instance of classes with constructors in unions: only @emph{pointers}
|
||||
to such objects are allowed.
|
||||
Non POD (Plain Old Data) types cannot be used. C++98 forbids any instance
|
||||
of classes with constructors in unions: only @emph{pointers} to such objects
|
||||
are allowed. C++11 relaxed this constraints, but at the cost of safety.
|
||||
@end itemize
|
||||
|
||||
Because objects have to be stored via pointers, memory is not
|
||||
@@ -10739,13 +11038,18 @@ of alternative types such as @samp{$<int>2} or @samp{$<std::string>$}, even
|
||||
in midrule actions. It is mandatory to use typed midrule actions
|
||||
(@pxref{Typed Midrule Actions}).
|
||||
|
||||
@deftypemethod {semantic_type} {T&} build<T> ()
|
||||
Initialize, but leave empty. Returns the address where the actual value may
|
||||
be stored. Requires that the variant was not initialized yet.
|
||||
@deftypemethod {semantic_type} {T&} emplace<T> ()
|
||||
Initialize, but leave empty. Return a reference to where the actual value
|
||||
may be stored. Requires that the variant was not initialized yet.
|
||||
@end deftypemethod
|
||||
|
||||
@deftypemethod {semantic_type} {T&} build<T> (const T& @var{t})
|
||||
Initialize, and copy-construct from @var{t}.
|
||||
@deftypemethod {semantic_type} {T&} emplace<T> (const T& @var{t})
|
||||
Initialize, and copy-construct from @var{t}. Available in C++98/C++03 only.
|
||||
@end deftypemethod
|
||||
|
||||
@deftypemethod {semantic_type} {T&} emplace<T, U> (U&& @var{u})
|
||||
Build a variant of type @code{T} from the forwarding reference @var{u}.
|
||||
Available in C++11 and later only.
|
||||
@end deftypemethod
|
||||
|
||||
|
||||
@@ -11021,89 +11325,6 @@ files, reused by other parsers as follows:
|
||||
@end example
|
||||
|
||||
|
||||
@node C++ Parser Interface
|
||||
@subsection C++ Parser Interface
|
||||
@c - define parser_class_name
|
||||
@c - Ctor
|
||||
@c - parse, error, set_debug_level, debug_level, set_debug_stream,
|
||||
@c debug_stream.
|
||||
@c - Reporting errors
|
||||
|
||||
The output files @file{@var{output}.hh} and @file{@var{output}.cc} declare
|
||||
and define the parser class in the namespace @code{yy}. The class name
|
||||
defaults to @code{parser}, but may be changed using @samp{%define
|
||||
parser_class_name @{@var{name}@}}. The interface of this class is detailed
|
||||
below. It can be extended using the @code{%parse-param} feature: its
|
||||
semantics is slightly changed since it describes an additional member of the
|
||||
parser class, and an additional argument for its constructor.
|
||||
|
||||
@defcv {Type} {parser} {semantic_type}
|
||||
@defcvx {Type} {parser} {location_type}
|
||||
The types for semantic values and locations (if enabled).
|
||||
@end defcv
|
||||
|
||||
@defcv {Type} {parser} {token}
|
||||
A structure that contains (only) the @code{yytokentype} enumeration, which
|
||||
defines the tokens. To refer to the token @code{FOO},
|
||||
use @code{yy::parser::token::FOO}. The scanner can use
|
||||
@samp{typedef yy::parser::token token;} to ``import'' the token enumeration
|
||||
(@pxref{Calc++ Scanner}).
|
||||
@end defcv
|
||||
|
||||
@defcv {Type} {parser} {syntax_error}
|
||||
This class derives from @code{std::runtime_error}. Throw instances of it
|
||||
from the scanner or from the actions to raise parse errors. This is
|
||||
equivalent with first invoking @code{error} to report the location and
|
||||
message of the syntax error, and then to invoke @code{YYERROR} to enter the
|
||||
error-recovery mode. But contrary to @code{YYERROR} which can only be
|
||||
invoked from user actions (i.e., written in the action itself), the
|
||||
exception can be thrown from function invoked from the user action.
|
||||
@end defcv
|
||||
|
||||
@deftypeop {Constructor} {parser} {} parser ()
|
||||
@deftypeopx {Constructor} {parser} {} parser (@var{type1} @var{arg1}, ...)
|
||||
Build a new parser object. There are no arguments, unless
|
||||
@samp{%parse-param @{@var{type1} @var{arg1}@}} was used.
|
||||
@end deftypeop
|
||||
|
||||
@deftypeop {Constructor} {syntax_error} {} syntax_error (const location_type& @var{l}, const std::string& @var{m})
|
||||
@deftypeopx {Constructor} {syntax_error} {} syntax_error (const std::string& @var{m})
|
||||
Instantiate a syntax-error exception.
|
||||
@end deftypeop
|
||||
|
||||
@deftypemethod {parser} {int} parse ()
|
||||
Run the syntactic analysis, and return 0 on success, 1 otherwise.
|
||||
|
||||
@cindex exceptions
|
||||
The whole function is wrapped in a @code{try}/@code{catch} block, so that
|
||||
when an exception is thrown, the @code{%destructor}s are called to release
|
||||
the lookahead symbol, and the symbols pushed on the stack.
|
||||
|
||||
Exception related code in the generated parser is protected by CPP guards
|
||||
(@code{#if}) and disabled when exceptions are not supported (i.e., passing
|
||||
@code{-fno-exceptions} to the C++ compiler).
|
||||
@end deftypemethod
|
||||
|
||||
@deftypemethod {parser} {std::ostream&} debug_stream ()
|
||||
@deftypemethodx {parser} {void} set_debug_stream (std::ostream& @var{o})
|
||||
Get or set the stream used for tracing the parsing. It defaults to
|
||||
@code{std::cerr}.
|
||||
@end deftypemethod
|
||||
|
||||
@deftypemethod {parser} {debug_level_type} debug_level ()
|
||||
@deftypemethodx {parser} {void} set_debug_level (debug_level @var{l})
|
||||
Get or set the tracing level. Currently its value is either 0, no trace,
|
||||
or nonzero, full tracing.
|
||||
@end deftypemethod
|
||||
|
||||
@deftypemethod {parser} {void} error (const location_type& @var{l}, const std::string& @var{m})
|
||||
@deftypemethodx {parser} {void} error (const std::string& @var{m})
|
||||
The definition for this member function must be supplied by the user: the
|
||||
parser uses it to report a parser error occurring at @var{l}, described by
|
||||
@var{m}. If location tracking is not enabled, the second signature is used.
|
||||
@end deftypemethod
|
||||
|
||||
|
||||
@node C++ Scanner Interface
|
||||
@subsection C++ Scanner Interface
|
||||
@c - prefix for yylex.
|
||||
@@ -11153,11 +11374,11 @@ initialized. So the code would look like:
|
||||
|
||||
@example
|
||||
[0-9]+ @{
|
||||
yylval->build<int> () = text_to_int (yytext);
|
||||
yylval->emplace<int> () = text_to_int (yytext);
|
||||
return yy::parser::token::INTEGER;
|
||||
@}
|
||||
[a-z]+ @{
|
||||
yylval->build<std::string> () = yytext;
|
||||
yylval->emplace<std::string> () = yytext;
|
||||
return yy::parser::token::IDENTIFIER;
|
||||
@}
|
||||
@end example
|
||||
@@ -11167,11 +11388,11 @@ or
|
||||
|
||||
@example
|
||||
[0-9]+ @{
|
||||
yylval->build (text_to_int (yytext));
|
||||
yylval->emplace (text_to_int (yytext));
|
||||
return yy::parser::token::INTEGER;
|
||||
@}
|
||||
[a-z]+ @{
|
||||
yylval->build (yytext);
|
||||
yylval->emplace (yytext);
|
||||
return yy::parser::token::IDENTIFIER;
|
||||
@}
|
||||
@end example
|
||||
@@ -11185,7 +11406,7 @@ api.token.constructor}, the parser defines the type @code{symbol_type}, and
|
||||
expects @code{yylex} to have the following prototype.
|
||||
|
||||
@deftypefun {parser::symbol_type} yylex ()
|
||||
@deftypefunx {parser::symbol_type} yylex (var{type1} @var{arg1}, ...)
|
||||
@deftypefunx {parser::symbol_type} yylex (@var{type1} @var{arg1}, ...)
|
||||
Return a @emph{complete} symbol, aggregating its type (i.e., the traditional
|
||||
value returned by @code{yylex}), its semantic value, and possibly its
|
||||
location. Invocations of @samp{%lex-param @{@var{type1} @var{arg1}@}} yield
|
||||
@@ -11211,6 +11432,7 @@ For instance, given the following declarations:
|
||||
%token <std::string> IDENTIFIER;
|
||||
%token <int> INTEGER;
|
||||
%token COLON;
|
||||
%token EOF 0;
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
@@ -11220,20 +11442,22 @@ Bison generates:
|
||||
symbol_type make_IDENTIFIER (const std::string&, const location_type&);
|
||||
symbol_type make_INTEGER (const int&, const location_type&);
|
||||
symbol_type make_COLON (const location_type&);
|
||||
symbol_type make_EOF (const location_type&);
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
which should be used in a Lex-scanner as follows.
|
||||
which should be used in a Flex-scanner as follows.
|
||||
|
||||
@example
|
||||
[0-9]+ return yy::parser::make_INTEGER (text_to_int (yytext), loc);
|
||||
[a-z]+ return yy::parser::make_IDENTIFIER (yytext, loc);
|
||||
[0-9]+ return yy::parser::make_INTEGER (text_to_int (yytext), loc);
|
||||
":" return yy::parser::make_COLON (loc);
|
||||
<<EOF>> return yy::parser::make_EOF (loc);
|
||||
@end example
|
||||
|
||||
Tokens that do not have an identifier are not accessible: you cannot simply
|
||||
use characters such as @code{':'}, they must be declared with @code{%token}.
|
||||
|
||||
use characters such as @code{':'}, they must be declared with @code{%token},
|
||||
including the end-of-file token.
|
||||
|
||||
@node A Complete C++ Example
|
||||
@subsection A Complete C++ Example
|
||||
@@ -11302,7 +11526,7 @@ C++ parser expects it to be declared. We can factor both as follows.
|
||||
|
||||
@comment file: calc++/driver.hh
|
||||
@example
|
||||
// Tell Flex the lexer's prototype ...
|
||||
// Give Flex the prototype of yylex we want ...
|
||||
# define YY_DECL \
|
||||
yy::parser::symbol_type yylex (driver& drv)
|
||||
// ... and declare it for the parser's sake.
|
||||
@@ -11383,9 +11607,9 @@ driver::parse (const std::string &f)
|
||||
file = f;
|
||||
location.initialize (&file);
|
||||
scan_begin ();
|
||||
yy::parser parser (*this);
|
||||
parser.set_debug_level (trace_parsing);
|
||||
int res = parser.parse ();
|
||||
yy::parser parse (*this);
|
||||
parse.set_debug_level (trace_parsing);
|
||||
int res = parse ();
|
||||
scan_end ();
|
||||
return res;
|
||||
@}
|
||||
@@ -11529,7 +11753,7 @@ regular destructors. All the values are printed using their
|
||||
|
||||
@comment file: calc++/parser.yy
|
||||
@example
|
||||
%printer @{ yyoutput << $$; @} <*>;
|
||||
%printer @{ yyo << $$; @} <*>;
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
@@ -11558,7 +11782,7 @@ exp:
|
||||
| exp "-" exp @{ $$ = $1 - $3; @}
|
||||
| exp "*" exp @{ $$ = $1 * $3; @}
|
||||
| exp "/" exp @{ $$ = $1 / $3; @}
|
||||
| "(" exp ")" @{ std::swap ($$, $2); @}
|
||||
| "(" exp ")" @{ $$ = $2; @}
|
||||
%%
|
||||
@end example
|
||||
|
||||
@@ -11586,6 +11810,7 @@ then the parser's to get the set of defined tokens.
|
||||
# include <cerrno>
|
||||
# include <climits>
|
||||
# include <cstdlib>
|
||||
# include <cstring> // strerror
|
||||
# include <string>
|
||||
# include "driver.hh"
|
||||
# include "parser.hh"
|
||||
@@ -11608,6 +11833,13 @@ then the parser's to get the set of defined tokens.
|
||||
# pragma GCC diagnostic ignored "-Wnull-dereference"
|
||||
#endif
|
||||
|
||||
// Of course, when compiling C as C++, expect warnings about NULL.
|
||||
#if defined __clang__
|
||||
# pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
|
||||
#elif defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
|
||||
# pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
|
||||
#endif
|
||||
|
||||
#define FLEX_VERSION (YY_FLEX_MAJOR_VERSION * 100 + YY_FLEX_MINOR_VERSION)
|
||||
|
||||
// Old versions of Flex (2.5.35) generate an incomplete documentation comment.
|
||||
@@ -11631,19 +11863,44 @@ then the parser's to get the set of defined tokens.
|
||||
# pragma GCC diagnostic ignored "-Wregister"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if FLEX_VERSION < 206
|
||||
# if defined __clang__
|
||||
# pragma clang diagnostic ignored "-Wconversion"
|
||||
# pragma clang diagnostic ignored "-Wdocumentation"
|
||||
# pragma clang diagnostic ignored "-Wshorten-64-to-32"
|
||||
# pragma clang diagnostic ignored "-Wsign-conversion"
|
||||
# elif defined __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wconversion"
|
||||
# pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
# endif
|
||||
#endif
|
||||
%@}
|
||||
@end example
|
||||
@end ignore
|
||||
|
||||
@noindent
|
||||
Because there is no @code{#include}-like feature we don't need
|
||||
@code{yywrap}, we don't need @code{unput} either, and we parse an actual
|
||||
file, this is not an interactive session with the user. Finally, we enable
|
||||
scanner tracing.
|
||||
Since our calculator has no @code{#include}-like feature, we don't need
|
||||
@code{yywrap}. We don't need the @code{unput} and @code{input} functions
|
||||
either, and we parse an actual file, this is not an interactive session with
|
||||
the user. Finally, we enable scanner tracing.
|
||||
|
||||
@comment file: calc++/scanner.ll
|
||||
@example
|
||||
%option noyywrap nounput batch debug noinput
|
||||
%option noyywrap nounput noinput batch debug
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
The following function will be handy to convert a string denoting a number
|
||||
into a number token.
|
||||
|
||||
@comment file: calc++/scanner.ll
|
||||
@example
|
||||
%@{
|
||||
// A number symbol corresponding to the value in S.
|
||||
yy::parser::symbol_type
|
||||
make_NUMBER (const std::string &s, const yy::parser::location_type& loc);
|
||||
%@}
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
@@ -11682,7 +11939,7 @@ the blanks preceding tokens. Comments would be treated equally.
|
||||
%@}
|
||||
@end group
|
||||
@{blank@}+ loc.step ();
|
||||
[\n]+ loc.lines (yyleng); loc.step ();
|
||||
\n+ loc.lines (yyleng); loc.step ();
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
@@ -11690,24 +11947,15 @@ The rules are simple. The driver is used to report errors.
|
||||
|
||||
@comment file: calc++/scanner.ll
|
||||
@example
|
||||
"-" return yy::parser::make_MINUS (loc);
|
||||
"+" return yy::parser::make_PLUS (loc);
|
||||
"*" return yy::parser::make_STAR (loc);
|
||||
"/" return yy::parser::make_SLASH (loc);
|
||||
"(" return yy::parser::make_LPAREN (loc);
|
||||
")" return yy::parser::make_RPAREN (loc);
|
||||
":=" return yy::parser::make_ASSIGN (loc);
|
||||
"-" return yy::parser::make_MINUS (loc);
|
||||
"+" return yy::parser::make_PLUS (loc);
|
||||
"*" return yy::parser::make_STAR (loc);
|
||||
"/" return yy::parser::make_SLASH (loc);
|
||||
"(" return yy::parser::make_LPAREN (loc);
|
||||
")" return yy::parser::make_RPAREN (loc);
|
||||
":=" return yy::parser::make_ASSIGN (loc);
|
||||
|
||||
@group
|
||||
@{int@} @{
|
||||
errno = 0;
|
||||
long n = strtol (yytext, NULL, 10);
|
||||
if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
|
||||
throw yy::parser::syntax_error (loc, "integer is out of range: "
|
||||
+ std::string(yytext));
|
||||
return yy::parser::make_NUMBER (n, loc);
|
||||
@}
|
||||
@end group
|
||||
@{int@} return make_NUMBER (yytext, loc);
|
||||
@{id@} return yy::parser::make_IDENTIFIER (yytext, loc);
|
||||
@group
|
||||
. @{
|
||||
@@ -11719,6 +11967,25 @@ The rules are simple. The driver is used to report errors.
|
||||
%%
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
You should keep your rules simple, both in the parser and in the scanner.
|
||||
Throwing from the auxiliary functions is then very handy to report errors.
|
||||
|
||||
@comment file: scanner.ll
|
||||
@example
|
||||
@group
|
||||
yy::parser::symbol_type
|
||||
make_NUMBER (const std::string &s, const yy::parser::location_type& loc)
|
||||
@{
|
||||
errno = 0;
|
||||
long n = strtol (s.c_str(), NULL, 10);
|
||||
if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
|
||||
throw yy::parser::syntax_error (loc, "integer is out of range: " + s);
|
||||
return yy::parser::make_NUMBER ((int) n, loc);
|
||||
@}
|
||||
@end group
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
Finally, because the scanner-related driver's member-functions depend
|
||||
on the scanner's data, it is simpler to implement them in this file.
|
||||
@@ -12512,9 +12779,9 @@ too. How can I reset the error flag of @code{yyparse}?
|
||||
or
|
||||
|
||||
@quotation
|
||||
My parser includes support for an @samp{#include}-like feature, in
|
||||
which case I run @code{yyparse} from @code{yyparse}. This fails
|
||||
although I did specify @samp{%define api.pure full}.
|
||||
My parser includes support for an @samp{#include}-like feature, in which
|
||||
case I run @code{yyparse} from @code{yyparse}. This fails although I did
|
||||
specify @samp{%define api.pure full}.
|
||||
@end quotation
|
||||
|
||||
These problems typically come not from Bison itself, but from
|
||||
@@ -12624,7 +12891,7 @@ char *yylval = NULL;
|
||||
@group
|
||||
%%
|
||||
.* yylval = yytext; return 1;
|
||||
\n /* IGNORE */
|
||||
\n continue;
|
||||
%%
|
||||
@end group
|
||||
@group
|
||||
@@ -13728,15 +13995,16 @@ London, Department of Computer Science, TR-00-12 (December 2000).
|
||||
@c LocalWords: subdirectory Solaris nonassociativity perror schemas Malloy ints
|
||||
@c LocalWords: Scannerless ispell american ChangeLog smallexample CSTYPE CLTYPE
|
||||
@c LocalWords: clval CDEBUG cdebug deftypeopx yyterminate LocationType yyo
|
||||
@c LocalWords: parsers parser's documentencoding documentlanguage Wempty
|
||||
@c LocalWords: parsers parser's documentencoding documentlanguage Wempty ss
|
||||
@c LocalWords: associativity subclasses precedences unresolvable runnable
|
||||
@c LocalWords: allocators subunit initializations unreferenced untyped dir
|
||||
@c LocalWords: errorVerbose subtype subtypes Wmidrule midrule's src rvalues
|
||||
@c LocalWords: automove evolutions Wother Wconflicts PNG lookaheads Acc
|
||||
@c LocalWords: automove evolutions Wother Wconflicts PNG lookaheads Acc sep
|
||||
@c LocalWords: xsltproc XSL xsl xhtml html num Wprecedence Werror fcaret
|
||||
@c LocalWords: fdiagnostics setlocale nullptr ast srcdir copyable iff drv
|
||||
@c LocalWords: deftypefunx pragma Wnull dereference Wdocumentation elif
|
||||
@c LocalWords: Wdeprecated Wregister noinput yyloc yypos
|
||||
@c LocalWords: deftypefunx pragma Wnull dereference Wdocumentation elif ish
|
||||
@c LocalWords: Wdeprecated Wregister noinput yyloc yypos PODs sstream Wsign
|
||||
@c LocalWords: typename emplace Wconversion Wshorten
|
||||
|
||||
@c Local Variables:
|
||||
@c ispell-dictionary: "american"
|
||||
|
||||
+18
-15
@@ -32,7 +32,7 @@ $(doc_bison).html: $(FIGS_GV:.gv=.png)
|
||||
TEXI2DVI = texi2dvi --build-dir=doc/bison.t2d -I doc
|
||||
CLEANDIRS += doc/bison.t2d
|
||||
|
||||
MOSTLYCLEANFILES += $(top_srcdir)/doc/*.t
|
||||
MOSTLYCLEANFILES += $(top_srcdir)/doc/*.tmp
|
||||
|
||||
CROSS_OPTIONS_PL = $(top_srcdir)/build-aux/cross-options.pl
|
||||
CROSS_OPTIONS_TEXI = $(top_srcdir)/doc/cross-options.texi
|
||||
@@ -42,8 +42,8 @@ $(CROSS_OPTIONS_TEXI): doc/bison.help $(CROSS_OPTIONS_PL)
|
||||
# diff in the next run. Note that $@ might not exist yet.
|
||||
$(AM_V_GEN){ test ! -f $@ || cat $@; } >$@~
|
||||
$(AM_V_at)test ! -f $@.tmp || rm -f $@.tmp
|
||||
$(AM_V_at)src/bison$(EXEEXT) --help | \
|
||||
$(PERL) $(CROSS_OPTIONS_PL) $(top_srcdir)/src/scan-gram.l >$@.tmp
|
||||
$(AM_V_at)$(PERL) $(CROSS_OPTIONS_PL) $(top_srcdir)/src/scan-gram.l \
|
||||
<$(top_srcdir)/doc/bison.help >$@.tmp
|
||||
$(AM_V_at)diff -u $@~ $@.tmp || true
|
||||
$(AM_V_at)mv $@.tmp $@
|
||||
MAINTAINERCLEANFILES = $(CROSS_OPTIONS_TEXI)
|
||||
@@ -64,9 +64,9 @@ doc/refcard.pdf: doc/refcard.tex
|
||||
## doc/bison.help. ##
|
||||
## ---------------- ##
|
||||
|
||||
# Some of our targets (cross-option.texi, bison.1) use "bison --help".
|
||||
# Some of our targets (cross-options.texi, bison.1) use "bison --help".
|
||||
# Since we want to ship the generated file to avoid additional
|
||||
# requirements over the user environment, we used not depend on
|
||||
# requirements over the user environment, we used to not depend on
|
||||
# src/bison itself, but on src/getargs.c and other files. Yet, we
|
||||
# need "bison --help" to work to make help2man happy, so we used to
|
||||
# include "make src/bison" in the commands. Then we may have a
|
||||
@@ -80,15 +80,18 @@ doc/refcard.pdf: doc/refcard.tex
|
||||
# bison.help, which contains --version then --help. This file can
|
||||
# depend on bison, which ensures its correctness. But update it
|
||||
# *only* if needed (content changes). This way, we avoid useless
|
||||
# compilations of cross-option.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.
|
||||
|
||||
EXTRA_DIST += $(top_srcdir)/doc/bison.help
|
||||
if ! CROSS_COMPILING
|
||||
MAINTAINERCLEANFILES += $(top_srcdir)/doc/bison.help
|
||||
$(top_srcdir)/doc/bison.help: src/bison$(EXEEXT)
|
||||
$(AM_V_GEN)src/bison$(EXEEXT) --version >doc/bison.help.tmp
|
||||
$(AM_V_at) src/bison$(EXEEXT) --help >>doc/bison.help.tmp
|
||||
$(AM_V_GEN)LC_ALL=C src/bison$(EXEEXT) --version >doc/bison.help.tmp
|
||||
$(AM_V_at) LC_ALL=C src/bison$(EXEEXT) --help | \
|
||||
## Avoid variations in the output depending on whether we are
|
||||
## on a glibc system.
|
||||
sed '/translation bugs/d' >>doc/bison.help.tmp
|
||||
$(AM_V_at)$(top_srcdir)/build-aux/move-if-change doc/bison.help.tmp $@
|
||||
endif ! CROSS_COMPILING
|
||||
|
||||
@@ -114,14 +117,14 @@ endif
|
||||
$(top_srcdir)/doc/bison.1: $(MAN_DEPS)
|
||||
$(AM_V_GEN)$(HELP2MAN) \
|
||||
--include=$(top_srcdir)/doc/bison.x \
|
||||
--output=$@.t src/bison$(EXEEXT)
|
||||
$(AM_V_at)if $(remove_time_stamp) $@ >$@a.t 2>/dev/null && \
|
||||
$(remove_time_stamp) $@.t | cmp $@a.t - >/dev/null 2>&1; then \
|
||||
touch $@; \
|
||||
else \
|
||||
mv $@.t $@; \
|
||||
--output=$@.tmp src/bison$(EXEEXT)
|
||||
$(AM_V_at)if $(remove_time_stamp) $@ >$@a.tmp 2>/dev/null && \
|
||||
$(remove_time_stamp) $@.tmp | cmp $@a.tmp - >/dev/null 2>&1; then \
|
||||
touch $@; \
|
||||
else \
|
||||
mv $@.tmp $@; \
|
||||
fi
|
||||
$(AM_V_at)rm -f $@*.t
|
||||
$(AM_V_at)rm -f $@*.tmp
|
||||
|
||||
if ENABLE_YACC
|
||||
nodist_man_MANS = doc/yacc.1
|
||||
|
||||
+31
-13
@@ -1,27 +1,45 @@
|
||||
This directory contains examples of Bison grammar files.
|
||||
|
||||
* mfcalc
|
||||
A C example of a multi-function calculator. Extracted from the
|
||||
documentation.
|
||||
Most of them come from the documentation, which should be installed together
|
||||
with Bison. The URLs are provided for convenience.
|
||||
|
||||
* calc++
|
||||
A C++ version of the canonical example for parsers: a calculator. Also uses
|
||||
Flex for the scanner. Extracted from the documentation.
|
||||
|
||||
* variant.yy
|
||||
A C++ example that uses variants (they allow to use any C++ type as semantic
|
||||
value type) and symbol constructors (they ensure consistency between
|
||||
declared token type and effective semantic value).
|
||||
* Examples in C
|
||||
|
||||
** rpcalc - Reverse Polish Notation Calculator
|
||||
The first example is that of a simple double-precision Reverse Polish
|
||||
Notation calculator (a calculator using postfix operators). This example
|
||||
provides a good starting point, since operator precedence is not an issue.
|
||||
|
||||
Extracted from the documentation: "Reverse Polish Notation Calculator"
|
||||
https://www.gnu.org/software/bison/manual/html_node/RPN-Calc.html
|
||||
|
||||
** mfcalc - Multi-Function Calculator
|
||||
A more complete C example: a multi-function calculator.
|
||||
|
||||
Extracted from the documentation: "Multi-Function Calculator: mfcalc".
|
||||
https://www.gnu.org/software/bison/manual/html_node/Multi_002dfunction-Calc.html
|
||||
|
||||
|
||||
|
||||
* Examples in C++
|
||||
|
||||
** c++ - A directory of simple C++ examples
|
||||
|
||||
** calc++ - A Complete C++ Example
|
||||
A fully featured C++ version of the canonical example for parsers: a
|
||||
calculator. Also uses Flex for the scanner.
|
||||
|
||||
Extracted from the documentation: "A Complete C++ Example".
|
||||
https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html
|
||||
|
||||
* variant-11.yy
|
||||
Another C++ example, closely related to the previous one, but exhibiting
|
||||
support for C++11's move semantics.
|
||||
|
||||
-----
|
||||
|
||||
Local Variables:
|
||||
mode: outline
|
||||
fill-column: 76
|
||||
ispell-dictionary: "american"
|
||||
End:
|
||||
|
||||
Copyright (C) 2018 Free Software Foundation, Inc.
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# This Makefile is designed to be simple and readable. It does not
|
||||
# aim at portability. It requires GNU Make.
|
||||
|
||||
BISON = bison
|
||||
CXX = g++
|
||||
CXXFLAGS =
|
||||
PROGS = simple variant variant-11
|
||||
|
||||
simple: CXXFLAGS = -std=c++14
|
||||
variant-11: CXXFLAGS = -std=c++11
|
||||
|
||||
all: $(PROGS)
|
||||
|
||||
%.cc %.hh: %.yy
|
||||
$(BISON) $(BISONFLAGS) -o $*.cc $<
|
||||
|
||||
%: %.cc
|
||||
$(CXX) $(CXXFLAGS) -o$@ $<
|
||||
|
||||
clean:
|
||||
rm -f $(PROGS:=.cc) $(PROGS)
|
||||
@@ -0,0 +1,47 @@
|
||||
This directory contains examples of Bison grammar files in C++.
|
||||
|
||||
* Examples in C++
|
||||
|
||||
You can run `make` to compile these examples. And `make clean` to tidy
|
||||
afterwards.
|
||||
|
||||
** simple.yy - Simple example in C++14
|
||||
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
|
||||
constructors ensure consistency between declared token type and effective
|
||||
semantic value.
|
||||
|
||||
Run as `./simple`.
|
||||
|
||||
Extracted from the documentation: "A Simple C++ Example".
|
||||
https://www.gnu.org/software/bison/manual/html_node/A-Simple-C_002b_002b-Example.html
|
||||
|
||||
** variant.yy - Self-contained example in C++98
|
||||
A variation of simple.yy, in C++98.
|
||||
|
||||
Run as `./variant`.
|
||||
|
||||
** variant-11.yy - Self-contained example in modern C++
|
||||
Another variation of simple.yy, closely related to the previous one, but
|
||||
exhibiting support for C++11's move semantics.
|
||||
|
||||
Run as `./variant` or `./variant NUMBER`.
|
||||
|
||||
-----
|
||||
|
||||
Local Variables:
|
||||
mode: outline
|
||||
fill-column: 76
|
||||
ispell-dictionary: "american"
|
||||
End:
|
||||
|
||||
Copyright (C) 2018 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.
|
||||
|
||||
# LocalWords: mfcalc calc parsers yy ispell american
|
||||
@@ -0,0 +1,70 @@
|
||||
## Copyright (C) 2018 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/>.
|
||||
|
||||
cxxdir = $(examplesdir)/c++
|
||||
|
||||
## -------- ##
|
||||
## Simple. ##
|
||||
## -------- ##
|
||||
|
||||
BUILT_SOURCES += $(simple_sources)
|
||||
CLEANFILES += %D%/simple.[ch] %D%/simple.output
|
||||
CLEANDIRS += %D%/*.dSYM
|
||||
cxx_DATA = $(simple_extracted)
|
||||
|
||||
simple_extracted = %D%/simple.yy
|
||||
simple_sources = $(simple_extracted)
|
||||
extracted += $(simple_extracted)
|
||||
|
||||
if ENABLE_CXX14
|
||||
check_PROGRAMS += %D%/simple
|
||||
nodist_%C%_simple_SOURCES = $(simple_sources)
|
||||
|
||||
%C%_simple_CXXFLAGS = $(CXX11_CXXFLAGS) $(WARN_CXXFLAGS_TEST)
|
||||
# Don't use gnulib's system headers.
|
||||
%C%_simple_CPPFLAGS = -I$(top_builddir)
|
||||
TESTS += %D%/simple.test
|
||||
%D%/simple.cc: $(BISON_IN) $(dist_pkgdata_DATA)
|
||||
endif
|
||||
EXTRA_DIST += %D%/simple.test
|
||||
|
||||
|
||||
## ---------- ##
|
||||
## Variants. ##
|
||||
## ---------- ##
|
||||
|
||||
if ENABLE_CXX
|
||||
check_PROGRAMS += %D%/variant
|
||||
nodist_%C%_variant_SOURCES = %D%/variant.yy
|
||||
# Don't use gnulib's system headers.
|
||||
%C%_variant_CPPFLAGS = -I$(top_builddir)
|
||||
TESTS += %D%/variant.test
|
||||
%D%/variant.cc: $(BISON_IN) $(dist_pkgdata_DATA)
|
||||
endif
|
||||
EXTRA_DIST += %D%/variant.test
|
||||
|
||||
if ENABLE_CXX11
|
||||
check_PROGRAMS += %D%/variant-11
|
||||
nodist_%C%_variant_11_SOURCES = %D%/variant-11.yy
|
||||
%C%_variant_11_CXXFLAGS = $(CXX11_CXXFLAGS) $(WARN_CXXFLAGS_TEST)
|
||||
# Don't use gnulib's system headers.
|
||||
%C%_variant_11_CPPFLAGS = -I$(top_builddir)
|
||||
TESTS += %D%/variant-11.test
|
||||
%D%/variant-11.cc: $(BISON_IN) $(dist_pkgdata_DATA)
|
||||
endif
|
||||
EXTRA_DIST += %D%/variant-11.test
|
||||
|
||||
dist_cxx_DATA = %D%/README %D%/Makefile %D%/variant.yy %D%/variant-11.yy
|
||||
CLEANFILES += %D%/simple.output %D%/variant.output %D%/variant-11.output
|
||||
@@ -0,0 +1,4 @@
|
||||
#! /bin/sh
|
||||
|
||||
: >input
|
||||
run 0 "{I have three numbers for you., 1, 2, 3, And that's all!}"
|
||||
@@ -0,0 +1,21 @@
|
||||
#! /bin/sh
|
||||
|
||||
# Copyright (C) 2018 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/>.
|
||||
|
||||
: >input
|
||||
run 0 "{I have numbers for you., 1, 2, 3, And that's all!}" 4
|
||||
|
||||
run 0 "{I have numbers for you., 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, And that's all!}" 1000
|
||||
@@ -37,9 +37,8 @@
|
||||
|
||||
%code // *.cc
|
||||
{
|
||||
#include <algorithm>
|
||||
#include <climits> // INT_MIN, INT_MAX
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
namespace yy
|
||||
@@ -69,16 +68,6 @@
|
||||
// std::make_unique is C++14.
|
||||
return string_uptr (new std::string{std::forward<Args> (args)...});
|
||||
}
|
||||
|
||||
// Convert to string.
|
||||
template <typename T>
|
||||
std::string
|
||||
to_string (const T& t)
|
||||
{
|
||||
auto&& o = std::ostringstream{};
|
||||
o << t;
|
||||
return o.str ();
|
||||
}
|
||||
}
|
||||
|
||||
%token <string_uptr> TEXT;
|
||||
@@ -103,17 +92,21 @@ list:
|
||||
|
||||
item:
|
||||
TEXT
|
||||
| NUMBER { $$ = make_string_uptr (to_string ($1)); }
|
||||
| NUMBER { $$ = make_string_uptr (std::to_string ($1)); }
|
||||
;
|
||||
%%
|
||||
|
||||
// The last number return by the scanner is max - 1.
|
||||
int max = 4;
|
||||
|
||||
namespace yy
|
||||
{
|
||||
// The yylex function providing subsequent tokens:
|
||||
// TEXT "I have three numbers for you."
|
||||
// NUMBER 1
|
||||
// NUMBER 2
|
||||
// NUMBER 3
|
||||
// NUMBER ...
|
||||
// NUMBER max - 1
|
||||
// TEXT "And that's all!"
|
||||
// END_OF_FILE
|
||||
|
||||
@@ -121,23 +114,18 @@ namespace yy
|
||||
parser::symbol_type
|
||||
yylex ()
|
||||
{
|
||||
static auto count = 0u;
|
||||
auto stage = count;
|
||||
static int count = 0;
|
||||
const int stage = count;
|
||||
++count;
|
||||
auto loc = parser::location_type{nullptr, stage + 1, stage + 1};
|
||||
switch (stage)
|
||||
{
|
||||
case 0:
|
||||
return parser::make_TEXT (make_string_uptr ("I have three numbers for you."), std::move (loc));
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
return parser::make_NUMBER (stage, std::move (loc));
|
||||
case 4:
|
||||
return parser::make_TEXT (make_string_uptr ("And that's all!"), std::move (loc));
|
||||
default:
|
||||
return parser::make_END_OF_FILE (std::move (loc));
|
||||
}
|
||||
auto loc = parser::location_type{nullptr, unsigned (stage + 1), unsigned (stage + 1)};
|
||||
if (stage == 0)
|
||||
return parser::make_TEXT (make_string_uptr ("I have numbers for you."), std::move (loc));
|
||||
else if (stage < max)
|
||||
return parser::make_NUMBER (stage, std::move (loc));
|
||||
else if (stage == max)
|
||||
return parser::make_TEXT (make_string_uptr ("And that's all!"), std::move (loc));
|
||||
else
|
||||
return parser::make_END_OF_FILE (std::move (loc));
|
||||
}
|
||||
|
||||
// Mandatory error function
|
||||
@@ -149,8 +137,13 @@ namespace yy
|
||||
}
|
||||
|
||||
int
|
||||
main ()
|
||||
main (int argc, const char *argv[])
|
||||
{
|
||||
if (2 <= argc && isdigit (*argv[1]))
|
||||
{
|
||||
auto maxl = strtol (argv[1], nullptr, 10);
|
||||
max = INT_MIN <= maxl && maxl <= INT_MAX ? int(maxl) : 4;
|
||||
}
|
||||
auto&& p = yy::parser{};
|
||||
p.set_debug_level (!!getenv ("YYDEBUG"));
|
||||
return p.parse ();
|
||||
@@ -33,9 +33,7 @@ typedef std::vector<std::string> strings_type;
|
||||
|
||||
%code // *.cc
|
||||
{
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
namespace yy
|
||||
@@ -97,6 +95,13 @@ item:
|
||||
|
||||
namespace yy
|
||||
{
|
||||
// Use nullptr with pre-C++11.
|
||||
#if !defined __cplusplus || __cplusplus < 201103L
|
||||
# define NULLPTR 0
|
||||
#else
|
||||
# define NULLPTR nullptr
|
||||
#endif
|
||||
|
||||
// The yylex function providing subsequent tokens:
|
||||
// TEXT "I have three numbers for you."
|
||||
// NUMBER 1
|
||||
@@ -109,9 +114,10 @@ namespace yy
|
||||
parser::symbol_type
|
||||
yylex ()
|
||||
{
|
||||
static int stage = -1;
|
||||
++stage;
|
||||
parser::location_type loc (YY_NULLPTR, stage + 1, stage + 1);
|
||||
static int count = 0;
|
||||
const int stage = count;
|
||||
++count;
|
||||
parser::location_type loc (NULLPTR, unsigned (stage + 1), unsigned (stage + 1));
|
||||
switch (stage)
|
||||
{
|
||||
case 0:
|
||||
@@ -29,6 +29,7 @@ the scanner's.
|
||||
Local Variables:
|
||||
mode: outline
|
||||
fill-column: 76
|
||||
ispell-dictionary: "american"
|
||||
End:
|
||||
|
||||
Copyright (C) 2018 Free Software Foundation, Inc.
|
||||
@@ -48,4 +49,4 @@ 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/>.
|
||||
|
||||
# LocalWords: mfcalc calc parsers yy MERCHANTABILITY
|
||||
# LocalWords: mfcalc calc parsers yy MERCHANTABILITY Ctrl ispell american
|
||||
|
||||
@@ -19,7 +19,8 @@ cat >input <<EOF
|
||||
toto := 1
|
||||
toto
|
||||
EOF
|
||||
run 0 1 -s
|
||||
run 0 1
|
||||
run -noerr 0 1 -s
|
||||
|
||||
|
||||
cat >input <<EOF
|
||||
@@ -30,7 +31,7 @@ d := a + b * c
|
||||
d
|
||||
EOF
|
||||
run 0 7
|
||||
run 0 7 -p
|
||||
run -noerr 0 7 -p
|
||||
|
||||
|
||||
cat >input <<EOF
|
||||
@@ -47,4 +48,11 @@ cat >input <<EOF
|
||||
a := 1
|
||||
d := a + b * c
|
||||
EOF
|
||||
run 1 ''
|
||||
run 1 'err: -:3.1: syntax error, unexpected end of file, expecting ( or identifier or number'
|
||||
|
||||
|
||||
cat >input <<EOF
|
||||
a := 072101108108111044032119111114108100033
|
||||
a
|
||||
EOF
|
||||
run 1 'err: -:1.6-44: integer is out of range: 072101108108111044032119111114108100033'
|
||||
|
||||
+25
-27
@@ -1,18 +1,18 @@
|
||||
# Copyright (C) 2005-2006, 2008-2015, 2018 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/>.
|
||||
## Copyright (C) 2005-2006, 2008-2015, 2018 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/>.
|
||||
|
||||
## ------------------- ##
|
||||
## Parser generation. ##
|
||||
@@ -57,24 +57,22 @@ extracted += $(calcxx_extracted)
|
||||
calcxx_sources_generated = \
|
||||
%D%/parser.cc \
|
||||
%D%/parser.hh \
|
||||
%D%/location.hh \
|
||||
%D%/position.hh \
|
||||
%D%/stack.hh
|
||||
%D%/location.hh
|
||||
calcxx_sources = \
|
||||
$(calcxx_sources_extracted) \
|
||||
$(calcxx_sources_generated)
|
||||
|
||||
if FLEX_CXX_WORKS
|
||||
check_PROGRAMS += %D%/calc++
|
||||
nodist_%C%_calc___SOURCES = \
|
||||
$(calcxx_sources)
|
||||
|
||||
%C%_calc___CPPFLAGS = -I$(top_builddir)/%D%
|
||||
%C%_calc___CXXFLAGS = $(AM_CXXFLAGS) $(FLEX_SCANNER_CXXFLAGS)
|
||||
dist_TESTS += %D%/calc++.test
|
||||
else
|
||||
if ENABLE_CXX
|
||||
check_PROGRAMS += %D%/calc++
|
||||
nodist_%C%_calc___SOURCES = $(calcxx_sources)
|
||||
# Don't use gnulib's system headers.
|
||||
%C%_calc___CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
|
||||
%C%_calc___CXXFLAGS = $(AM_CXXFLAGS) $(FLEX_SCANNER_CXXFLAGS)
|
||||
TESTS += %D%/calc++.test
|
||||
endif ENABLE_CXX
|
||||
endif FLEX_CXX_WORKS
|
||||
EXTRA_DIST += %D%/calc++.test
|
||||
endif
|
||||
|
||||
|
||||
## ------------ ##
|
||||
|
||||
+41
-33
@@ -1,17 +1,17 @@
|
||||
# Copyright (C) 2005, 2008-2015, 2018 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/>.
|
||||
## Copyright (C) 2005, 2008-2015, 2018 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/>.
|
||||
|
||||
dist_noinst_SCRIPTS = %D%/extexi %D%/test
|
||||
TEST_LOG_COMPILER = $(top_srcdir)/%D%/test
|
||||
@@ -30,7 +30,8 @@ EXTEXIFLAGS = --synclines
|
||||
endif
|
||||
extract = VERSION="$(VERSION)" $(PERL) $(extexi) $(EXTEXIFLAGS) $(doc) --
|
||||
extracted =
|
||||
CLEANFILES += $(extracted) %D%/extracted.stamp
|
||||
EXTRA_DIST += $(extracted)
|
||||
MAINTAINERCLEANFILES += $(extracted) %D%/extracted.stamp
|
||||
%D%/extracted.stamp: $(doc) $(extexi)
|
||||
$(AM_V_GEN)rm -f $@ $@.tmp
|
||||
$(AM_V_at)$(MKDIR_P) %D%
|
||||
@@ -42,32 +43,39 @@ $(extracted): %D%/extracted.stamp
|
||||
@test -f $@ || rm -f %D%/extracted.stamp
|
||||
@test -f $@ || $(MAKE) $(AM_MAKEFLAGS) %D%/extracted.stamp
|
||||
|
||||
|
||||
## ------ ##
|
||||
## Dist. ##
|
||||
## ------ ##
|
||||
|
||||
# Ship the stamp file, otherwise it will be recreated, which is what
|
||||
# we want to avoid.
|
||||
EXTRA_DIST += %D%/extracted.stamp
|
||||
|
||||
# Suppress the #lines from the examples when rolling the tarball, so
|
||||
# that regular users have readable examples even before installing
|
||||
# Bison.
|
||||
dist-hook: examples-unline
|
||||
.PHONY: examples-unline
|
||||
examples-unline:
|
||||
for e in $(extracted); \
|
||||
do \
|
||||
e=$(distdir)/$$e; \
|
||||
sed -e '/#line/d' $$e >$$e.tmp; \
|
||||
mv -f $$e.tmp $$e; \
|
||||
done
|
||||
|
||||
|
||||
## ---------- ##
|
||||
## Examples. ##
|
||||
## ---------- ##
|
||||
|
||||
|
||||
examplesdir = $(docdir)/examples
|
||||
dist_examples_DATA = %D%/README %D%/variant.yy %D%/variant-11.yy
|
||||
dist_examples_DATA = %D%/README
|
||||
|
||||
check_PROGRAMS += %D%/variant
|
||||
nodist_%C%_variant_SOURCES = %D%/variant.yy
|
||||
%C%_variant_CPPFLAGS = -I$(top_builddir)
|
||||
dist_TESTS += %D%/variant.test
|
||||
%D%/variant.cc: $(BISON_IN) $(dist_pkgdata_DATA)
|
||||
|
||||
if ENABLE_CXX11
|
||||
check_PROGRAMS += %D%/variant-11
|
||||
nodist_%C%_variant_11_SOURCES = %D%/variant-11.yy
|
||||
%C%_variant_11_CXXFLAGS = $(CXX11_CXXFLAGS)
|
||||
%C%_variant_11_CPPFLAGS = -I$(top_builddir)
|
||||
dist_TESTS += %D%/variant-11.test
|
||||
%D%/variant-11.cc: $(BISON_IN) $(dist_pkgdata_DATA)
|
||||
endif
|
||||
|
||||
CLEANFILES += %D%/variant.output %D%/variant-11.output
|
||||
CLEANDIRS += %D%/*.dSYM
|
||||
|
||||
include %D%/calc++/local.mk
|
||||
include %D%/c++/local.mk
|
||||
include %D%/mfcalc/local.mk
|
||||
include %D%/rpcalc/local.mk
|
||||
|
||||
+17
-16
@@ -1,18 +1,18 @@
|
||||
# Copyright (C) 2005-2006, 2008-2015, 2018 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/>.
|
||||
## Copyright (C) 2005-2006, 2008-2015, 2018 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/>.
|
||||
|
||||
## -------------------- ##
|
||||
## Building & testing. ##
|
||||
@@ -28,7 +28,8 @@ extracted += $(mfcalc_extracted)
|
||||
|
||||
check_PROGRAMS += %D%/mfcalc
|
||||
nodist_%C%_mfcalc_SOURCES = $(mfcalc_sources)
|
||||
%C%_mfcalc_CPPFLAGS = -I$(top_builddir)/%D%
|
||||
# Don't use gnulib's system headers.
|
||||
%C%_mfcalc_CPPFLAGS = -I$(top_srcdir)/%D% -I$(top_builddir)/%D%
|
||||
%C%_mfcalc_LDADD = -lm
|
||||
|
||||
dist_TESTS += %D%/mfcalc.test
|
||||
|
||||
@@ -24,4 +24,4 @@ cat >input <<EOF
|
||||
(1+2) * 3
|
||||
EOF
|
||||
run 0 9
|
||||
run 0 9 -p
|
||||
run -noerr 0 9 -p
|
||||
|
||||
+16
-15
@@ -1,18 +1,18 @@
|
||||
# Copyright (C) 2005-2006, 2008-2015, 2018 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/>.
|
||||
## Copyright (C) 2005-2006, 2008-2015, 2018 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/>.
|
||||
|
||||
## -------------------- ##
|
||||
## Building & testing. ##
|
||||
@@ -28,6 +28,7 @@ extracted += $(rpcalc_extracted)
|
||||
|
||||
check_PROGRAMS += %D%/rpcalc
|
||||
nodist_%C%_rpcalc_SOURCES = $(rpcalc_sources)
|
||||
# Don't use gnulib's system headers.
|
||||
%C%_rpcalc_CPPFLAGS = -I$(top_builddir)/%D%
|
||||
%C%_rpcalc_LDADD = -lm
|
||||
|
||||
|
||||
+20
-13
@@ -15,7 +15,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
me=`basename $1 .test`
|
||||
me=$(basename "$1" .test)
|
||||
medir=$(basename "$(dirname "$1")")
|
||||
|
||||
# Number of the current test.
|
||||
number=1
|
||||
@@ -24,10 +25,10 @@ number=1
|
||||
exit=true
|
||||
|
||||
# top_builddir.
|
||||
cwd=`pwd`
|
||||
cwd=$(pwd)
|
||||
|
||||
# The exercised program.
|
||||
for p in $cwd/examples/$me/$me $cwd/examples/$me
|
||||
for p in "$cwd/examples/$medir/$me" "$cwd/examples/$me"
|
||||
do
|
||||
if test -x "$p"; then
|
||||
prog=$p
|
||||
@@ -44,7 +45,7 @@ fi
|
||||
# -------
|
||||
cleanup ()
|
||||
{
|
||||
local status=$?
|
||||
status=$?
|
||||
if test -z "$DEBUG"; then
|
||||
cd $cwd
|
||||
rm -rf $$.dir
|
||||
@@ -55,21 +56,27 @@ trap cleanup 0 1 2 13 15
|
||||
mkdir $$.dir
|
||||
cd $$.dir
|
||||
|
||||
# run EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS]
|
||||
# ---------------------------------------------------------
|
||||
# run [-noerr] EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS]
|
||||
# ------------------------------------------------------------------
|
||||
# -noerr: ignore stderr, otherwise merge it into effective output.
|
||||
run ()
|
||||
{
|
||||
noerr=false
|
||||
case $1 in
|
||||
(-noerr) noerr=true; shift;;
|
||||
esac
|
||||
|
||||
# Expected exit status.
|
||||
local sta_exp="$1"
|
||||
sta_exp=$1
|
||||
shift
|
||||
# Expected output.
|
||||
local out_exp="$1"
|
||||
out_exp=$1
|
||||
shift
|
||||
# Effective exit status.
|
||||
local sta_eff=0
|
||||
$prog "$@" - <input >out_eff || sta_eff=$?
|
||||
# Effective output.
|
||||
local out_eff="`cat out_eff`"
|
||||
sta_eff=0
|
||||
$prog "$@" - <input >out_eff 2>err_eff || sta_eff=$?
|
||||
# Combine effective output and error streams.
|
||||
out_eff=$(cat out_eff && $noerr || sed -e 's/^/err: /g' err_eff)
|
||||
if test $sta_eff -eq $sta_exp; then
|
||||
if test "$out_eff" = "$out_exp"; then
|
||||
echo "$me: PASS: $number"
|
||||
@@ -81,7 +88,7 @@ run ()
|
||||
echo "$me: FAIL: $number (expected status: $sta_exp, effective: $sta_eff)"
|
||||
exit=false
|
||||
fi
|
||||
number=`expr $number + 1`
|
||||
number=$(expr $number + 1)
|
||||
}
|
||||
|
||||
# We have cd'd one level deeper.
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#! /bin/sh
|
||||
|
||||
# Copyright (C) 2018 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/>.
|
||||
|
||||
: >input
|
||||
run 0 "{I have three numbers for you., 1, 2, 3, And that's all!}"
|
||||
+1
-1
Submodule gnulib updated: a79f2a2871...48a6c46b0b
+11
-24
@@ -35,7 +35,7 @@
|
||||
static bitset_bindex
|
||||
abitset_resize (bitset src, bitset_bindex size)
|
||||
{
|
||||
/* These bitsets have a fixed size. */
|
||||
/* These bitsets have a fixed size. */
|
||||
if (BITSET_SIZE_ (src) != size)
|
||||
abort ();
|
||||
|
||||
@@ -43,8 +43,8 @@ abitset_resize (bitset src, bitset_bindex size)
|
||||
}
|
||||
|
||||
/* Find list of up to NUM bits set in BSET starting from and including
|
||||
*NEXT and store in array LIST. Return with actual number of bits
|
||||
found and with *NEXT indicating where search stopped. */
|
||||
*NEXT and store in array LIST. Return with actual number of bits
|
||||
found and with *NEXT indicating where search stopped. */
|
||||
static bitset_bindex
|
||||
abitset_small_list (bitset src, bitset_bindex *list,
|
||||
bitset_bindex num, bitset_bindex *next)
|
||||
@@ -138,11 +138,10 @@ static bitset_bindex
|
||||
abitset_list_reverse (bitset src, bitset_bindex *list,
|
||||
bitset_bindex num, bitset_bindex *next)
|
||||
{
|
||||
bitset_bindex rbitno = *next;
|
||||
bitset_word *srcp = ABITSET_WORDS (src);
|
||||
bitset_bindex n_bits = BITSET_SIZE_ (src);
|
||||
|
||||
bitset_bindex rbitno = *next;
|
||||
|
||||
/* If num is 1, we could speed things up with a binary search
|
||||
of the word of interest. */
|
||||
|
||||
@@ -194,7 +193,6 @@ abitset_list (bitset src, bitset_bindex *list,
|
||||
bitset_bindex bitoff;
|
||||
bitset_windex size = src->b.csize;
|
||||
bitset_word *srcp = ABITSET_WORDS (src);
|
||||
bitset_word word;
|
||||
|
||||
bitset_bindex bitno = *next;
|
||||
|
||||
@@ -228,7 +226,7 @@ abitset_list (bitset src, bitset_bindex *list,
|
||||
on the previous call to this function. */
|
||||
|
||||
bitoff = windex * BITSET_WORD_BITS;
|
||||
word = srcp[windex] >> bitno;
|
||||
bitset_word word = srcp[windex] >> bitno;
|
||||
for (bitno = bitoff + bitno; word; bitno++)
|
||||
{
|
||||
if (word & 1)
|
||||
@@ -249,7 +247,8 @@ abitset_list (bitset src, bitset_bindex *list,
|
||||
|
||||
for (; windex < size; windex++, bitoff += BITSET_WORD_BITS)
|
||||
{
|
||||
if (!(word = srcp[windex]))
|
||||
bitset_word word = srcp[windex];
|
||||
if (!word)
|
||||
continue;
|
||||
|
||||
if ((count + BITSET_WORD_BITS) < num)
|
||||
@@ -324,7 +323,6 @@ abitset_empty_p (bitset dst)
|
||||
for (bitset_windex i = 0; i < dst->b.csize; i++)
|
||||
if (dstp[i])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -334,10 +332,9 @@ abitset_copy1 (bitset dst, bitset src)
|
||||
{
|
||||
bitset_word *srcp = ABITSET_WORDS (src);
|
||||
bitset_word *dstp = ABITSET_WORDS (dst);
|
||||
bitset_windex size = dst->b.csize;
|
||||
|
||||
if (srcp == dstp)
|
||||
return;
|
||||
return;
|
||||
bitset_windex size = dst->b.csize;
|
||||
memcpy (dstp, srcp, sizeof (bitset_word) * size);
|
||||
}
|
||||
|
||||
@@ -393,7 +390,6 @@ abitset_disjoint_p (bitset dst, bitset src)
|
||||
for (bitset_windex i = 0; i < size; i++)
|
||||
if (*srcp++ & *dstp++)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -423,7 +419,6 @@ abitset_and_cmp (bitset dst, bitset src1, bitset src2)
|
||||
for (bitset_windex i = 0; i < size; i++, dstp++)
|
||||
{
|
||||
bitset_word tmp = *src1p++ & *src2p++;
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = true;
|
||||
@@ -459,7 +454,6 @@ abitset_andn_cmp (bitset dst, bitset src1, bitset src2)
|
||||
for (bitset_windex i = 0; i < size; i++, dstp++)
|
||||
{
|
||||
bitset_word tmp = *src1p++ & ~(*src2p++);
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = true;
|
||||
@@ -515,7 +509,7 @@ abitset_xor (bitset dst, bitset src1, bitset src2)
|
||||
bitset_windex size = dst->b.csize;
|
||||
|
||||
for (bitset_windex i = 0; i < size; i++)
|
||||
*dstp++ = *src1p++ ^ *src2p++;
|
||||
*dstp++ = *src1p++ ^ *src2p++;
|
||||
}
|
||||
|
||||
|
||||
@@ -569,7 +563,6 @@ abitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
|
||||
for (bitset_windex i = 0; i < size; i++, dstp++)
|
||||
{
|
||||
bitset_word tmp = (*src1p++ & *src2p++) | *src3p++;
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = true;
|
||||
@@ -607,7 +600,6 @@ abitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
|
||||
for (bitset_windex i = 0; i < size; i++, dstp++)
|
||||
{
|
||||
bitset_word tmp = (*src1p++ & ~(*src2p++)) | *src3p++;
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = true;
|
||||
@@ -645,7 +637,6 @@ abitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
|
||||
for (bitset_windex i = 0; i < size; i++, dstp++)
|
||||
{
|
||||
bitset_word tmp = (*src1p++ | *src2p++) & *src3p++;
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = true;
|
||||
@@ -773,11 +764,7 @@ abitset_init (bitset bset, bitset_bindex n_bits)
|
||||
/* Use optimized routines if bitset fits within a single word.
|
||||
There is probably little merit if using caching since
|
||||
the small bitset will always fit in the cache. */
|
||||
if (size == 1)
|
||||
bset->b.vtable = &abitset_small_vtable;
|
||||
else
|
||||
bset->b.vtable = &abitset_vtable;
|
||||
|
||||
bset->b.vtable = size == 1 ? &abitset_small_vtable : &abitset_vtable;
|
||||
bset->b.cindex = 0;
|
||||
bset->b.csize = size;
|
||||
bset->b.cdata = ABITSET_WORDS (bset);
|
||||
|
||||
+11
-3
@@ -21,12 +21,20 @@
|
||||
#ifndef _BBITSET_H
|
||||
#define _BBITSET_H
|
||||
|
||||
#include "libiberty.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "xalloc.h"
|
||||
|
||||
#ifndef __attribute__
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
|
||||
# define __attribute__(x)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
|
||||
|
||||
/* Currently we support five flavours of bitsets:
|
||||
BITSET_ARRAY: Array of bits (fixed size, fast for dense bitsets).
|
||||
Memory for bit array and bitset structure allocated
|
||||
|
||||
+19
-25
@@ -24,12 +24,14 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "obstack.h"
|
||||
|
||||
#include "abitset.h"
|
||||
#include "lbitset.h"
|
||||
#include "ebitset.h"
|
||||
#include "vbitset.h"
|
||||
#include "bitset_stats.h"
|
||||
#include "obstack.h"
|
||||
|
||||
const char * const bitset_type_names[] = BITSET_TYPE_NAMES;
|
||||
|
||||
@@ -42,30 +44,23 @@ bitset_bytes (enum bitset_type type, bitset_bindex n_bits)
|
||||
if (bitset_stats_enabled)
|
||||
return bitset_stats_bytes ();
|
||||
|
||||
size_t bytes;
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
abort ();
|
||||
|
||||
case BITSET_ARRAY:
|
||||
bytes = abitset_bytes (n_bits);
|
||||
break;
|
||||
return abitset_bytes (n_bits);
|
||||
|
||||
case BITSET_LIST:
|
||||
bytes = lbitset_bytes (n_bits);
|
||||
break;
|
||||
return lbitset_bytes (n_bits);
|
||||
|
||||
case BITSET_TABLE:
|
||||
bytes = ebitset_bytes (n_bits);
|
||||
break;
|
||||
return ebitset_bytes (n_bits);
|
||||
|
||||
case BITSET_VARRAY:
|
||||
bytes = vbitset_bytes (n_bits);
|
||||
break;
|
||||
return vbitset_bytes (n_bits);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
@@ -193,7 +188,7 @@ bitset_type_get (bitset bset)
|
||||
{
|
||||
enum bitset_type type = BITSET_TYPE_ (bset);
|
||||
if (type != BITSET_STATS)
|
||||
return type;
|
||||
return type;
|
||||
|
||||
return bitset_stats_type_get (bset);
|
||||
}
|
||||
@@ -214,9 +209,8 @@ bitset_type_name_get (bitset bset)
|
||||
bitset_bindex
|
||||
bitset_next (bitset src, bitset_bindex bitno)
|
||||
{
|
||||
bitset_bindex val;
|
||||
bitset_bindex next = bitno;
|
||||
|
||||
bitset_bindex val;
|
||||
if (!bitset_list (src, &val, 1, &next))
|
||||
return BITSET_BINDEX_MAX;
|
||||
return val;
|
||||
@@ -236,9 +230,8 @@ bitset_compatible_p (bitset bset1, bitset bset2)
|
||||
bitset_bindex
|
||||
bitset_prev (bitset src, bitset_bindex bitno)
|
||||
{
|
||||
bitset_bindex val;
|
||||
bitset_bindex next = bitno;
|
||||
|
||||
bitset_bindex val;
|
||||
if (!bitset_list_reverse (src, &val, 1, &next))
|
||||
return BITSET_BINDEX_MAX;
|
||||
return val;
|
||||
@@ -295,7 +288,7 @@ bitset_print (FILE *file, bitset bset, bool verbose)
|
||||
|
||||
fprintf (file, "%lu ", (unsigned long) i);
|
||||
pos += 1 + (i >= 10) + (i >= 100);
|
||||
};
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
fprintf (file, "}\n");
|
||||
@@ -351,17 +344,18 @@ bitset_bindex
|
||||
bitset_count_ (bitset src)
|
||||
{
|
||||
bitset_bindex list[BITSET_LIST_SIZE];
|
||||
bitset_bindex num;
|
||||
bitset_bindex count;
|
||||
bitset_bindex count = 0;
|
||||
|
||||
/* This could be greatly sped up by adding a count method for each
|
||||
bitset implementation that uses a direct technique (based on
|
||||
masks) for counting the number of bits set in a word. */
|
||||
|
||||
bitset_bindex next = 0;
|
||||
for (count = 0; (num = bitset_list (src, list, BITSET_LIST_SIZE, &next));
|
||||
count += num)
|
||||
continue;
|
||||
{
|
||||
bitset_bindex next = 0;
|
||||
bitset_bindex num;
|
||||
while ((num = bitset_list (src, list, BITSET_LIST_SIZE, &next)))
|
||||
count += num;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
@@ -382,7 +376,7 @@ bitset_copy_ (bitset dst, bitset src)
|
||||
BITSET_FOR_EACH (iter, src, i, 0)
|
||||
{
|
||||
bitset_set (dst, i);
|
||||
};
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+5
-10
@@ -24,14 +24,14 @@
|
||||
/* This file is the public interface to the bitset abstract data type.
|
||||
Only use the functions and macros defined in this file. */
|
||||
|
||||
#include "bbitset.h"
|
||||
#include "obstack.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if USE_UNLOCKED_IO
|
||||
# include "unlocked-io.h"
|
||||
#endif
|
||||
|
||||
#include "bbitset.h"
|
||||
#include "obstack.h"
|
||||
|
||||
/* Attributes used to select a bitset implementation. */
|
||||
enum bitset_attr {BITSET_FIXED = 1, /* Bitset size fixed. */
|
||||
BITSET_VARIABLE = 2, /* Bitset size variable. */
|
||||
@@ -83,7 +83,6 @@ union bitset_union
|
||||
struct bbitset_struct b;
|
||||
bitset_windex size; /* Allocated size of array. */
|
||||
} v;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -309,9 +308,7 @@ void bitset_dump (FILE *, bitset);
|
||||
bitset_iterator iter;
|
||||
|
||||
BITSET_FOR_EACH (iter, src, i, 0)
|
||||
{
|
||||
printf ("%lu ", (unsigned long) i);
|
||||
};
|
||||
printf ("%lu ", (unsigned long) i);
|
||||
*/
|
||||
#define BITSET_FOR_EACH(ITER, BSET, INDEX, MIN) \
|
||||
for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \
|
||||
@@ -331,9 +328,7 @@ void bitset_dump (FILE *, bitset);
|
||||
bitset_iterator iter;
|
||||
|
||||
BITSET_FOR_EACH_REVERSE (iter, src, i, 0)
|
||||
{
|
||||
printf ("%lu ", (unsigned long) i);
|
||||
};
|
||||
printf ("%lu ", (unsigned long) i);
|
||||
*/
|
||||
#define BITSET_FOR_EACH_REVERSE(ITER, BSET, INDEX, MIN) \
|
||||
for (ITER.next = (MIN), ITER.num = BITSET_LIST_SIZE; \
|
||||
|
||||
+53
-42
@@ -29,18 +29,19 @@
|
||||
|
||||
#include "bitset_stats.h"
|
||||
|
||||
#include "bbitset.h"
|
||||
#include "abitset.h"
|
||||
#include "ebitset.h"
|
||||
#include "lbitset.h"
|
||||
#include "vbitset.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "gettext.h"
|
||||
#define _(Msgid) gettext (Msgid)
|
||||
|
||||
#include "abitset.h"
|
||||
#include "bbitset.h"
|
||||
#include "ebitset.h"
|
||||
#include "lbitset.h"
|
||||
#include "vbitset.h"
|
||||
|
||||
/* Configuration macros. */
|
||||
#define BITSET_STATS_FILE "bitset.dat"
|
||||
#define BITSET_LOG_COUNT_BINS 10
|
||||
@@ -371,7 +372,7 @@ bitset_stats_test (bitset src, bitset_bindex bitno)
|
||||
static bitset_bindex
|
||||
bitset_stats_resize (bitset src, bitset_bindex size)
|
||||
{
|
||||
return BITSET_RESIZE_ (src->s.bset, size);
|
||||
return BITSET_RESIZE_ (src->s.bset, size);
|
||||
}
|
||||
|
||||
|
||||
@@ -570,30 +571,36 @@ bitset_stats_list (bitset bset, bitset_bindex *list,
|
||||
|
||||
BITSET_STATS_LISTS_INC (bset->s.bset);
|
||||
|
||||
bitset_bindex tmp;
|
||||
bitset_bindex size;
|
||||
bitset_bindex i;
|
||||
|
||||
/* Log histogram of number of set bits. */
|
||||
for (i = 0, tmp = count; tmp; tmp >>= 1, i++)
|
||||
continue;
|
||||
if (i >= BITSET_LOG_COUNT_BINS)
|
||||
i = BITSET_LOG_COUNT_BINS - 1;
|
||||
BITSET_STATS_LIST_COUNTS_INC (bset->s.bset, i);
|
||||
{
|
||||
bitset_bindex i;
|
||||
bitset_bindex tmp;
|
||||
for (i = 0, tmp = count; tmp; tmp >>= 1, i++)
|
||||
continue;
|
||||
if (i >= BITSET_LOG_COUNT_BINS)
|
||||
i = BITSET_LOG_COUNT_BINS - 1;
|
||||
BITSET_STATS_LIST_COUNTS_INC (bset->s.bset, i);
|
||||
}
|
||||
|
||||
/* Log histogram of number of bits in set. */
|
||||
size = BITSET_SIZE_ (bset->s.bset);
|
||||
for (i = 0, tmp = size; tmp; tmp >>= 1, i++)
|
||||
continue;
|
||||
if (i >= BITSET_LOG_SIZE_BINS)
|
||||
i = BITSET_LOG_SIZE_BINS - 1;
|
||||
BITSET_STATS_LIST_SIZES_INC (bset->s.bset, i);
|
||||
bitset_bindex size = BITSET_SIZE_ (bset->s.bset);
|
||||
{
|
||||
bitset_bindex i;
|
||||
bitset_bindex tmp;
|
||||
for (i = 0, tmp = size; tmp; tmp >>= 1, i++)
|
||||
continue;
|
||||
if (i >= BITSET_LOG_SIZE_BINS)
|
||||
i = BITSET_LOG_SIZE_BINS - 1;
|
||||
BITSET_STATS_LIST_SIZES_INC (bset->s.bset, i);
|
||||
}
|
||||
|
||||
/* Histogram of fraction of bits set. */
|
||||
i = size ? (count * BITSET_DENSITY_BINS) / size : 0;
|
||||
if (i >= BITSET_DENSITY_BINS)
|
||||
i = BITSET_DENSITY_BINS - 1;
|
||||
BITSET_STATS_LIST_DENSITY_INC (bset->s.bset, i);
|
||||
{
|
||||
bitset_bindex i = size ? (count * BITSET_DENSITY_BINS) / size : 0;
|
||||
if (i >= BITSET_DENSITY_BINS)
|
||||
i = BITSET_DENSITY_BINS - 1;
|
||||
BITSET_STATS_LIST_DENSITY_INC (bset->s.bset, i);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -680,40 +687,44 @@ bitset_stats_init (bitset bset, bitset_bindex n_bits, enum bitset_type type)
|
||||
|
||||
/* Set up the actual bitset implementation that
|
||||
we are a wrapper over. */
|
||||
size_t bytes;
|
||||
bitset sbset;
|
||||
switch (type)
|
||||
{
|
||||
default:
|
||||
abort ();
|
||||
|
||||
case BITSET_ARRAY:
|
||||
bytes = abitset_bytes (n_bits);
|
||||
sbset = xcalloc (1, bytes);
|
||||
abitset_init (sbset, n_bits);
|
||||
{
|
||||
size_t bytes = abitset_bytes (n_bits);
|
||||
bset->s.bset = xcalloc (1, bytes);
|
||||
abitset_init (bset->s.bset, n_bits);
|
||||
}
|
||||
break;
|
||||
|
||||
case BITSET_LIST:
|
||||
bytes = lbitset_bytes (n_bits);
|
||||
sbset = xcalloc (1, bytes);
|
||||
lbitset_init (sbset, n_bits);
|
||||
{
|
||||
size_t bytes = lbitset_bytes (n_bits);
|
||||
bset->s.bset = xcalloc (1, bytes);
|
||||
lbitset_init (bset->s.bset, n_bits);
|
||||
}
|
||||
break;
|
||||
|
||||
case BITSET_TABLE:
|
||||
bytes = ebitset_bytes (n_bits);
|
||||
sbset = xcalloc (1, bytes);
|
||||
ebitset_init (sbset, n_bits);
|
||||
{
|
||||
size_t bytes = ebitset_bytes (n_bits);
|
||||
bset->s.bset = xcalloc (1, bytes);
|
||||
ebitset_init (bset->s.bset, n_bits);
|
||||
}
|
||||
break;
|
||||
|
||||
case BITSET_VARRAY:
|
||||
bytes = vbitset_bytes (n_bits);
|
||||
sbset = xcalloc (1, bytes);
|
||||
vbitset_init (sbset, n_bits);
|
||||
{
|
||||
size_t bytes = vbitset_bytes (n_bits);
|
||||
bset->s.bset = xcalloc (1, bytes);
|
||||
vbitset_init (bset->s.bset, n_bits);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
bset->s.bset = sbset;
|
||||
|
||||
BITSET_STATS_ALLOCS_INC (type);
|
||||
|
||||
return bset;
|
||||
|
||||
+4
-12
@@ -22,10 +22,11 @@
|
||||
|
||||
#include "ebitset.h"
|
||||
|
||||
#include "obstack.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "obstack.h"
|
||||
|
||||
/* This file implements expandable bitsets. These bitsets can be of
|
||||
arbitrary length and are more efficient than arrays of bits for
|
||||
large sparse sets.
|
||||
@@ -73,7 +74,7 @@ typedef ebitset_elt *ebitset_elts;
|
||||
/* Number of elements to initially allocate. */
|
||||
|
||||
#ifndef EBITSET_INITIAL_SIZE
|
||||
#define EBITSET_INITIAL_SIZE 2
|
||||
# define EBITSET_INITIAL_SIZE 2
|
||||
#endif
|
||||
|
||||
|
||||
@@ -131,8 +132,6 @@ ebitset_resize (bitset src, bitset_bindex n_bits)
|
||||
|
||||
if (oldsize < newsize)
|
||||
{
|
||||
bitset_windex size;
|
||||
|
||||
/* The bitset needs to grow. If we already have enough memory
|
||||
allocated, then just zero what we need. */
|
||||
if (newsize > EBITSET_ASIZE (src))
|
||||
@@ -142,11 +141,7 @@ ebitset_resize (bitset src, bitset_bindex n_bits)
|
||||
grow the bitset 25% larger than requested to reduce
|
||||
number of reallocations. */
|
||||
|
||||
if (oldsize == 0)
|
||||
size = newsize;
|
||||
else
|
||||
size = newsize + newsize / 4;
|
||||
|
||||
bitset_windex size = oldsize == 0 ? newsize : newsize + newsize / 4;
|
||||
EBITSET_ELTS (src)
|
||||
= realloc (EBITSET_ELTS (src), size * sizeof (ebitset_elt *));
|
||||
EBITSET_ASIZE (src) = size;
|
||||
@@ -274,7 +269,6 @@ ebitset_elt_zero_p (ebitset_elt *elt)
|
||||
for (int i = 0; i < EBITSET_ELT_WORDS; i++)
|
||||
if (EBITSET_WORDS (elt)[i])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -378,7 +372,6 @@ ebitset_zero (bitset bset)
|
||||
for (bitset_windex j = 0; j < EBITSET_SIZE (bset); j++)
|
||||
{
|
||||
ebitset_elt *elt = elts[j];
|
||||
|
||||
if (elt)
|
||||
ebitset_elt_remove (bset, j);
|
||||
}
|
||||
@@ -439,7 +432,6 @@ ebitset_copy_ (bitset dst, bitset src)
|
||||
for (bitset_windex j = 0; j < EBITSET_SIZE (src); j++)
|
||||
{
|
||||
ebitset_elt *selt = selts[j];
|
||||
|
||||
if (selt)
|
||||
{
|
||||
ebitset_elt *tmp = ebitset_elt_alloc ();
|
||||
|
||||
+41
-60
@@ -22,12 +22,13 @@
|
||||
|
||||
#include "lbitset.h"
|
||||
|
||||
#include "obstack.h"
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "obstack.h"
|
||||
|
||||
/* This file implements linked-list bitsets. These bitsets can be of
|
||||
arbitrary length and are more efficient than arrays of bits for
|
||||
large sparse sets.
|
||||
@@ -108,21 +109,21 @@ lbitset_elt_alloc (void)
|
||||
/* Let particular systems override the size of a chunk. */
|
||||
|
||||
#ifndef OBSTACK_CHUNK_SIZE
|
||||
#define OBSTACK_CHUNK_SIZE 0
|
||||
# define OBSTACK_CHUNK_SIZE 0
|
||||
#endif
|
||||
|
||||
/* Let them override the alloc and free routines too. */
|
||||
|
||||
#ifndef OBSTACK_CHUNK_ALLOC
|
||||
#define OBSTACK_CHUNK_ALLOC xmalloc
|
||||
# define OBSTACK_CHUNK_ALLOC xmalloc
|
||||
#endif
|
||||
|
||||
#ifndef OBSTACK_CHUNK_FREE
|
||||
#define OBSTACK_CHUNK_FREE free
|
||||
# define OBSTACK_CHUNK_FREE free
|
||||
#endif
|
||||
|
||||
#if ! defined __GNUC__ || __GNUC__ < 2
|
||||
#define __alignof__(type) 0
|
||||
# define __alignof__(type) 0
|
||||
#endif
|
||||
|
||||
obstack_specify_allocation (&lbitset_obstack, OBSTACK_CHUNK_SIZE,
|
||||
@@ -242,7 +243,6 @@ lbitset_elt_zero_p (lbitset_elt *elt)
|
||||
for (int i = 0; i < LBITSET_ELT_WORDS; i++)
|
||||
if (elt->words[i])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -253,11 +253,7 @@ lbitset_elt_link (bitset bset, lbitset_elt *elt)
|
||||
{
|
||||
bitset_windex windex = elt->index;
|
||||
|
||||
lbitset_elt *current;
|
||||
if (bset->b.csize)
|
||||
current = LBITSET_CURRENT (bset);
|
||||
else
|
||||
current = LBITSET_HEAD (bset);
|
||||
lbitset_elt *current = bset->b.csize ? LBITSET_CURRENT (bset) : LBITSET_HEAD (bset);
|
||||
|
||||
/* If this is the first and only element, add it in. */
|
||||
if (LBITSET_HEAD (bset) == 0)
|
||||
@@ -634,8 +630,8 @@ lbitset_list_reverse (bitset bset, bitset_bindex *list,
|
||||
|
||||
|
||||
/* Find list of up to NUM bits set in BSET starting from and including
|
||||
*NEXT and store in array LIST. Return with actual number of bits
|
||||
found and with *NEXT indicating where search stopped. */
|
||||
*NEXT and store in array LIST. Return with actual number of bits
|
||||
found and with *NEXT indicating where search stopped. */
|
||||
static bitset_bindex
|
||||
lbitset_list (bitset bset, bitset_bindex *list,
|
||||
bitset_bindex num, bitset_bindex *next)
|
||||
@@ -646,7 +642,6 @@ lbitset_list (bitset bset, bitset_bindex *list,
|
||||
|
||||
bitset_windex windex;
|
||||
lbitset_elt *elt;
|
||||
bitset_word word;
|
||||
|
||||
bitset_bindex bitno = *next;
|
||||
bitset_bindex count = 0;
|
||||
@@ -686,7 +681,7 @@ lbitset_list (bitset bset, bitset_bindex *list,
|
||||
|
||||
for (; (windex - elt->index) < LBITSET_ELT_WORDS; windex++)
|
||||
{
|
||||
word = srcp[windex - elt->index] >> (bitno % BITSET_WORD_BITS);
|
||||
bitset_word word = srcp[windex - elt->index] >> (bitno % BITSET_WORD_BITS);
|
||||
|
||||
for (; word; bitno++)
|
||||
{
|
||||
@@ -726,7 +721,7 @@ lbitset_list (bitset bset, bitset_bindex *list,
|
||||
/* The coast is clear, plant boot! */
|
||||
|
||||
#if LBITSET_ELT_WORDS == 2
|
||||
word = srcp[0];
|
||||
bitset_word word = srcp[0];
|
||||
if (word)
|
||||
{
|
||||
if (!(word & 0xffff))
|
||||
@@ -769,7 +764,7 @@ lbitset_list (bitset bset, bitset_bindex *list,
|
||||
#else
|
||||
for (int i = 0; i < LBITSET_ELT_WORDS; i++)
|
||||
{
|
||||
word = srcp[i];
|
||||
bitset_word word = srcp[i];
|
||||
if (word)
|
||||
{
|
||||
if (!(word & 0xffff))
|
||||
@@ -801,7 +796,7 @@ lbitset_list (bitset bset, bitset_bindex *list,
|
||||
|
||||
for (int i = 0; i < LBITSET_ELT_WORDS; i++)
|
||||
{
|
||||
for (word = srcp[i]; word; bitno++)
|
||||
for (bitset_word word = srcp[i]; word; bitno++)
|
||||
{
|
||||
if (word & 1)
|
||||
{
|
||||
@@ -842,12 +837,12 @@ lbitset_empty_p (bitset dst)
|
||||
{
|
||||
next = elt->next;
|
||||
if (!lbitset_elt_zero_p (elt))
|
||||
return 0;
|
||||
return false;
|
||||
/* Weed as we go. */
|
||||
lbitset_elt_unlink (dst, elt);
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -855,21 +850,14 @@ lbitset_empty_p (bitset dst)
|
||||
static inline void
|
||||
lbitset_unused_clear (bitset dst)
|
||||
{
|
||||
unsigned last_bit;
|
||||
bitset_bindex n_bits;
|
||||
|
||||
n_bits = BITSET_SIZE_ (dst);
|
||||
last_bit = n_bits % LBITSET_ELT_BITS;
|
||||
bitset_bindex n_bits = BITSET_SIZE_ (dst);
|
||||
unsigned last_bit = n_bits % LBITSET_ELT_BITS;
|
||||
|
||||
if (last_bit)
|
||||
{
|
||||
lbitset_elt *elt;
|
||||
bitset_windex windex;
|
||||
bitset_word *srcp;
|
||||
|
||||
elt = LBITSET_TAIL (dst);
|
||||
srcp = elt->words;
|
||||
windex = n_bits / BITSET_WORD_BITS;
|
||||
lbitset_elt *elt = LBITSET_TAIL (dst);
|
||||
bitset_word *srcp = elt->words;
|
||||
bitset_windex windex = n_bits / BITSET_WORD_BITS;
|
||||
|
||||
srcp[windex - elt->index] &= ((bitset_word) 1 << last_bit) - 1;
|
||||
windex++;
|
||||
@@ -920,7 +908,6 @@ lbitset_not (bitset dst, bitset src)
|
||||
}
|
||||
lbitset_unused_clear (dst);
|
||||
lbitset_weed (dst);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -995,13 +982,6 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op)
|
||||
lbitset_elt *selt1 = LBITSET_HEAD (src1);
|
||||
lbitset_elt *selt2 = LBITSET_HEAD (src2);
|
||||
lbitset_elt *delt = LBITSET_HEAD (dst);
|
||||
bitset_windex windex;
|
||||
lbitset_elt *stmp1;
|
||||
lbitset_elt *stmp2;
|
||||
lbitset_elt *dtmp;
|
||||
bitset_word *srcp1;
|
||||
bitset_word *srcp2;
|
||||
bitset_word *dstp;
|
||||
bool changed = false;
|
||||
|
||||
LBITSET_HEAD (dst) = 0;
|
||||
@@ -1012,6 +992,10 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op)
|
||||
|
||||
while (selt1 || selt2)
|
||||
{
|
||||
bitset_windex windex;
|
||||
lbitset_elt *stmp1;
|
||||
lbitset_elt *stmp2;
|
||||
|
||||
/* Figure out whether we need to substitute zero elements for
|
||||
missing links. */
|
||||
if (windex1 == windex2)
|
||||
@@ -1043,6 +1027,7 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op)
|
||||
|
||||
/* Find the appropriate element from DST. Begin by discarding
|
||||
elements that we've skipped. */
|
||||
lbitset_elt *dtmp;
|
||||
while (delt && delt->index < windex)
|
||||
{
|
||||
changed = true;
|
||||
@@ -1060,9 +1045,9 @@ lbitset_op3_cmp (bitset dst, bitset src1, bitset src2, enum bitset_ops op)
|
||||
|
||||
/* Do the operation, and if any bits are set, link it into the
|
||||
linked list. */
|
||||
srcp1 = stmp1->words;
|
||||
srcp2 = stmp2->words;
|
||||
dstp = dtmp->words;
|
||||
bitset_word *srcp1 = stmp1->words;
|
||||
bitset_word *srcp2 = stmp2->words;
|
||||
bitset_word *dstp = dtmp->words;
|
||||
switch (op)
|
||||
{
|
||||
default:
|
||||
@@ -1164,7 +1149,8 @@ lbitset_and_cmp (bitset dst, bitset src1, bitset src2)
|
||||
lbitset_zero (dst);
|
||||
return changed;
|
||||
}
|
||||
return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND);
|
||||
else
|
||||
return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_AND);
|
||||
}
|
||||
|
||||
|
||||
@@ -1192,7 +1178,8 @@ lbitset_andn_cmp (bitset dst, bitset src1, bitset src2)
|
||||
lbitset_zero (dst);
|
||||
return changed;
|
||||
}
|
||||
return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN);
|
||||
else
|
||||
return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_ANDN);
|
||||
}
|
||||
|
||||
|
||||
@@ -1210,14 +1197,11 @@ lbitset_or_cmp (bitset dst, bitset src1, bitset src2)
|
||||
lbitset_elt *selt2 = LBITSET_HEAD (src2);
|
||||
|
||||
if (!selt2)
|
||||
{
|
||||
return lbitset_copy_cmp (dst, src1);
|
||||
}
|
||||
return lbitset_copy_cmp (dst, src1);
|
||||
else if (!selt1)
|
||||
{
|
||||
return lbitset_copy_cmp (dst, src2);
|
||||
}
|
||||
return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR);
|
||||
return lbitset_copy_cmp (dst, src2);
|
||||
else
|
||||
return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_OR);
|
||||
}
|
||||
|
||||
|
||||
@@ -1235,14 +1219,11 @@ lbitset_xor_cmp (bitset dst, bitset src1, bitset src2)
|
||||
lbitset_elt *selt2 = LBITSET_HEAD (src2);
|
||||
|
||||
if (!selt2)
|
||||
{
|
||||
return lbitset_copy_cmp (dst, src1);
|
||||
}
|
||||
return lbitset_copy_cmp (dst, src1);
|
||||
else if (!selt1)
|
||||
{
|
||||
return lbitset_copy_cmp (dst, src2);
|
||||
}
|
||||
return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR);
|
||||
return lbitset_copy_cmp (dst, src2);
|
||||
else
|
||||
return lbitset_op3_cmp (dst, src1, src2, BITSET_OP_XOR);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/* Fake libiberty.h for Bison.
|
||||
|
||||
Copyright (C) 2002-2004, 2009-2015, 2018 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/>. */
|
||||
|
||||
|
||||
/* Bison depends on libiberty's implementation of bitsets, which
|
||||
requires a 'libiberty.h' file. This file provides the minimum
|
||||
services. */
|
||||
|
||||
#ifndef BISON_LIBIBERTY_H_
|
||||
# define BISON_LIBIBERTY_H_ 1
|
||||
|
||||
# ifndef __attribute__
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
|
||||
# define __attribute__(x)
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
|
||||
|
||||
# include "xalloc.h"
|
||||
|
||||
#endif /* ! BISON_LIBIBERTY_H_ */
|
||||
+17
-18
@@ -1,17 +1,17 @@
|
||||
# Copyright (C) 2001-2015, 2018 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/>.
|
||||
## Copyright (C) 2001-2015, 2018 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/>.
|
||||
|
||||
include lib/gnulib.mk
|
||||
|
||||
@@ -30,7 +30,6 @@ lib_libbison_a_SOURCES += \
|
||||
lib/ebitset.h \
|
||||
lib/lbitset.c \
|
||||
lib/lbitset.h \
|
||||
lib/libiberty.h \
|
||||
lib/vbitset.c \
|
||||
lib/vbitset.h
|
||||
|
||||
@@ -48,7 +47,7 @@ lib_libbison_a_SOURCES += \
|
||||
|
||||
# The Yacc compatibility library.
|
||||
if ENABLE_YACC
|
||||
lib_LIBRARIES = lib/liby.a
|
||||
EXTRA_LIBRARIES = lib/liby.a
|
||||
lib_liby_a_SOURCES = lib/main.c lib/yyerror.c
|
||||
lib_LIBRARIES = lib/liby.a
|
||||
EXTRA_LIBRARIES = lib/liby.a
|
||||
lib_liby_a_SOURCES = lib/main.c lib/yyerror.c
|
||||
endif
|
||||
|
||||
+65
-103
@@ -73,12 +73,7 @@ vbitset_resize (bitset src, bitset_bindex n_bits)
|
||||
grow the bitset 25% larger than requested to reduce
|
||||
number of reallocations. */
|
||||
|
||||
bitset_windex size;
|
||||
if (oldsize == 0)
|
||||
size = newsize;
|
||||
else
|
||||
size = newsize + newsize / 4;
|
||||
|
||||
bitset_windex size = oldsize == 0 ? newsize : newsize + newsize / 4;
|
||||
VBITSET_WORDS (src)
|
||||
= realloc (VBITSET_WORDS (src), size * sizeof (bitset_word));
|
||||
VBITSET_ASIZE (src) = size;
|
||||
@@ -142,7 +137,7 @@ vbitset_test (bitset src ATTRIBUTE_UNUSED,
|
||||
{
|
||||
/* We must be accessing outside the cache so the bit is
|
||||
zero anyway. */
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -206,15 +201,15 @@ static bitset_bindex
|
||||
vbitset_list (bitset src, bitset_bindex *list,
|
||||
bitset_bindex num, bitset_bindex *next)
|
||||
{
|
||||
bitset_windex windex;
|
||||
bitset_bindex bitoff;
|
||||
bitset_windex size = VBITSET_SIZE (src);
|
||||
bitset_word *srcp = VBITSET_WORDS (src);
|
||||
bitset_bindex bitno = *next;
|
||||
bitset_bindex count = 0;
|
||||
|
||||
bitset_windex windex;
|
||||
bitset_bindex bitoff;
|
||||
bitset_word word;
|
||||
|
||||
bitset_bindex bitno = *next;
|
||||
|
||||
bitset_bindex count = 0;
|
||||
if (!bitno)
|
||||
{
|
||||
/* Many bitsets are zero, so make this common case fast. */
|
||||
@@ -339,9 +334,8 @@ vbitset_empty_p (bitset dst)
|
||||
|
||||
for (unsigned i = 0; i < VBITSET_SIZE (dst); i++)
|
||||
if (dstp[i])
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -349,7 +343,7 @@ static void
|
||||
vbitset_copy1 (bitset dst, bitset src)
|
||||
{
|
||||
if (src == dst)
|
||||
return;
|
||||
return;
|
||||
|
||||
vbitset_resize (dst, BITSET_SIZE_ (src));
|
||||
|
||||
@@ -395,22 +389,22 @@ vbitset_equal_p (bitset dst, bitset src)
|
||||
unsigned i;
|
||||
for (i = 0; i < min (ssize, dsize); i++)
|
||||
if (*srcp++ != *dstp++)
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
if (ssize > dsize)
|
||||
{
|
||||
for (; i < ssize; i++)
|
||||
if (*srcp++)
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (; i < dsize; i++)
|
||||
if (*dstp++)
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -431,10 +425,10 @@ vbitset_subset_p (bitset dst, bitset src)
|
||||
{
|
||||
for (; i < ssize; i++)
|
||||
if (*srcp++)
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -448,9 +442,9 @@ vbitset_disjoint_p (bitset dst, bitset src)
|
||||
|
||||
for (unsigned i = 0; i < min (ssize, dsize); i++)
|
||||
if (*srcp++ & *dstp++)
|
||||
return 0;
|
||||
return false;
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -476,7 +470,7 @@ vbitset_and (bitset dst, bitset src1, bitset src2)
|
||||
static bool
|
||||
vbitset_and_cmp (bitset dst, bitset src1, bitset src2)
|
||||
{
|
||||
int changed = 0;
|
||||
bool changed = false;
|
||||
vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
|
||||
|
||||
bitset_windex dsize = VBITSET_SIZE (dst);
|
||||
@@ -493,7 +487,7 @@ vbitset_and_cmp (bitset dst, bitset src1, bitset src2)
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = 1;
|
||||
changed = true;
|
||||
*dstp = tmp;
|
||||
}
|
||||
}
|
||||
@@ -508,7 +502,7 @@ vbitset_and_cmp (bitset dst, bitset src1, bitset src2)
|
||||
{
|
||||
if (*dstp != 0)
|
||||
{
|
||||
changed = 1;
|
||||
changed = true;
|
||||
*dstp = 0;
|
||||
}
|
||||
}
|
||||
@@ -555,7 +549,7 @@ vbitset_andn (bitset dst, bitset src1, bitset src2)
|
||||
static bool
|
||||
vbitset_andn_cmp (bitset dst, bitset src1, bitset src2)
|
||||
{
|
||||
int changed = 0;
|
||||
bool changed = false;
|
||||
vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
|
||||
|
||||
bitset_windex dsize = VBITSET_SIZE (dst);
|
||||
@@ -572,7 +566,7 @@ vbitset_andn_cmp (bitset dst, bitset src1, bitset src2)
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = 1;
|
||||
changed = true;
|
||||
*dstp = tmp;
|
||||
}
|
||||
}
|
||||
@@ -583,7 +577,7 @@ vbitset_andn_cmp (bitset dst, bitset src1, bitset src2)
|
||||
{
|
||||
if (*dstp != 0)
|
||||
{
|
||||
changed = 1;
|
||||
changed = true;
|
||||
*dstp = 0;
|
||||
}
|
||||
}
|
||||
@@ -598,7 +592,7 @@ vbitset_andn_cmp (bitset dst, bitset src1, bitset src2)
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = 1;
|
||||
changed = true;
|
||||
*dstp = tmp;
|
||||
}
|
||||
}
|
||||
@@ -642,7 +636,7 @@ vbitset_or (bitset dst, bitset src1, bitset src2)
|
||||
static bool
|
||||
vbitset_or_cmp (bitset dst, bitset src1, bitset src2)
|
||||
{
|
||||
int changed = 0;
|
||||
bool changed = false;
|
||||
|
||||
vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
|
||||
|
||||
@@ -660,7 +654,7 @@ vbitset_or_cmp (bitset dst, bitset src1, bitset src2)
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = 1;
|
||||
changed = true;
|
||||
*dstp = tmp;
|
||||
}
|
||||
}
|
||||
@@ -677,7 +671,7 @@ vbitset_or_cmp (bitset dst, bitset src1, bitset src2)
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = 1;
|
||||
changed = true;
|
||||
*dstp = tmp;
|
||||
}
|
||||
}
|
||||
@@ -720,7 +714,7 @@ vbitset_xor (bitset dst, bitset src1, bitset src2)
|
||||
static bool
|
||||
vbitset_xor_cmp (bitset dst, bitset src1, bitset src2)
|
||||
{
|
||||
int changed = 0;
|
||||
bool changed = false;
|
||||
vbitset_resize (dst, max (BITSET_SIZE_ (src1), BITSET_SIZE_ (src2)));
|
||||
|
||||
bitset_windex dsize = VBITSET_SIZE (dst);
|
||||
@@ -737,7 +731,7 @@ vbitset_xor_cmp (bitset dst, bitset src1, bitset src2)
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = 1;
|
||||
changed = true;
|
||||
*dstp = tmp;
|
||||
}
|
||||
}
|
||||
@@ -754,7 +748,7 @@ vbitset_xor_cmp (bitset dst, bitset src1, bitset src2)
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = 1;
|
||||
changed = true;
|
||||
*dstp = tmp;
|
||||
}
|
||||
}
|
||||
@@ -771,12 +765,6 @@ vbitset_xor_cmp (bitset dst, bitset src1, bitset src2)
|
||||
static void
|
||||
vbitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3)
|
||||
{
|
||||
bitset_word *src1p;
|
||||
bitset_word *src2p;
|
||||
bitset_word *src3p;
|
||||
bitset_word *dstp;
|
||||
bitset_windex size;
|
||||
|
||||
if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
|
||||
|| BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
|
||||
{
|
||||
@@ -786,11 +774,11 @@ vbitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3)
|
||||
|
||||
vbitset_resize (dst, BITSET_NBITS_ (src1));
|
||||
|
||||
src1p = VBITSET_WORDS (src1);
|
||||
src2p = VBITSET_WORDS (src2);
|
||||
src3p = VBITSET_WORDS (src3);
|
||||
dstp = VBITSET_WORDS (dst);
|
||||
size = VBITSET_SIZE (dst);
|
||||
bitset_word *src1p = VBITSET_WORDS (src1);
|
||||
bitset_word *src2p = VBITSET_WORDS (src2);
|
||||
bitset_word *src3p = VBITSET_WORDS (src3);
|
||||
bitset_word *dstp = VBITSET_WORDS (dst);
|
||||
bitset_windex size = VBITSET_SIZE (dst);
|
||||
|
||||
for (unsigned i = 0; i < size; i++)
|
||||
*dstp++ = (*src1p++ & *src2p++) | *src3p++;
|
||||
@@ -800,32 +788,26 @@ vbitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3)
|
||||
static bool
|
||||
vbitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
|
||||
{
|
||||
int changed = 0;
|
||||
bitset_word *src1p;
|
||||
bitset_word *src2p;
|
||||
bitset_word *src3p;
|
||||
bitset_word *dstp;
|
||||
bitset_windex size;
|
||||
|
||||
if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
|
||||
|| BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
|
||||
return bitset_and_or_cmp_ (dst, src1, src2, src3);
|
||||
|
||||
vbitset_resize (dst, BITSET_NBITS_ (src1));
|
||||
|
||||
src1p = VBITSET_WORDS (src1);
|
||||
src2p = VBITSET_WORDS (src2);
|
||||
src3p = VBITSET_WORDS (src3);
|
||||
dstp = VBITSET_WORDS (dst);
|
||||
size = VBITSET_SIZE (dst);
|
||||
bitset_word *src1p = VBITSET_WORDS (src1);
|
||||
bitset_word *src2p = VBITSET_WORDS (src2);
|
||||
bitset_word *src3p = VBITSET_WORDS (src3);
|
||||
bitset_word *dstp = VBITSET_WORDS (dst);
|
||||
bitset_windex size = VBITSET_SIZE (dst);
|
||||
|
||||
bool changed = false;
|
||||
for (unsigned i = 0; i < size; i++, dstp++)
|
||||
{
|
||||
bitset_word tmp = (*src1p++ & *src2p++) | *src3p++;
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = 1;
|
||||
changed = true;
|
||||
*dstp = tmp;
|
||||
}
|
||||
}
|
||||
@@ -836,12 +818,6 @@ vbitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
|
||||
static void
|
||||
vbitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3)
|
||||
{
|
||||
bitset_word *src1p;
|
||||
bitset_word *src2p;
|
||||
bitset_word *src3p;
|
||||
bitset_word *dstp;
|
||||
bitset_windex size;
|
||||
|
||||
if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
|
||||
|| BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
|
||||
{
|
||||
@@ -851,11 +827,11 @@ vbitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3)
|
||||
|
||||
vbitset_resize (dst, BITSET_NBITS_ (src1));
|
||||
|
||||
src1p = VBITSET_WORDS (src1);
|
||||
src2p = VBITSET_WORDS (src2);
|
||||
src3p = VBITSET_WORDS (src3);
|
||||
dstp = VBITSET_WORDS (dst);
|
||||
size = VBITSET_SIZE (dst);
|
||||
bitset_word *src1p = VBITSET_WORDS (src1);
|
||||
bitset_word *src2p = VBITSET_WORDS (src2);
|
||||
bitset_word *src3p = VBITSET_WORDS (src3);
|
||||
bitset_word *dstp = VBITSET_WORDS (dst);
|
||||
bitset_windex size = VBITSET_SIZE (dst);
|
||||
|
||||
for (unsigned i = 0; i < size; i++)
|
||||
*dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++;
|
||||
@@ -865,32 +841,26 @@ vbitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3)
|
||||
static bool
|
||||
vbitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
|
||||
{
|
||||
int changed = 0;
|
||||
bitset_word *src1p;
|
||||
bitset_word *src2p;
|
||||
bitset_word *src3p;
|
||||
bitset_word *dstp;
|
||||
bitset_windex size;
|
||||
|
||||
if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
|
||||
|| BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
|
||||
return bitset_andn_or_cmp_ (dst, src1, src2, src3);
|
||||
|
||||
vbitset_resize (dst, BITSET_NBITS_ (src1));
|
||||
|
||||
src1p = VBITSET_WORDS (src1);
|
||||
src2p = VBITSET_WORDS (src2);
|
||||
src3p = VBITSET_WORDS (src3);
|
||||
dstp = VBITSET_WORDS (dst);
|
||||
size = VBITSET_SIZE (dst);
|
||||
bitset_word *src1p = VBITSET_WORDS (src1);
|
||||
bitset_word *src2p = VBITSET_WORDS (src2);
|
||||
bitset_word *src3p = VBITSET_WORDS (src3);
|
||||
bitset_word *dstp = VBITSET_WORDS (dst);
|
||||
bitset_windex size = VBITSET_SIZE (dst);
|
||||
|
||||
bool changed = false;
|
||||
for (unsigned i = 0; i < size; i++, dstp++)
|
||||
{
|
||||
bitset_word tmp = (*src1p++ & ~(*src2p++)) | *src3p++;
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = 1;
|
||||
changed = true;
|
||||
*dstp = tmp;
|
||||
}
|
||||
}
|
||||
@@ -924,33 +894,27 @@ vbitset_or_and (bitset dst, bitset src1, bitset src2, bitset src3)
|
||||
static bool
|
||||
vbitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3)
|
||||
{
|
||||
unsigned i;
|
||||
int changed = 0;
|
||||
bitset_word *src1p;
|
||||
bitset_word *src2p;
|
||||
bitset_word *src3p;
|
||||
bitset_word *dstp;
|
||||
bitset_windex size;
|
||||
|
||||
if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
|
||||
|| BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
|
||||
return bitset_or_and_cmp_ (dst, src1, src2, src3);
|
||||
|
||||
vbitset_resize (dst, BITSET_NBITS_ (src1));
|
||||
|
||||
src1p = VBITSET_WORDS (src1);
|
||||
src2p = VBITSET_WORDS (src2);
|
||||
src3p = VBITSET_WORDS (src3);
|
||||
dstp = VBITSET_WORDS (dst);
|
||||
size = VBITSET_SIZE (dst);
|
||||
bitset_word *src1p = VBITSET_WORDS (src1);
|
||||
bitset_word *src2p = VBITSET_WORDS (src2);
|
||||
bitset_word *src3p = VBITSET_WORDS (src3);
|
||||
bitset_word *dstp = VBITSET_WORDS (dst);
|
||||
bitset_windex size = VBITSET_SIZE (dst);
|
||||
|
||||
unsigned i;
|
||||
bool changed = false;
|
||||
for (i = 0; i < size; i++, dstp++)
|
||||
{
|
||||
bitset_word tmp = (*src1p++ | *src2p++) & *src3p++;
|
||||
|
||||
if (*dstp != tmp)
|
||||
{
|
||||
changed = 1;
|
||||
changed = true;
|
||||
*dstp = tmp;
|
||||
}
|
||||
}
|
||||
@@ -962,9 +926,9 @@ static void
|
||||
vbitset_copy (bitset dst, bitset src)
|
||||
{
|
||||
if (BITSET_COMPATIBLE_ (dst, src))
|
||||
vbitset_copy1 (dst, src);
|
||||
vbitset_copy1 (dst, src);
|
||||
else
|
||||
bitset_copy_ (dst, src);
|
||||
bitset_copy_ (dst, src);
|
||||
}
|
||||
|
||||
|
||||
@@ -1017,9 +981,7 @@ bitset
|
||||
vbitset_init (bitset bset, bitset_bindex n_bits)
|
||||
{
|
||||
bset->b.vtable = &vbitset_vtable;
|
||||
|
||||
bset->b.cindex = 0;
|
||||
|
||||
VBITSET_SIZE (bset) = 0;
|
||||
vbitset_resize (bset, n_bits);
|
||||
return bset;
|
||||
|
||||
@@ -190,3 +190,4 @@
|
||||
/localtime-buffer.m4
|
||||
/sys_resource_h.m4
|
||||
/timespec.m4
|
||||
/intl-thread-locale.m4
|
||||
|
||||
@@ -50,14 +50,12 @@ AC_DEFUN([BISON_TEST_FOR_WORKING_CXX_COMPILER],
|
||||
AC_LANG_POP([C++])])
|
||||
|
||||
case $bison_cv_cxx_works in
|
||||
yes)
|
||||
BISON_CXX_WORKS=':';;
|
||||
no | cross)
|
||||
BISON_CXX_WORKS='exit 77';;
|
||||
yes) BISON_CXX_WORKS=':';;
|
||||
no | cross) BISON_CXX_WORKS='false';;
|
||||
esac
|
||||
|
||||
AC_SUBST([BISON_CXX_WORKS])
|
||||
AM_CONDITIONAL(BISON_CXX_WORKS, test $bison_cv_cxx_works = yes)
|
||||
AM_CONDITIONAL([ENABLE_CXX], [test $bison_cv_cxx_works = yes])
|
||||
])
|
||||
|
||||
# BISON_CXX_COMPILER_POSIXLY_CORRECT
|
||||
|
||||
+60
-85
@@ -168,10 +168,9 @@ AnnotationList__compute_conflicted_tokens (bitset shift_tokens,
|
||||
bitset conflicted_tokens = bitset_create (ntokens, BITSET_FIXED);
|
||||
bitset conflicted_tokens_rule = bitset_create (ntokens, BITSET_FIXED);
|
||||
bitset tokens = bitset_create (ntokens, BITSET_FIXED);
|
||||
int i;
|
||||
|
||||
bitset_copy (tokens, shift_tokens);
|
||||
for (i = 0; i < reds->num; ++i)
|
||||
for (int i = 0; i < reds->num; ++i)
|
||||
{
|
||||
bitset_and (conflicted_tokens_rule, tokens, reds->lookahead_tokens[i]);
|
||||
bitset_or (conflicted_tokens,
|
||||
@@ -215,20 +214,17 @@ AnnotationList__compute_lhs_contributions (state *s, rule *the_rule,
|
||||
}
|
||||
|
||||
static void
|
||||
AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s,
|
||||
bitsetv follow_kernel_items,
|
||||
bitsetv always_follows,
|
||||
state ***predecessors,
|
||||
bitset **item_lookahead_sets,
|
||||
AnnotationList
|
||||
**annotation_lists,
|
||||
AnnotationIndex
|
||||
*annotation_counts,
|
||||
struct obstack
|
||||
*annotations_obstackp)
|
||||
AnnotationList__computePredecessorAnnotations (
|
||||
AnnotationList *self, state *s,
|
||||
bitsetv follow_kernel_items,
|
||||
bitsetv always_follows,
|
||||
state ***predecessors,
|
||||
bitset **item_lookahead_sets,
|
||||
AnnotationList **annotation_lists,
|
||||
AnnotationIndex *annotation_counts,
|
||||
struct obstack *annotations_obstackp)
|
||||
{
|
||||
state **predecessor;
|
||||
for (predecessor = predecessors[s->number]; *predecessor; ++predecessor)
|
||||
for (state **predecessor = predecessors[s->number]; *predecessor; ++predecessor)
|
||||
{
|
||||
AnnotationList *annotation_node =
|
||||
AnnotationList__alloc_on_obstack (
|
||||
@@ -237,8 +233,7 @@ AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s,
|
||||
bool potential_contribution = false;
|
||||
bitset *lookaheads = NULL;
|
||||
{
|
||||
ContributionIndex ci;
|
||||
for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
|
||||
for (ContributionIndex ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
|
||||
{
|
||||
symbol_number contribution_token =
|
||||
InadequacyList__getContributionToken (self->inadequacyNode, ci)
|
||||
@@ -274,12 +269,12 @@ AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s,
|
||||
if (item_number_is_rule_number (ritem[s->items[self_item]
|
||||
- 2]))
|
||||
{
|
||||
Sbitset items;
|
||||
unsigned rulei;
|
||||
for (rulei = s->items[self_item];
|
||||
!item_number_is_rule_number (ritem[rulei]);
|
||||
++rulei)
|
||||
;
|
||||
continue;
|
||||
Sbitset items;
|
||||
if (AnnotationList__compute_lhs_contributions (
|
||||
*predecessor,
|
||||
&rules[item_number_as_rule_number (ritem[rulei])],
|
||||
@@ -334,10 +329,9 @@ AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s,
|
||||
potential_contribution = true;
|
||||
if (!lookaheads)
|
||||
{
|
||||
size_t j;
|
||||
lookaheads = xnmalloc ((*predecessor)->nitems,
|
||||
sizeof *lookaheads);
|
||||
for (j = 0; j < (*predecessor)->nitems; ++j)
|
||||
for (size_t j = 0; j < (*predecessor)->nitems; ++j)
|
||||
lookaheads[j] = NULL;
|
||||
}
|
||||
if (!lookaheads[i])
|
||||
@@ -377,8 +371,7 @@ AnnotationList__computePredecessorAnnotations (AnnotationList *self, state *s,
|
||||
annotation_node = NULL;
|
||||
}
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < (*predecessor)->nitems; ++i)
|
||||
for (size_t i = 0; i < (*predecessor)->nitems; ++i)
|
||||
if (lookaheads[i])
|
||||
bitset_free (lookaheads[i]);
|
||||
free (lookaheads);
|
||||
@@ -416,23 +409,19 @@ AnnotationList__compute_from_inadequacies (
|
||||
struct obstack *annotations_obstackp,
|
||||
InadequacyListNodeCount *inadequacy_list_node_count)
|
||||
{
|
||||
bitsetv all_lookaheads;
|
||||
bitset shift_tokens;
|
||||
bitset conflicted_tokens;
|
||||
bitset_iterator biter_conflict;
|
||||
bitset_bindex conflicted_token;
|
||||
|
||||
/* Return an empty list if s->lookahead_tokens = NULL. */
|
||||
if (s->consistent)
|
||||
return;
|
||||
|
||||
all_lookaheads = bitsetv_create (s->nitems, ntokens, BITSET_FIXED);
|
||||
bitsetv all_lookaheads = bitsetv_create (s->nitems, ntokens, BITSET_FIXED);
|
||||
bitsetv_ones (all_lookaheads);
|
||||
shift_tokens = AnnotationList__compute_shift_tokens (s->transitions);
|
||||
conflicted_tokens =
|
||||
bitset shift_tokens = AnnotationList__compute_shift_tokens (s->transitions);
|
||||
bitset conflicted_tokens =
|
||||
AnnotationList__compute_conflicted_tokens (shift_tokens, s->reductions);
|
||||
|
||||
/* Add an inadequacy annotation for each conflicted_token. */
|
||||
bitset_iterator biter_conflict;
|
||||
bitset_bindex conflicted_token;
|
||||
BITSET_FOR_EACH (biter_conflict, conflicted_tokens, conflicted_token, 0)
|
||||
{
|
||||
AnnotationList *annotation_node;
|
||||
@@ -444,8 +433,7 @@ AnnotationList__compute_from_inadequacies (
|
||||
|
||||
/* Allocate the annotation node. */
|
||||
{
|
||||
int rule_i;
|
||||
for (rule_i = 0; rule_i < s->reductions->num; ++rule_i)
|
||||
for (int rule_i = 0; rule_i < s->reductions->num; ++rule_i)
|
||||
if (bitset_test (s->reductions->lookahead_tokens[rule_i],
|
||||
conflicted_token))
|
||||
++contribution_count;
|
||||
@@ -461,8 +449,7 @@ AnnotationList__compute_from_inadequacies (
|
||||
{
|
||||
ContributionIndex ci = 0;
|
||||
int item_i = 0;
|
||||
int rule_i;
|
||||
for (rule_i = 0; rule_i < s->reductions->num; ++rule_i)
|
||||
for (int rule_i = 0; rule_i < s->reductions->num; ++rule_i)
|
||||
{
|
||||
rule *the_rule = s->reductions->rules[rule_i];
|
||||
if (bitset_test (s->reductions->lookahead_tokens[rule_i],
|
||||
@@ -584,27 +571,20 @@ AnnotationList__debug (AnnotationList const *self, size_t nitems, int spaces)
|
||||
AnnotationIndex ai;
|
||||
for (a = self, ai = 0; a; a = a->next, ++ai)
|
||||
{
|
||||
{
|
||||
int j;
|
||||
for (j = 0; j < spaces; ++j)
|
||||
putc (' ', stderr);
|
||||
}
|
||||
for (int j = 0; j < spaces; ++j)
|
||||
putc (' ', stderr);
|
||||
fprintf (stderr, "Annotation %d (manifesting state %d):\n",
|
||||
ai, a->inadequacyNode->manifestingState->number);
|
||||
{
|
||||
ContributionIndex ci;
|
||||
bitset_bindex rulei = 0; /* init suppresses compiler warning */
|
||||
rulei = bitset_first (a->inadequacyNode->inadequacy.conflict.actions);
|
||||
for (ci = 0; ci < a->inadequacyNode->contributionCount; ++ci)
|
||||
bitset_bindex rulei
|
||||
= bitset_first (a->inadequacyNode->inadequacy.conflict.actions);
|
||||
for (ContributionIndex ci = 0; ci < a->inadequacyNode->contributionCount; ++ci)
|
||||
{
|
||||
symbol_number token =
|
||||
InadequacyList__getContributionToken (a->inadequacyNode, ci)
|
||||
->content->number;
|
||||
{
|
||||
int j;
|
||||
for (j = 0; j < spaces+2; ++j)
|
||||
putc (' ', stderr);
|
||||
}
|
||||
for (int j = 0; j < spaces+2; ++j)
|
||||
putc (' ', stderr);
|
||||
if (ci == InadequacyList__getShiftContributionIndex (
|
||||
a->inadequacyNode))
|
||||
fprintf (stderr, "Contributes shift of token %d.\n", token);
|
||||
@@ -639,20 +619,17 @@ AnnotationList__computeLookaheadFilter (AnnotationList const *self,
|
||||
{
|
||||
bitsetv_zero (lookahead_filter);
|
||||
for (; self; self = self->next)
|
||||
{
|
||||
ContributionIndex ci;
|
||||
for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
|
||||
if (!AnnotationList__isContributionAlways (self, ci))
|
||||
{
|
||||
Sbitset__Index item;
|
||||
Sbitset biter;
|
||||
symbol_number token =
|
||||
InadequacyList__getContributionToken (self->inadequacyNode, ci)
|
||||
->content->number;
|
||||
SBITSET__FOR_EACH (self->contributions[ci], nitems, biter, item)
|
||||
bitset_set (lookahead_filter[item], token);
|
||||
}
|
||||
}
|
||||
for (ContributionIndex ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
|
||||
if (!AnnotationList__isContributionAlways (self, ci))
|
||||
{
|
||||
symbol_number token =
|
||||
InadequacyList__getContributionToken (self->inadequacyNode, ci)
|
||||
->content->number;
|
||||
Sbitset__Index item;
|
||||
Sbitset biter;
|
||||
SBITSET__FOR_EACH (self->contributions[ci], nitems, biter, item)
|
||||
bitset_set (lookahead_filter[item], token);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -699,11 +676,10 @@ AnnotationList__computeDominantContribution (AnnotationList const *self,
|
||||
size_t nitems, bitset *lookaheads,
|
||||
bool require_split_stable)
|
||||
{
|
||||
symbol *token;
|
||||
ContributionIndex const ci_shift =
|
||||
InadequacyList__getShiftContributionIndex (self->inadequacyNode);
|
||||
|
||||
token = self->inadequacyNode->inadequacy.conflict.token;
|
||||
symbol *token = self->inadequacyNode->inadequacy.conflict.token;
|
||||
|
||||
/* S/R conflict. */
|
||||
if (ci_shift != ContributionIndex__none)
|
||||
@@ -711,9 +687,6 @@ AnnotationList__computeDominantContribution (AnnotationList const *self,
|
||||
bool find_stable_domination_over_shift = false;
|
||||
bool find_stable_error_action_domination = false;
|
||||
{
|
||||
ContributionIndex ci;
|
||||
int actioni;
|
||||
ContributionIndex ci_rr_dominator = ContributionIndex__none;
|
||||
int shift_precedence = token->content->prec;
|
||||
|
||||
/* If the token has no precedence set, shift is always chosen. */
|
||||
@@ -723,11 +696,16 @@ AnnotationList__computeDominantContribution (AnnotationList const *self,
|
||||
/* Figure out which reductions contribute, which of those would
|
||||
dominate in a R/R comparison, and whether any reduction dominates
|
||||
the shift so that the R/R comparison is actually needed. */
|
||||
for (ci = 0, actioni = bitset_first (self->inadequacyNode->inadequacy
|
||||
.conflict.actions);
|
||||
ContributionIndex ci_rr_dominator = ContributionIndex__none;
|
||||
int actioni;
|
||||
ContributionIndex ci;
|
||||
for (ci = 0,
|
||||
actioni = bitset_first (self->inadequacyNode->inadequacy
|
||||
.conflict.actions);
|
||||
ci < self->inadequacyNode->contributionCount;
|
||||
++ci, actioni = bitset_next (self->inadequacyNode->inadequacy
|
||||
.conflict.actions, actioni+1))
|
||||
++ci,
|
||||
actioni = bitset_next (self->inadequacyNode->inadequacy
|
||||
.conflict.actions, actioni+1))
|
||||
{
|
||||
int reduce_precedence = 0;
|
||||
if (ci == ci_shift)
|
||||
@@ -796,17 +774,14 @@ AnnotationList__computeDominantContribution (AnnotationList const *self,
|
||||
|
||||
/* R/R conflict, so the reduction with the lowest rule number dominates.
|
||||
Fortunately, contributions are sorted by rule number. */
|
||||
{
|
||||
ContributionIndex ci;
|
||||
for (ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
|
||||
if (AnnotationList__stateMakesContribution (self, nitems, ci,
|
||||
lookaheads))
|
||||
{
|
||||
if (require_split_stable
|
||||
&& !AnnotationList__isContributionAlways (self, ci))
|
||||
return ContributionIndex__none;
|
||||
return ci;
|
||||
}
|
||||
}
|
||||
for (ContributionIndex ci = 0; ci < self->inadequacyNode->contributionCount; ++ci)
|
||||
if (AnnotationList__stateMakesContribution (self, nitems, ci,
|
||||
lookaheads))
|
||||
{
|
||||
if (require_split_stable
|
||||
&& !AnnotationList__isContributionAlways (self, ci))
|
||||
return ContributionIndex__none;
|
||||
return ci;
|
||||
}
|
||||
return ContributionIndex__none;
|
||||
}
|
||||
|
||||
+32
-25
@@ -1,27 +1,17 @@
|
||||
# Copyright (C) 2001-2015, 2018 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/>.
|
||||
|
||||
LDADD = \
|
||||
$(ISNAND_LIBM) \
|
||||
$(ISNANF_LIBM) \
|
||||
$(ISNANL_LIBM) \
|
||||
$(LDEXPL_LIBM) \
|
||||
$(LDEXP_LIBM) \
|
||||
$(LIBINTL) \
|
||||
$(LIBTHREAD) \
|
||||
lib/libbison.a
|
||||
## Copyright (C) 2001-2015, 2018 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/>.
|
||||
|
||||
bin_PROGRAMS = src/bison
|
||||
# Prettify Automake-computed names of compiled objects.
|
||||
@@ -114,13 +104,30 @@ BUILT_SOURCES += \
|
||||
src/scan-gram.c \
|
||||
src/scan-skel.c
|
||||
|
||||
# Although conceptually most of these guys would make more sense in the
|
||||
# definition of libbison, beware that they might expand as flags such as
|
||||
# `-lm`. Keep them here. Or use a Libtool convenience library.
|
||||
src_bison_LDADD = \
|
||||
$(ISNAND_LIBM) \
|
||||
$(ISNANF_LIBM) \
|
||||
$(ISNANL_LIBM) \
|
||||
$(LDEXPL_LIBM) \
|
||||
$(LDEXP_LIBM) \
|
||||
$(LIBINTL) \
|
||||
$(LIBTHREAD) \
|
||||
$(LIB_CLOCK_GETTIME) \
|
||||
$(LIB_GETHRXTIME) \
|
||||
lib/libbison.a
|
||||
|
||||
|
||||
|
||||
|
||||
## ------ ##
|
||||
## yacc. ##
|
||||
## ------ ##
|
||||
|
||||
if ENABLE_YACC
|
||||
bin_SCRIPTS = src/yacc
|
||||
bin_SCRIPTS = src/yacc
|
||||
endif
|
||||
EXTRA_SCRIPTS = src/yacc
|
||||
MOSTLYCLEANFILES += src/yacc
|
||||
|
||||
+293
-307
File diff suppressed because it is too large
Load Diff
+20
-17
@@ -1,4 +1,4 @@
|
||||
/* A Bison parser, made by GNU Bison 3.1.222-4227c. */
|
||||
/* A Bison parser, made by GNU Bison 3.1.91.31-00793. */
|
||||
|
||||
/* Bison interface for Yacc-like parsers in C
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
/* Undocumented macros, especially those whose name start with YY_,
|
||||
are private implementation details. Do not rely on them. */
|
||||
|
||||
#ifndef YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED
|
||||
# define YY_GRAM_SRC_PARSE_GRAM_H_INCLUDED
|
||||
/* Debug traces. */
|
||||
@@ -48,11 +51,11 @@
|
||||
extern int gram_debug;
|
||||
#endif
|
||||
/* "%code requires" blocks. */
|
||||
#line 21 "src/parse-gram.y" /* yacc.c:1913 */
|
||||
#line 21 "src/parse-gram.y" /* yacc.c:1906 */
|
||||
|
||||
#include "symlist.h"
|
||||
#include "symtab.h"
|
||||
#line 222 "src/parse-gram.y" /* yacc.c:1913 */
|
||||
#line 222 "src/parse-gram.y" /* yacc.c:1906 */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -61,10 +64,10 @@ extern int gram_debug;
|
||||
param_parse = 1 << 1,
|
||||
param_both = param_lex | param_parse
|
||||
} param_type;
|
||||
#line 645 "src/parse-gram.y" /* yacc.c:1913 */
|
||||
#line 645 "src/parse-gram.y" /* yacc.c:1906 */
|
||||
#include "muscle-tab.h"
|
||||
|
||||
#line 68 "src/parse-gram.h" /* yacc.c:1913 */
|
||||
#line 71 "src/parse-gram.h" /* yacc.c:1906 */
|
||||
|
||||
/* Token type. */
|
||||
#ifndef GRAM_TOKENTYPE
|
||||
@@ -135,27 +138,27 @@ extern int gram_debug;
|
||||
|
||||
union GRAM_STYPE
|
||||
{
|
||||
#line 183 "src/parse-gram.y" /* yacc.c:1913 */
|
||||
#line 183 "src/parse-gram.y" /* yacc.c:1906 */
|
||||
unsigned char character;
|
||||
#line 187 "src/parse-gram.y" /* yacc.c:1913 */
|
||||
#line 187 "src/parse-gram.y" /* yacc.c:1906 */
|
||||
char *code;
|
||||
#line 192 "src/parse-gram.y" /* yacc.c:1913 */
|
||||
#line 192 "src/parse-gram.y" /* yacc.c:1906 */
|
||||
uniqstr uniqstr;
|
||||
#line 200 "src/parse-gram.y" /* yacc.c:1913 */
|
||||
#line 200 "src/parse-gram.y" /* yacc.c:1906 */
|
||||
int integer;
|
||||
#line 204 "src/parse-gram.y" /* yacc.c:1913 */
|
||||
#line 204 "src/parse-gram.y" /* yacc.c:1906 */
|
||||
symbol *symbol;
|
||||
#line 209 "src/parse-gram.y" /* yacc.c:1913 */
|
||||
#line 209 "src/parse-gram.y" /* yacc.c:1906 */
|
||||
assoc assoc;
|
||||
#line 212 "src/parse-gram.y" /* yacc.c:1913 */
|
||||
#line 212 "src/parse-gram.y" /* yacc.c:1906 */
|
||||
symbol_list *list;
|
||||
#line 215 "src/parse-gram.y" /* yacc.c:1913 */
|
||||
#line 215 "src/parse-gram.y" /* yacc.c:1906 */
|
||||
named_ref *named_ref;
|
||||
#line 242 "src/parse-gram.y" /* yacc.c:1913 */
|
||||
#line 242 "src/parse-gram.y" /* yacc.c:1906 */
|
||||
param_type param;
|
||||
#line 409 "src/parse-gram.y" /* yacc.c:1913 */
|
||||
#line 409 "src/parse-gram.y" /* yacc.c:1906 */
|
||||
code_props_type code_type;
|
||||
#line 647 "src/parse-gram.y" /* yacc.c:1913 */
|
||||
#line 647 "src/parse-gram.y" /* yacc.c:1906 */
|
||||
|
||||
struct
|
||||
{
|
||||
@@ -163,7 +166,7 @@ code_props_type code_type;
|
||||
muscle_kind kind;
|
||||
} value;
|
||||
|
||||
#line 167 "src/parse-gram.h" /* yacc.c:1913 */
|
||||
#line 170 "src/parse-gram.h" /* yacc.c:1906 */
|
||||
};
|
||||
|
||||
typedef union GRAM_STYPE GRAM_STYPE;
|
||||
|
||||
+41
-60
@@ -61,7 +61,6 @@ max_length (size_t *width, const char *str)
|
||||
static void
|
||||
print_core (FILE *out, state *s)
|
||||
{
|
||||
size_t i;
|
||||
item_number *sitems = s->items;
|
||||
size_t snritems = s->nitems;
|
||||
sym_content *previous_lhs = NULL;
|
||||
@@ -79,18 +78,15 @@ print_core (FILE *out, state *s)
|
||||
|
||||
fputc ('\n', out);
|
||||
|
||||
for (i = 0; i < snritems; i++)
|
||||
for (size_t i = 0; i < snritems; i++)
|
||||
{
|
||||
item_number *sp;
|
||||
item_number *sp1;
|
||||
rule_number r;
|
||||
|
||||
sp1 = sp = ritem + sitems[i];
|
||||
item_number *sp1 = ritem + sitems[i];
|
||||
|
||||
item_number *sp = sp1;
|
||||
while (*sp >= 0)
|
||||
sp++;
|
||||
|
||||
r = item_number_as_rule_number (*sp);
|
||||
rule_number r = item_number_as_rule_number (*sp);
|
||||
|
||||
rule_lhs_print (&rules[r], previous_lhs, out);
|
||||
previous_lhs = rules[r].lhs;
|
||||
@@ -124,10 +120,9 @@ print_transitions (state *s, FILE *out, bool display_transitions_p)
|
||||
{
|
||||
transitions *trans = s->transitions;
|
||||
size_t width = 0;
|
||||
int i;
|
||||
|
||||
/* Compute the width of the lookahead token column. */
|
||||
for (i = 0; i < trans->num; i++)
|
||||
for (int i = 0; i < trans->num; i++)
|
||||
if (!TRANSITION_IS_DISABLED (trans, i)
|
||||
&& TRANSITION_IS_SHIFT (trans, i) == display_transitions_p)
|
||||
{
|
||||
@@ -143,17 +138,16 @@ print_transitions (state *s, FILE *out, bool display_transitions_p)
|
||||
width += 2;
|
||||
|
||||
/* Report lookahead tokens and shifts. */
|
||||
for (i = 0; i < trans->num; i++)
|
||||
for (int i = 0; i < trans->num; i++)
|
||||
if (!TRANSITION_IS_DISABLED (trans, i)
|
||||
&& TRANSITION_IS_SHIFT (trans, i) == display_transitions_p)
|
||||
{
|
||||
symbol *sym = symbols[TRANSITION_SYMBOL (trans, i)];
|
||||
const char *tag = sym->tag;
|
||||
state *s1 = trans->states[i];
|
||||
int j;
|
||||
|
||||
fprintf (out, " %s", tag);
|
||||
for (j = width - strlen (tag); j > 0; --j)
|
||||
for (int j = width - strlen (tag); j > 0; --j)
|
||||
fputc (' ', out);
|
||||
if (display_transitions_p)
|
||||
fprintf (out, _("shift, and go to state %d\n"), s1->number);
|
||||
@@ -172,10 +166,9 @@ print_errs (FILE *out, state *s)
|
||||
{
|
||||
errs *errp = s->errs;
|
||||
size_t width = 0;
|
||||
int i;
|
||||
|
||||
/* Compute the width of the lookahead token column. */
|
||||
for (i = 0; i < errp->num; ++i)
|
||||
for (int i = 0; i < errp->num; ++i)
|
||||
if (errp->symbols[i])
|
||||
max_length (&width, errp->symbols[i]->tag);
|
||||
|
||||
@@ -187,13 +180,12 @@ print_errs (FILE *out, state *s)
|
||||
width += 2;
|
||||
|
||||
/* Report lookahead tokens and errors. */
|
||||
for (i = 0; i < errp->num; ++i)
|
||||
for (int i = 0; i < errp->num; ++i)
|
||||
if (errp->symbols[i])
|
||||
{
|
||||
const char *tag = errp->symbols[i]->tag;
|
||||
int j;
|
||||
fprintf (out, " %s", tag);
|
||||
for (j = width - strlen (tag); j > 0; --j)
|
||||
for (int j = width - strlen (tag); j > 0; --j)
|
||||
fputc (' ', out);
|
||||
fputs (_("error (nonassociative)\n"), out);
|
||||
}
|
||||
@@ -211,9 +203,8 @@ print_reduction (FILE *out, size_t width,
|
||||
const char *lookahead_token,
|
||||
rule *r, bool enabled)
|
||||
{
|
||||
int j;
|
||||
fprintf (out, " %s", lookahead_token);
|
||||
for (j = width - strlen (lookahead_token); j > 0; --j)
|
||||
for (int j = width - strlen (lookahead_token); j > 0; --j)
|
||||
fputc (' ', out);
|
||||
if (!enabled)
|
||||
fputc ('[', out);
|
||||
@@ -235,36 +226,37 @@ print_reduction (FILE *out, size_t width,
|
||||
static void
|
||||
print_reductions (FILE *out, state *s)
|
||||
{
|
||||
transitions *trans = s->transitions;
|
||||
reductions *reds = s->reductions;
|
||||
rule *default_reduction = NULL;
|
||||
size_t width = 0;
|
||||
int i, j;
|
||||
bool default_reduction_only = true;
|
||||
|
||||
if (reds->num == 0)
|
||||
return;
|
||||
|
||||
rule *default_reduction = NULL;
|
||||
if (yydefact[s->number] != 0)
|
||||
default_reduction = &rules[yydefact[s->number] - 1];
|
||||
|
||||
transitions *trans = s->transitions;
|
||||
|
||||
bitset_zero (no_reduce_set);
|
||||
FOR_EACH_SHIFT (trans, i)
|
||||
bitset_set (no_reduce_set, TRANSITION_SYMBOL (trans, i));
|
||||
for (i = 0; i < s->errs->num; ++i)
|
||||
{
|
||||
int i;
|
||||
FOR_EACH_SHIFT (trans, i)
|
||||
bitset_set (no_reduce_set, TRANSITION_SYMBOL (trans, i));
|
||||
}
|
||||
for (int i = 0; i < s->errs->num; ++i)
|
||||
if (s->errs->symbols[i])
|
||||
bitset_set (no_reduce_set, s->errs->symbols[i]->content->number);
|
||||
|
||||
/* Compute the width of the lookahead token column. */
|
||||
size_t width = 0;
|
||||
if (default_reduction)
|
||||
width = strlen (_("$default"));
|
||||
|
||||
if (reds->lookahead_tokens)
|
||||
for (i = 0; i < ntokens; i++)
|
||||
for (int i = 0; i < ntokens; i++)
|
||||
{
|
||||
bool count = bitset_test (no_reduce_set, i);
|
||||
|
||||
for (j = 0; j < reds->num; ++j)
|
||||
for (int j = 0; j < reds->num; ++j)
|
||||
if (bitset_test (reds->lookahead_tokens[j], i))
|
||||
{
|
||||
if (! count)
|
||||
@@ -274,9 +266,7 @@ print_reductions (FILE *out, state *s)
|
||||
count = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
max_length (&width, symbols[i]->tag);
|
||||
}
|
||||
max_length (&width, symbols[i]->tag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,16 +277,18 @@ print_reductions (FILE *out, state *s)
|
||||
fputc ('\n', out);
|
||||
width += 2;
|
||||
|
||||
bool default_reduction_only = true;
|
||||
|
||||
/* Report lookahead tokens (or $default) and reductions. */
|
||||
if (reds->lookahead_tokens)
|
||||
for (i = 0; i < ntokens; i++)
|
||||
for (int i = 0; i < ntokens; i++)
|
||||
{
|
||||
bool defaulted = false;
|
||||
bool count = bitset_test (no_reduce_set, i);
|
||||
if (count)
|
||||
default_reduction_only = false;
|
||||
|
||||
for (j = 0; j < reds->num; ++j)
|
||||
for (int j = 0; j < reds->num; ++j)
|
||||
if (bitset_test (reds->lookahead_tokens[j], i))
|
||||
{
|
||||
if (! count)
|
||||
@@ -396,18 +388,14 @@ print_state (FILE *out, state *s)
|
||||
static void
|
||||
print_terminal_symbols (FILE *out)
|
||||
{
|
||||
symbol_number i;
|
||||
|
||||
/* TERMINAL (type #) : rule #s terminal is on RHS */
|
||||
fprintf (out, "%s\n\n", _("Terminals, with rules where they appear"));
|
||||
for (i = 0; i < max_user_token_number + 1; i++)
|
||||
for (symbol_number i = 0; i < max_user_token_number + 1; i++)
|
||||
if (token_translations[i] != undeftoken->content->number)
|
||||
{
|
||||
const char *tag = symbols[token_translations[i]]->tag;
|
||||
int column = strlen (tag);
|
||||
char buffer[90];
|
||||
rule_number r;
|
||||
item_number *rhsp;
|
||||
|
||||
buffer[0] = 0;
|
||||
fputs (tag, out);
|
||||
@@ -420,8 +408,8 @@ print_terminal_symbols (FILE *out)
|
||||
}
|
||||
sprintf (buffer, " (%d)", i);
|
||||
|
||||
for (r = 0; r < nrules; r++)
|
||||
for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
|
||||
for (rule_number r = 0; r < nrules; r++)
|
||||
for (item_number *rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
|
||||
if (item_number_as_symbol_number (*rhsp) == token_translations[i])
|
||||
{
|
||||
END_TEST (65);
|
||||
@@ -437,24 +425,18 @@ print_terminal_symbols (FILE *out)
|
||||
static void
|
||||
print_nonterminal_symbols (FILE *out)
|
||||
{
|
||||
symbol_number i;
|
||||
|
||||
fprintf (out, "%s\n\n", _("Nonterminals, with rules where they appear"));
|
||||
for (i = ntokens; i < nsyms; i++)
|
||||
for (symbol_number i = ntokens; i < nsyms; i++)
|
||||
{
|
||||
const char *tag = symbols[i]->tag;
|
||||
int column = strlen (tag);
|
||||
int left_count = 0, right_count = 0;
|
||||
rule_number r;
|
||||
char buffer[90];
|
||||
buffer[0] = 0;
|
||||
|
||||
for (r = 0; r < nrules; r++)
|
||||
for (rule_number r = 0; r < nrules; r++)
|
||||
{
|
||||
item_number *rhsp;
|
||||
if (rules[r].lhs->number == i)
|
||||
left_count++;
|
||||
for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
|
||||
for (item_number *rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
|
||||
if (item_number_as_symbol_number (*rhsp) == i)
|
||||
{
|
||||
right_count++;
|
||||
@@ -466,6 +448,8 @@ print_nonterminal_symbols (FILE *out)
|
||||
if (symbols[i]->content->type_name)
|
||||
column += fprintf (out, " <%s>",
|
||||
symbols[i]->content->type_name);
|
||||
char buffer[90];
|
||||
buffer[0] = 0;
|
||||
sprintf (buffer, " (%d)", i);
|
||||
END_TEST (0);
|
||||
|
||||
@@ -474,7 +458,7 @@ print_nonterminal_symbols (FILE *out)
|
||||
END_TEST (65);
|
||||
sprintf (buffer + strlen (buffer), _(" on left:"));
|
||||
|
||||
for (r = 0; r < nrules; r++)
|
||||
for (rule_number r = 0; r < nrules; r++)
|
||||
{
|
||||
if (rules[r].lhs->number == i)
|
||||
{
|
||||
@@ -490,7 +474,7 @@ print_nonterminal_symbols (FILE *out)
|
||||
sprintf (buffer + strlen (buffer), ",");
|
||||
END_TEST (65);
|
||||
sprintf (buffer + strlen (buffer), _(" on right:"));
|
||||
for (r = 0; r < nrules; r++)
|
||||
for (rule_number r = 0; r < nrules; r++)
|
||||
{
|
||||
item_number *rhsp;
|
||||
for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
|
||||
@@ -528,12 +512,9 @@ print_results (void)
|
||||
if (report_flag & report_itemsets)
|
||||
new_closure (nritems);
|
||||
/* Storage for print_reductions. */
|
||||
no_reduce_set = bitset_create (ntokens, BITSET_FIXED);
|
||||
{
|
||||
state_number i;
|
||||
for (i = 0; i < nstates; i++)
|
||||
print_state (out, states[i]);
|
||||
}
|
||||
no_reduce_set = bitset_create (ntokens, BITSET_FIXED);
|
||||
for (state_number i = 0; i < nstates; i++)
|
||||
print_state (out, states[i]);
|
||||
bitset_free (no_reduce_set);
|
||||
if (report_flag & report_itemsets)
|
||||
free_closure ();
|
||||
|
||||
+4
-4
@@ -307,10 +307,10 @@ grammar_rule_check_and_complete (symbol_list *r)
|
||||
else
|
||||
{
|
||||
/* Install the default action only for C++. */
|
||||
bool is_cxx =
|
||||
skeleton
|
||||
? STREQ (skeleton, "glr.cc") || STREQ (skeleton, "lalr1.cc")
|
||||
: STREQ (language->language, "c++");
|
||||
const bool is_cxx =
|
||||
STREQ (language->language, "c++")
|
||||
|| (skeleton && (STREQ (skeleton, "glr.cc")
|
||||
|| STREQ (skeleton, "lalr1.cc")));
|
||||
if (is_cxx)
|
||||
{
|
||||
code_props_rule_action_init (&r->action_props, "{ $$ = $1; }",
|
||||
|
||||
+17
-23
@@ -252,15 +252,15 @@ AT_DATA_GRAMMAR([[input.y]],
|
||||
]AT_YYLEX_DECLARE[
|
||||
}
|
||||
%%
|
||||
exp: { ]AT_SKEL_CC_IF([[std::cerr << @$ << '\n']],
|
||||
[[LOCATION_PRINT(stderr, @$); fputc ('\n', stderr)]])[; }
|
||||
exp: { ]AT_CXX_IF([[std::cerr << @$ << '\n']],
|
||||
[[LOCATION_PRINT(stderr, @$); fputc ('\n', stderr)]])[; }
|
||||
%%
|
||||
]AT_YYERROR_DEFINE[
|
||||
|
||||
]AT_YYLEX_PROTOTYPE[
|
||||
{]AT_PURE_IF([
|
||||
YYUSE(lvalp);
|
||||
YYUSE(llocp);], [AT_SKEL_CC_IF([
|
||||
YYUSE(llocp);], [AT_CXX_IF([
|
||||
YYUSE(lvalp);
|
||||
YYUSE(llocp);])])[
|
||||
return 'x';
|
||||
@@ -268,7 +268,7 @@ exp: { ]AT_SKEL_CC_IF([[std::cerr << @$ << '\n']],
|
||||
|
||||
int
|
||||
main (void)
|
||||
{]AT_SKEL_CC_IF([[
|
||||
{]AT_CXX_IF([[
|
||||
yy::parser p;
|
||||
p.set_debug_level (!!getenv("YYDEBUG"));
|
||||
return p.parse ();]], [[
|
||||
@@ -369,7 +369,7 @@ main (void)
|
||||
loc.]AT_FIRST_COLUMN[ = C1; \
|
||||
loc.]AT_LAST_LINE[ = L2; \
|
||||
loc.]AT_LAST_COLUMN[ = C2; \
|
||||
]AT_SKEL_CC_IF([std::cout << loc],
|
||||
]AT_CXX_IF([std::cout << loc],
|
||||
[LOCATION_PRINT(stdout, loc)])[;\
|
||||
putchar ('\n');
|
||||
|
||||
@@ -397,11 +397,8 @@ AT_BISON_OPTION_POPDEFS
|
||||
AT_CLEANUP
|
||||
])
|
||||
|
||||
## FIXME: test Java, and iterate over skeletons.
|
||||
AT_TEST([yacc.c])
|
||||
AT_TEST([glr.c])
|
||||
AT_TEST([lalr1.cc])
|
||||
AT_TEST([glr.cc])
|
||||
## FIXME: test Java.
|
||||
m4_map_args([AT_TEST], [yacc.c], [glr.c], [lalr1.cc], [glr.cc])
|
||||
|
||||
m4_popdef([AT_TEST])
|
||||
|
||||
@@ -694,13 +691,13 @@ const char *source = YY_NULLPTR;
|
||||
static
|
||||
]AT_YYLEX_PROTOTYPE[
|
||||
{
|
||||
static unsigned counter = 0;
|
||||
static int counter = 0;
|
||||
|
||||
unsigned c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++;
|
||||
int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++;
|
||||
/* As in BASIC, line numbers go from 10 to 10. */
|
||||
]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = 10 * c;
|
||||
]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = ]AT_CXX_IF([(unsigned)], [(int)])[(10 * c);
|
||||
]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9;
|
||||
assert (c <= strlen (source));
|
||||
assert (c <= (int) strlen (source));
|
||||
if (source[c])
|
||||
fprintf (stderr, "sending: '%c'", source[c]);
|
||||
else
|
||||
@@ -1651,7 +1648,7 @@ AT_DATA_GRAMMAR([[input.y]],
|
||||
|
||||
# define YYSTYPE sem_type
|
||||
|
||||
]AT_SKEL_CC_IF([[
|
||||
]AT_CXX_IF([[
|
||||
# include <iostream>
|
||||
namespace
|
||||
{
|
||||
@@ -1687,7 +1684,7 @@ AT_DATA_GRAMMAR([[input.y]],
|
||||
%initial-action
|
||||
{
|
||||
$<ival>$ = 42;
|
||||
$<fval>$ = 4.2;
|
||||
$<fval>$ = 4.2f;
|
||||
}
|
||||
|
||||
%%
|
||||
@@ -1698,11 +1695,11 @@ float: UNTYPED INT
|
||||
};
|
||||
%%
|
||||
]AT_YYERROR_DEFINE[
|
||||
]AT_YYLEX_DEFINE(AT_SKEL_CC_IF([[{yy::parser::token::UNTYPED,
|
||||
]AT_YYLEX_DEFINE(AT_CXX_IF([[{yy::parser::token::UNTYPED,
|
||||
yy::parser::token::INT,
|
||||
EOF}]],
|
||||
[[{UNTYPED, INT, EOF}]]),
|
||||
[AT_VAL.ival = toknum * 10; AT_VAL.fval = toknum / 10.0;])[
|
||||
[AT_VAL.ival = (int) toknum * 10; AT_VAL.fval = (float) toknum / 10.0f;])[
|
||||
]AT_MAIN_DEFINE[
|
||||
]])
|
||||
|
||||
@@ -1726,10 +1723,7 @@ AT_BISON_OPTION_POPDEFS
|
||||
AT_CLEANUP
|
||||
])
|
||||
|
||||
AT_TEST([yacc.c])
|
||||
AT_TEST([glr.c])
|
||||
AT_TEST([lalr1.cc])
|
||||
AT_TEST([glr.cc])
|
||||
m4_map_args([AT_TEST], [yacc.c], [glr.c], [lalr1.cc], [glr.cc])
|
||||
|
||||
m4_popdef([AT_TEST])
|
||||
|
||||
@@ -1822,7 +1816,7 @@ exp:
|
||||
|
||||
%%
|
||||
]AT_YYERROR_DEFINE[
|
||||
]AT_YYLEX_DEFINE(["bcd"], [*lvalp = (toknum + 1) * 10])[
|
||||
]AT_YYLEX_DEFINE(["bcd"], [*lvalp = (int) ((toknum + 1) * 10)])[
|
||||
]AT_MAIN_DEFINE[
|
||||
]])
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
|
||||
+2
-4
@@ -98,10 +98,8 @@ fi
|
||||
: ${CXX_COMPILER_POSIXLY_CORRECT='@CXX_COMPILER_POSIXLY_CORRECT@'}
|
||||
|
||||
if $POSIXLY_CORRECT_IS_EXPORTED; then
|
||||
$C_COMPILER_POSIXLY_CORRECT ||
|
||||
BISON_C_WORKS="as_fn_error 77 POSIXLY_CORRECT"
|
||||
$CXX_COMPILER_POSIXLY_CORRECT ||
|
||||
BISON_CXX_WORKS="as_fn_error 77 POSIXLY_CORRECT"
|
||||
$C_COMPILER_POSIXLY_CORRECT || BISON_C_WORKS=false
|
||||
$CXX_COMPILER_POSIXLY_CORRECT || BISON_CXX_WORKS=false
|
||||
fi
|
||||
|
||||
# Handle --compile-c-with-cxx here, once CXX and CXXFLAGS are known.
|
||||
|
||||
+20
-11
@@ -162,19 +162,27 @@ int main()
|
||||
std::cerr << ss.value.as<int>() << '\n';
|
||||
}
|
||||
|
||||
// pushing on the stack.
|
||||
// Pushing on the stack.
|
||||
// Sufficiently many so that it will be resized.
|
||||
// Probably 3 times (starting at 200).
|
||||
{
|
||||
parser::stack_type st;
|
||||
for (int i = 0; i < 100; ++i)
|
||||
const int mucho = 1700;
|
||||
for (int i = 0; i < mucho; ++i)
|
||||
{
|
||||
#if defined __cplusplus && 201103L <= __cplusplus
|
||||
st.push(parser::stack_symbol_type{1, parser::make_INT(123)});
|
||||
st.push(parser::stack_symbol_type{1, parser::make_INT (i)});
|
||||
#else
|
||||
parser::symbol_type s = parser::make_INT(123);
|
||||
parser::stack_symbol_type ss(1, s);
|
||||
st.push(ss);
|
||||
parser::symbol_type s = parser::make_INT (i);
|
||||
parser::stack_symbol_type ss (1, s);
|
||||
st.push (ss);
|
||||
#endif
|
||||
}
|
||||
for (int i = mucho - 1; 0 <= i; --i)
|
||||
{
|
||||
assert (st[0].value.as<int>() == i);
|
||||
st.pop ();
|
||||
}
|
||||
}
|
||||
}
|
||||
]])
|
||||
@@ -671,14 +679,15 @@ m4_define([AT_CHECK_DOXYGEN],
|
||||
[m4_fatal([invalid argument: $1])])
|
||||
AT_SETUP([Doxygen $1 Documentation])
|
||||
|
||||
AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc"])
|
||||
AT_BISON_OPTION_PUSHDEFS([%skeleton "lalr1.cc" %locations])
|
||||
AT_DATA([input.yy],
|
||||
[[%skeleton "lalr1.cc"
|
||||
[[%require "3.2"
|
||||
%skeleton "lalr1.cc"
|
||||
%locations
|
||||
%defines
|
||||
%debug
|
||||
%%
|
||||
exp: /* empty */;
|
||||
exp: %empty;
|
||||
%%
|
||||
]AT_YYERROR_DEFINE[
|
||||
]])
|
||||
@@ -1173,12 +1182,12 @@ yylex (yy::parser::semantic_type *lvalp)
|
||||
// 'R': call YYERROR in the action
|
||||
// 's': reduction throws.
|
||||
// 'T': call YYABORT in the action
|
||||
switch (int res = *input++)
|
||||
switch (char res = *input++)
|
||||
{
|
||||
case 'l':
|
||||
throw std::runtime_error ("yylex");
|
||||
default:
|
||||
lvalp->]AT_VARIANT_IF([build (Object (res))],
|
||||
lvalp->]AT_VARIANT_IF([build<Object> (res)],
|
||||
[obj = new Object (res)])[;
|
||||
// Fall through.
|
||||
case 0:
|
||||
|
||||
+11
-11
@@ -48,7 +48,7 @@ m4_pushdef([AT_CALC_MAIN],
|
||||
[#include <assert.h>
|
||||
#include <unistd.h>
|
||||
|
||||
AT_SKEL_CC_IF([[
|
||||
AT_CXX_IF([[
|
||||
namespace
|
||||
{
|
||||
/* A C++ ]AT_NAME_PREFIX[parse that simulates the C signature. */
|
||||
@@ -93,7 +93,7 @@ main (int argc, const char **argv)
|
||||
return 3;
|
||||
}
|
||||
|
||||
]AT_SKEL_CC_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]])[);
|
||||
if (fclose (input))
|
||||
perror ("fclose");
|
||||
@@ -206,7 +206,7 @@ read_signed_integer (]AT_YYLEX_FORMALS[)
|
||||
AT_DATA_GRAMMAR([calc.y],
|
||||
[[/* Infix notation calculator--calc */
|
||||
]$4
|
||||
AT_SKEL_CC_IF(
|
||||
AT_CXX_IF(
|
||||
[%define global_tokens_and_yystype])[
|
||||
%code requires
|
||||
{
|
||||
@@ -247,8 +247,8 @@ AT_SKEL_CC_IF(
|
||||
{
|
||||
semantic_value ival;
|
||||
};
|
||||
%printer { ]AT_SKEL_CC_IF([[yyoutput << $$]],
|
||||
[[fprintf (yyoutput, "%d", $$)]])[; } <ival>;
|
||||
%printer { ]AT_CXX_IF([[yyo << $$]],
|
||||
[[fprintf (yyo, "%d", $$)]])[; } <ival>;
|
||||
|
||||
%code provides
|
||||
{
|
||||
@@ -272,7 +272,7 @@ static int power (int base, int exponent);
|
||||
]AT_YYLEX_DECLARE_EXTERN[
|
||||
}
|
||||
|
||||
]AT_SKEL_CC_IF([AT_LOCATION_TYPE_IF([[
|
||||
]AT_CXX_IF([AT_LOCATION_TYPE_IF([[
|
||||
%initial-action
|
||||
{
|
||||
@$.first.l = @$.first.c = 1;
|
||||
@@ -333,7 +333,7 @@ power (int base, int exponent)
|
||||
return res;
|
||||
}
|
||||
|
||||
]AT_SKEL_CC_IF(
|
||||
]AT_CXX_IF(
|
||||
[AT_LOCATION_TYPE_IF([[
|
||||
namespace
|
||||
{
|
||||
@@ -354,12 +354,12 @@ namespace
|
||||
[AT_CALC_LEX
|
||||
AT_CALC_MAIN])])
|
||||
|
||||
AT_DEFINES_IF([AT_DATA_SOURCE([[calc-lex.c]AT_SKEL_CC_IF([[c]])],
|
||||
[[#include "calc.h]AT_SKEL_CC_IF([[h]])["
|
||||
AT_DEFINES_IF([AT_DATA_SOURCE([[calc-lex.]AT_LANG_EXT],
|
||||
[[#include "calc.]AT_LANG_HDR["
|
||||
|
||||
]AT_CALC_LEX])
|
||||
AT_DATA_SOURCE([[calc-main.c]AT_SKEL_CC_IF([[c]])],
|
||||
[[#include "calc.h]AT_SKEL_CC_IF([[h]])["
|
||||
AT_DATA_SOURCE([[calc-main.]AT_LANG_EXT],
|
||||
[[#include "calc.]AT_LANG_HDR["
|
||||
|
||||
]AT_CALC_MAIN])
|
||||
])
|
||||
|
||||
+11
-11
@@ -405,17 +405,17 @@ AT_SETUP([[parse.error=verbose and consistent errors: ]$1])
|
||||
AT_BISON_OPTION_PUSHDEFS([$1])
|
||||
|
||||
m4_pushdef([AT_YYLEX_PROTOTYPE],
|
||||
[AT_SKEL_CC_IF([[int yylex (yy::parser::semantic_type *lvalp)]],
|
||||
[[int yylex (YYSTYPE *lvalp)]])])
|
||||
[AT_CXX_IF([[int yylex (yy::parser::semantic_type *lvalp)]],
|
||||
[[int yylex (YYSTYPE *lvalp)]])])
|
||||
|
||||
AT_SKEL_JAVA_IF([AT_DATA], [AT_DATA_GRAMMAR])([input.y],
|
||||
[AT_SKEL_JAVA_IF([[
|
||||
AT_JAVA_IF([AT_DATA], [AT_DATA_GRAMMAR])([input.y],
|
||||
[AT_JAVA_IF([[
|
||||
|
||||
%code imports {
|
||||
import java.io.IOException;
|
||||
}]], [[
|
||||
|
||||
%code {]AT_SKEL_CC_IF([[
|
||||
%code {]AT_CXX_IF([[
|
||||
#include <string>]], [[
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
@@ -424,7 +424,7 @@ AT_SKEL_JAVA_IF([AT_DATA], [AT_DATA_GRAMMAR])([input.y],
|
||||
#define USE(Var)
|
||||
}
|
||||
|
||||
]AT_SKEL_CC_IF([[%defines]], [[%define api.pure]])])[
|
||||
]AT_CXX_IF([[%defines]], [[%define api.pure]])])[
|
||||
|
||||
]AT_YACC_IF([[
|
||||
%code {
|
||||
@@ -442,11 +442,11 @@ AT_SKEL_JAVA_IF([AT_DATA], [AT_DATA_GRAMMAR])([input.y],
|
||||
|
||||
]$2[
|
||||
|
||||
]AT_SKEL_JAVA_IF([[%code lexer {]], [[%%]])[
|
||||
]AT_JAVA_IF([[%code lexer {]], [[%%]])[
|
||||
|
||||
/*--------.
|
||||
| yylex. |
|
||||
`--------*/]AT_SKEL_JAVA_IF([[
|
||||
`--------*/]AT_JAVA_IF([[
|
||||
|
||||
public String input = "]$3[";
|
||||
public int index = 0;
|
||||
@@ -469,7 +469,7 @@ public Object getLVal ()
|
||||
return *input++;
|
||||
}]])[
|
||||
]AT_YYERROR_DEFINE[
|
||||
]AT_SKEL_JAVA_IF([[
|
||||
]AT_JAVA_IF([[
|
||||
};
|
||||
|
||||
%%]])[
|
||||
@@ -486,8 +486,8 @@ m4_pushdef([AT_EXPECTING], [m4_if($5, [ab], [[, expecting 'a' or 'b']],
|
||||
$5, [a], [[, expecting 'a']],
|
||||
$5, [b], [[, expecting 'b']])])
|
||||
|
||||
AT_SKEL_JAVA_IF([AT_JAVA_PARSER_CHECK([[input]], [[0]]],
|
||||
[AT_PARSER_CHECK([[./input]], [[1]]]),
|
||||
AT_JAVA_IF([AT_JAVA_PARSER_CHECK([[input]], [[0]]],
|
||||
[AT_PARSER_CHECK([[./input]], [[1]]]),
|
||||
[[]],
|
||||
[[syntax error, unexpected ]$4[]AT_EXPECTING[
|
||||
]])
|
||||
|
||||
+4
-5
@@ -137,9 +137,6 @@ main (int argc, char **argv)
|
||||
|
||||
]AT_YYLEX_PROTOTYPE[
|
||||
{
|
||||
char buffer[256];
|
||||
int c;
|
||||
unsigned i;
|
||||
static int lineNum = 1;
|
||||
static int colNum = 0;
|
||||
|
||||
@@ -152,6 +149,7 @@ main (int argc, char **argv)
|
||||
|
||||
while (1)
|
||||
{
|
||||
int c;
|
||||
assert (!feof (stdin));
|
||||
c = getchar ();
|
||||
switch (c)
|
||||
@@ -175,11 +173,12 @@ main (int argc, char **argv)
|
||||
yylloc.first_column = colNum;]])[
|
||||
if (isalpha (c))
|
||||
{
|
||||
i = 0;
|
||||
char buffer[256];
|
||||
unsigned i = 0;
|
||||
|
||||
do
|
||||
{
|
||||
buffer[i++] = c;
|
||||
buffer[i++] = (char) c;
|
||||
colNum += 1;
|
||||
assert (i != sizeof buffer - 1);
|
||||
c = getchar ();
|
||||
|
||||
+8
-10
@@ -1000,8 +1000,7 @@ static int
|
||||
merge (YYSTYPE s1, YYSTYPE s2)
|
||||
{
|
||||
/* Not invoked. */
|
||||
char dummy = s1.dummy + s2.dummy;
|
||||
return dummy;
|
||||
return s1.dummy + s2.dummy;
|
||||
}
|
||||
|
||||
]AT_YYERROR_DEFINE[
|
||||
@@ -1119,7 +1118,7 @@ change_lookahead:
|
||||
|
||||
]AT_YYERROR_DEFINE[
|
||||
]AT_YYLEX_DEFINE(["ab"],
|
||||
[yylval.value = res + 'A' - 'a'])[
|
||||
[yylval.value = (char) (res + 'A' - 'a')])[
|
||||
|
||||
static void
|
||||
print_lookahead (char const *reduction)
|
||||
@@ -1319,11 +1318,11 @@ static int
|
||||
yylex (void)
|
||||
{
|
||||
static char const input[] = "abcdddd";
|
||||
static size_t toknum;
|
||||
assert (toknum < sizeof input);
|
||||
static int toknum = 0;
|
||||
assert (toknum < (int) sizeof input);
|
||||
yylloc.first_line = yylloc.last_line = 1;
|
||||
yylloc.first_column = yylloc.last_column = toknum + 1;
|
||||
yylval.value = input[toknum] + 'A' - 'a';
|
||||
yylval.value = (char) (input[toknum] + 'A' - 'a');
|
||||
return input[toknum++];
|
||||
}
|
||||
|
||||
@@ -1350,8 +1349,7 @@ print_lookahead (char const *reduction)
|
||||
static char
|
||||
merge (union YYSTYPE s1, union YYSTYPE s2)
|
||||
{
|
||||
char dummy = s1.value + s2.value;
|
||||
return dummy;
|
||||
return (char) (s1.value + s2.value);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -1578,8 +1576,8 @@ static int
|
||||
yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
|
||||
{
|
||||
static char const input[] = "ab";
|
||||
static size_t toknum;
|
||||
assert (toknum < sizeof input);
|
||||
static int toknum = 0;
|
||||
assert (toknum < (int) sizeof input);
|
||||
lvalp->dummy = 0;
|
||||
llocp->first_line = llocp->last_line = 2;
|
||||
llocp->first_column = toknum + 1;
|
||||
|
||||
+3
-2
@@ -41,7 +41,7 @@ AT_DATA_GRAMMAR([$1.y],
|
||||
]AT_YYLEX_DECLARE_EXTERN[
|
||||
%}
|
||||
%%
|
||||
dummy: /* empty */;
|
||||
dummy: %empty;
|
||||
%%
|
||||
#include <$1.h>
|
||||
])
|
||||
@@ -81,7 +81,7 @@ AT_DATA_GRAMMAR([input.y],
|
||||
]AT_YYLEX_DEFINE[
|
||||
%}
|
||||
%%
|
||||
exp: /* empty */;
|
||||
exp: %empty;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK([--defines -o input.c input.y])
|
||||
@@ -317,6 +317,7 @@ AT_CHECK([[$PERL -n -0777 -e '
|
||||
|YYUSE
|
||||
|YY_ATTRIBUTE(?:_PURE|_UNUSED)?
|
||||
|YY_COPY
|
||||
|YY_CPLUSPLUS
|
||||
|YY_IGNORE_MAYBE_UNINITIALIZED_(?:BEGIN|END)
|
||||
|YY_INITIAL_VALUE
|
||||
|YY_MOVE
|
||||
|
||||
+7
-1
@@ -36,7 +36,13 @@ AT_BISON_CHECK([1.y 2.y], [1], [],
|
||||
Try 'bison --help' for more information.
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK([--skeleton], [1], [],
|
||||
# For some reason, on some systems we use the system's getopt, not the
|
||||
# one we ship in gnulib. So we can get two different error messages.
|
||||
# See https://lists.gnu.org/archive/html/bison-patches/2018-10/msg00154.html
|
||||
AT_BISON_CHECK([--skeleton], [1], [], [stderr])
|
||||
AT_CHECK([[sed -e \
|
||||
"s/requires an argument -- skeleton/'--skeleton' requires an argument/" \
|
||||
stderr]], 0,
|
||||
[[bison: option '--skeleton' requires an argument
|
||||
Try 'bison --help' for more information.
|
||||
]])
|
||||
|
||||
+81
-37
@@ -138,28 +138,28 @@ m4_define([AT_BISON_OPTION_PUSHDEFS],
|
||||
# This sucks hard, GNU M4 should really provide M5-like $$1.
|
||||
m4_define([_AT_BISON_OPTION_PUSHDEFS],
|
||||
[m4_if([$1$2], $[1]$[2], [],
|
||||
[m4_fatal([$0: Invalid arguments: $@])])dnl
|
||||
[m4_fatal([$0: invalid arguments: $@])])dnl
|
||||
m4_pushdef([AT_AUTOMOVE_IF],
|
||||
[m4_bmatch([$3], [%define api\.value\.automove], [$1], [$2])])
|
||||
m4_pushdef([AT_DEFINES_IF],
|
||||
[m4_bmatch([$3], [%defines], [$1], [$2])])
|
||||
m4_pushdef([AT_DEBUG_IF],
|
||||
[m4_bmatch([$3], [%debug\|%define parse.trace], [$1], [$2])])
|
||||
m4_pushdef([AT_SKEL_CC_IF],
|
||||
m4_pushdef([AT_CXX_IF],
|
||||
[m4_bmatch([$3], [%language "[Cc]\+\+"\|%skeleton "[a-z0-9]+\.cc"], [$1], [$2])])
|
||||
m4_pushdef([AT_SKEL_JAVA_IF],
|
||||
m4_pushdef([AT_JAVA_IF],
|
||||
[m4_bmatch([$3], [%language "[Jj][Aa][Vv][Aa]"\|%skeleton "[a-z0-9]+\.java"], [$1], [$2])])
|
||||
# The target language: "c", "c++", or "java".
|
||||
m4_pushdef([AT_LANG],
|
||||
[AT_SKEL_JAVA_IF([java],
|
||||
[AT_SKEL_CC_IF([c++],
|
||||
[c])])])
|
||||
[AT_JAVA_IF([java],
|
||||
[AT_CXX_IF([c++],
|
||||
[c])])])
|
||||
m4_pushdef([AT_GLR_IF],
|
||||
[m4_bmatch([$3], [%glr-parser\|%skeleton "glr\..*"], [$1], [$2])])
|
||||
m4_pushdef([AT_LALR1_CC_IF],
|
||||
[AT_SKEL_CC_IF([AT_GLR_IF([$2], [$1])], [$2])])
|
||||
[AT_CXX_IF([AT_GLR_IF([$2], [$1])], [$2])])
|
||||
m4_pushdef([AT_GLR_CC_IF],
|
||||
[AT_SKEL_CC_IF([AT_GLR_IF([$1], [$2])], [$2])])
|
||||
[AT_CXX_IF([AT_GLR_IF([$1], [$2])], [$2])])
|
||||
# Using yacc.c?
|
||||
m4_pushdef([AT_YACC_IF],
|
||||
[m4_bmatch([$3], [%language\|%glr-parser\|%skeleton], [$2], [$1])])
|
||||
@@ -239,13 +239,13 @@ m4_pushdef([AT_YYERROR_SEES_LOC_IF],
|
||||
# are using the C++ parsers.
|
||||
m4_pushdef([AT_PURE_LEX_IF],
|
||||
[AT_PURE_IF([$1],
|
||||
[AT_SKEL_CC_IF([$1], [$2])])])
|
||||
[AT_CXX_IF([$1], [$2])])])
|
||||
|
||||
m4_pushdef([AT_YYSTYPE],
|
||||
[AT_SKEL_CC_IF([AT_NAMESPACE[::parser::semantic_type]],
|
||||
[AT_CXX_IF([AT_NAMESPACE[::parser::semantic_type]],
|
||||
[AT_API_PREFIX[STYPE]])])
|
||||
m4_pushdef([AT_YYLTYPE],
|
||||
[AT_SKEL_CC_IF([AT_NAMESPACE[::parser::location_type]],
|
||||
[AT_CXX_IF([AT_NAMESPACE[::parser::location_type]],
|
||||
[AT_API_PREFIX[LTYPE]])])
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ AT_PURE_LEX_IF(
|
||||
|
||||
# Handle the different types of location components.
|
||||
|
||||
AT_SKEL_CC_IF(
|
||||
AT_CXX_IF(
|
||||
[AT_LOCATION_TYPE_IF(
|
||||
[AT_LOC_PUSHDEF([first.l], [first.c], [last.l], [last.c])],
|
||||
[AT_LOC_PUSHDEF([begin.line], [begin.column], [end.line], [end.column])])],
|
||||
@@ -317,9 +317,9 @@ m4_popdef([AT_PARAM_IF])
|
||||
m4_popdef([AT_LEXPARAM_IF])
|
||||
m4_popdef([AT_YACC_IF])
|
||||
m4_popdef([AT_GLR_IF])
|
||||
m4_popdef([AT_SKEL_CC_IF])
|
||||
m4_popdef([AT_CXX_IF])
|
||||
m4_popdef([AT_LANG])
|
||||
m4_popdef([AT_SKEL_JAVA_IF])
|
||||
m4_popdef([AT_JAVA_IF])
|
||||
m4_popdef([AT_GLR_CC_IF])
|
||||
m4_popdef([AT_LALR1_CC_IF])
|
||||
m4_popdef([AT_DEFINES_IF])
|
||||
@@ -429,7 +429,7 @@ static
|
||||
res = input[toknum++];
|
||||
]$2[;]AT_LOCATION_IF([[
|
||||
]AT_LOC_FIRST_LINE[ = ]AT_LOC_LAST_LINE[ = 1;
|
||||
]AT_LOC_FIRST_COLUMN[ = ]AT_LOC_LAST_COLUMN[ = toknum;]])[
|
||||
]AT_LOC_FIRST_COLUMN[ = ]AT_LOC_LAST_COLUMN[ = ]AT_CXX_IF([(unsigned )], [(int)])[toknum;]])[
|
||||
return res;
|
||||
}]dnl
|
||||
])
|
||||
@@ -470,7 +470,7 @@ m4_define([AT_YYERROR_DECLARE(c)],
|
||||
[#include <stdio.h>
|
||||
]AT_LOCATION_IF([[
|
||||
#if defined ]AT_YYLTYPE[_IS_TRIVIAL && ]AT_YYLTYPE[_IS_TRIVIAL
|
||||
static unsigned location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp);
|
||||
static int location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp);
|
||||
# ifndef LOCATION_PRINT
|
||||
# define LOCATION_PRINT(File, Loc) location_print (File, &(Loc))
|
||||
# endif
|
||||
@@ -485,10 +485,10 @@ m4_define([AT_YYERROR_DEFINE(c)],
|
||||
# if defined ]AT_YYLTYPE[_IS_TRIVIAL && ]AT_YYLTYPE[_IS_TRIVIAL
|
||||
/* Print *YYLOCP on YYO. */
|
||||
__attribute__((__unused__))
|
||||
static unsigned
|
||||
static int
|
||||
location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp)
|
||||
{
|
||||
unsigned res = 0;
|
||||
int res = 0;
|
||||
int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
|
||||
if (0 <= yylocp->first_line)
|
||||
{
|
||||
@@ -539,6 +539,9 @@ main (int argc, char const* argv[])
|
||||
return ]AT_NAME_PREFIX[parse ();
|
||||
}]])
|
||||
|
||||
m4_define([AT_LANG_FOR_EACH_STD(c)],
|
||||
[$1])
|
||||
|
||||
|
||||
## ----- ##
|
||||
## C++. ##
|
||||
@@ -573,21 +576,24 @@ main (int argc, char const* argv[])
|
||||
return p.parse ();
|
||||
}]])
|
||||
|
||||
m4_define([AT_LANG_FOR_EACH_STD(c++)],
|
||||
[AT_FOR_EACH_CXX([$1])])
|
||||
|
||||
m4_define([AT_FOR_EACH_CXX],
|
||||
[[at_for_each_cxx_CXXFLAGS_save=$CXXFLAGS
|
||||
for at_cxx_std in '' \
|
||||
${CXX98_CXXFLAGS:+"$CXX98_CXXFLAGS"} \
|
||||
${CXX03_CXXFLAGS:+"$CXX03_CXXFLAGS"} \
|
||||
${CXX11_CXXFLAGS:+"$CXX11_CXXFLAGS"} \
|
||||
${CXX14_CXXFLAGS:+"$CXX14_CXXFLAGS"} \
|
||||
${CXX17_CXXFLAGS:+"$CXX17_CXXFLAGS"} \
|
||||
${CXX2A_CXXFLAGS:+"$CXX2A_CXXFLAGS"}
|
||||
[[at_for_each_std_CXXFLAGS_save=$CXXFLAGS
|
||||
for at_std in '' \
|
||||
${CXX98_CXXFLAGS:+"$CXX98_CXXFLAGS"} \
|
||||
${CXX03_CXXFLAGS:+"$CXX03_CXXFLAGS"} \
|
||||
${CXX11_CXXFLAGS:+"$CXX11_CXXFLAGS"} \
|
||||
${CXX14_CXXFLAGS:+"$CXX14_CXXFLAGS"} \
|
||||
${CXX17_CXXFLAGS:+"$CXX17_CXXFLAGS"} \
|
||||
${CXX2A_CXXFLAGS:+"$CXX2A_CXXFLAGS"}
|
||||
do
|
||||
]AS_ECHO(["======== Testing with C++ standard flags: '$at_cxx_std'"])[
|
||||
CXXFLAGS="$at_for_each_cxx_CXXFLAGS_save $at_cxx_std"
|
||||
CXXFLAGS="$at_for_each_std_CXXFLAGS_save $at_std"
|
||||
]$1[
|
||||
done
|
||||
CXXFLAGS=$at_for_each_cxx_CXXFLAGS_save
|
||||
CXXFLAGS=$at_for_each_std_CXXFLAGS_save
|
||||
]])
|
||||
|
||||
## ------ ##
|
||||
@@ -619,7 +625,8 @@ m4_define([AT_MAIN_DEFINE(java)],
|
||||
}
|
||||
}]])
|
||||
|
||||
|
||||
m4_define([AT_LANG_FOR_EACH_STD(java)],
|
||||
[$1])
|
||||
|
||||
## --------------- ##
|
||||
## Running Bison. ##
|
||||
@@ -777,7 +784,7 @@ m4_define([AT_QUELL_VALGRIND],
|
||||
# otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
|
||||
# with trailing .o removed, and ".c" appended.
|
||||
m4_define([AT_COMPILE],
|
||||
[AT_CHECK([$BISON_C_WORKS], 0, ignore, ignore)
|
||||
[AT_SKIP_IF([[! $BISON_C_WORKS]])
|
||||
AT_CHECK(m4_join([ ],
|
||||
[$CC $CFLAGS $CPPFLAGS $3],
|
||||
[m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
|
||||
@@ -797,7 +804,7 @@ AT_CHECK(m4_join([ ],
|
||||
# with trailing ".o" removed, and ".cc" appended.
|
||||
m4_define([AT_COMPILE_CXX],
|
||||
[AT_KEYWORDS(c++)
|
||||
AT_CHECK([$BISON_CXX_WORKS], 0, ignore, ignore)
|
||||
AT_SKIP_IF([[! $BISON_CXX_WORKS]])
|
||||
AT_CHECK(m4_join([ ],
|
||||
[$CXX $CXXFLAGS $CPPFLAGS $3],
|
||||
[m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
|
||||
@@ -819,6 +826,11 @@ AT_CHECK([[$SHELL ../../../javacomp.sh ]$1],
|
||||
[[0]], [ignore], [ignore])])
|
||||
|
||||
|
||||
# AT_LANG_FOR_EACH_STD(BODY)
|
||||
# -------------------------------
|
||||
m4_define([AT_LANG_FOR_EACH_STD], [AT_LANG_DISPATCH([$0], $@)])
|
||||
|
||||
|
||||
# AT_LANG_COMPILE(OUTPUT, [SOURCES = OUTPUT.c], [EXTRA-COMPILER-FLAGS])
|
||||
# ---------------------------------------------------------------------
|
||||
# Compile SOURCES into OUTPUT. Skip if compiler does not work.
|
||||
@@ -854,8 +866,8 @@ m4_define([AT_LANG_HDR(c++)], [hh])
|
||||
# Compile OUTPUT.y to OUTPUT.c, OUTPUT.cc, or OUTPUT.java, and then
|
||||
# compile it to OUTPUT or OUTPUT.class. If OTHER is specified, compile
|
||||
# OUTPUT-OTHER.c, OUTPUT-OTHER.cc, or OUTPUT-OTHER.java to OUTPUT or
|
||||
# OUTPUT.java along with it. Relies on AT_SKEL_CC_IF and
|
||||
# AT_SKEL_JAVA_IF.
|
||||
# OUTPUT.java along with it. Relies on AT_CXX_IF and
|
||||
# AT_JAVA_IF.
|
||||
m4_define([AT_FULL_COMPILE],
|
||||
[AT_BISON_CHECK([-o $1.AT_LANG_EXT $1.y])
|
||||
AT_LANG_COMPILE([$1],
|
||||
@@ -904,6 +916,38 @@ AT_PARSER_CHECK([./c-and-cxx])
|
||||
])
|
||||
|
||||
|
||||
# AT_REQUIRE_CXX_STD(STD, [IF-FAIL = SKIP])
|
||||
# -----------------------------------------
|
||||
# Skip unless this compiler supports at least C++ STD (e.g., "11",
|
||||
# "14", etc.).
|
||||
m4_define([AT_REQUIRE_CXX_STD],
|
||||
[AT_DATA([check.cc],
|
||||
[[int main ()
|
||||
{
|
||||
#if !defined __cplusplus || __cplusplus < ]m4_case([$1],
|
||||
[98], [199711],
|
||||
[03], [199711],
|
||||
[11], [201103],
|
||||
[14], [201402],
|
||||
[17], [201703],
|
||||
[2a], [201709],
|
||||
[m4_fatal([$0: invalid arguments: $@])])[
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
]])
|
||||
AT_COMPILE_CXX([check])
|
||||
AT_CHECK([@&t@./check], [ignore])
|
||||
m4_ifval([$2],
|
||||
[if test $at_status != 0; then
|
||||
$2
|
||||
fi],
|
||||
[SKIP_IF([test $at_status != 0])])
|
||||
])
|
||||
|
||||
|
||||
# AT_SKIP_IF_EXCEPTION_SUPPORT_IS_POOR
|
||||
# ------------------------------------
|
||||
# Check that we can expect exceptions to be handled properly.
|
||||
@@ -913,11 +957,11 @@ m4_define([AT_SKIP_IF_EXCEPTION_SUPPORT_IS_POOR],
|
||||
[[#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
void foo()
|
||||
void foo ()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw std::runtime_error("foo");
|
||||
throw std::runtime_error ("foo");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -926,11 +970,11 @@ void foo()
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
int main ()
|
||||
{
|
||||
try
|
||||
{
|
||||
foo();
|
||||
foo ();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
||||
+14
-14
@@ -1,19 +1,19 @@
|
||||
## Makefile for Bison testsuite.
|
||||
|
||||
# Copyright (C) 2000-2015, 2018 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/>.
|
||||
## Copyright (C) 2000-2015, 2018 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/>.
|
||||
|
||||
EXTRA_DIST += $(TESTSUITE_AT) %D%/testsuite %D%/testsuite.h
|
||||
|
||||
|
||||
+2
-2
@@ -1012,7 +1012,7 @@ start:
|
||||
;
|
||||
|
||||
%destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a';
|
||||
%printer { fprintf (yyoutput, "PRINTER"); } 'a';
|
||||
%printer { fprintf (yyo, "PRINTER"); } 'a';
|
||||
|
||||
%%
|
||||
]AT_YYERROR_DEFINE[
|
||||
@@ -1565,7 +1565,7 @@ exp: 'a' { fprintf (stdout, "x: %d, y: %d\n", x, y); };
|
||||
]AT_YYERROR_DEFINE[
|
||||
]AT_YYLEX_DEFINE(["a"])[
|
||||
|
||||
]AT_SKEL_CC_IF(
|
||||
]AT_CXX_IF(
|
||||
[int
|
||||
yyparse (int x, int y)
|
||||
{
|
||||
|
||||
+8
-11
@@ -396,10 +396,10 @@ AT_BISON_OPTION_PUSHDEFS([%skeleton "$1"])
|
||||
# properly to the linker, and is unable to save a file named this way.
|
||||
# Don't try with such compilers.
|
||||
AT_DATA([\"\\\"\".c],
|
||||
[[int main() { return 0; }
|
||||
[[int main (void) { return 0; }
|
||||
]])
|
||||
|
||||
AT_CHECK([AT_SKEL_CC_IF([$CXX $CXXFLAGS], [$CC $CFLAGS]) $CPPFLAGS \"\\\"\".c -o \"\\\"\" ||
|
||||
AT_CHECK([AT_CXX_IF([$CXX $CXXFLAGS], [$CC $CFLAGS]) $CPPFLAGS \"\\\"\".c -o \"\\\"\" ||
|
||||
exit 77], [0], [ignore], [ignore])
|
||||
|
||||
AT_DATA_GRAMMAR([\"\\\"\".y],
|
||||
@@ -418,16 +418,16 @@ exp: '0'
|
||||
]AT_MAIN_DEFINE[
|
||||
]])
|
||||
|
||||
# Maybe we tried to create a file name that the file system does not
|
||||
# support.
|
||||
AT_SKIP_IF([[test ! -f \"\\\"\".y]])
|
||||
AT_FULL_COMPILE([\"\\\"\"])
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_CLEANUP
|
||||
])
|
||||
|
||||
AT_TEST([yacc.c])
|
||||
AT_TEST([glr.c])
|
||||
AT_TEST([lalr1.cc])
|
||||
AT_TEST([glr.cc])
|
||||
m4_map_args([AT_TEST], [yacc.c], [glr.c], [lalr1.cc], [glr.cc])
|
||||
|
||||
m4_popdef([AT_TEST])
|
||||
|
||||
@@ -453,15 +453,12 @@ AT_DATA_GRAMMAR([input.y],
|
||||
exp: '0'
|
||||
]])
|
||||
AT_BISON_CHECK([--no-lines -o input.AT_LANG_EXT -d input.y])
|
||||
AT_CHECK([[grep '#line' ]AT_SKEL_CC_IF([*.cc *.hh], [*.c *.h])], 1)
|
||||
AT_CHECK([[grep '#line'] *.AT_LANG_EXT *.AT_LANG_HDR], 1)
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
|
||||
AT_CLEANUP
|
||||
])
|
||||
|
||||
AT_TEST([yacc.c])
|
||||
AT_TEST([glr.c])
|
||||
AT_TEST([lalr1.cc])
|
||||
AT_TEST([glr.cc])
|
||||
m4_map_args([AT_TEST], [yacc.c], [glr.c], [lalr1.cc], [glr.cc])
|
||||
|
||||
m4_popdef([AT_TEST])
|
||||
|
||||
+2
-2
@@ -401,7 +401,7 @@ yylex (void)
|
||||
static int
|
||||
get_args (int argc, const char **argv)
|
||||
{
|
||||
int res;
|
||||
long res;
|
||||
char *endp;
|
||||
assert (argc == 2); (void) argc;
|
||||
res = strtol (argv[1], &endp, 10);
|
||||
@@ -409,7 +409,7 @@ get_args (int argc, const char **argv)
|
||||
assert (0 <= res);
|
||||
assert (res <= INT_MAX);
|
||||
assert (errno != ERANGE);
|
||||
return res;
|
||||
return (int) res;
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
+71
-25
@@ -66,14 +66,19 @@ AT_CLEANUP
|
||||
# $3: PARSER-ACTION,
|
||||
# $4: INPUT,
|
||||
# $5: SCANNER-ACTION,
|
||||
# $6: RESULT)
|
||||
# $6: RESULT,
|
||||
# $7: REQUIREMENT)
|
||||
# --------------------------------------
|
||||
# Compile the grammar and check the expected result.
|
||||
# BISON-DIRECTIVES are passed to AT_SETUP, contrary to MORE-BISON-DIRECTIVES.
|
||||
#
|
||||
# Use REQUIREMENT e.g. skip the test if the compiler does not meet the
|
||||
# requirements.
|
||||
m4_pushdef([_AT_TEST],
|
||||
[
|
||||
AT_SETUP([$1])
|
||||
AT_KEYWORDS([api.value.type])
|
||||
|
||||
AT_BISON_OPTION_PUSHDEFS([%debug $1 $2])
|
||||
AT_DATA_GRAMMAR([test.y],
|
||||
[[%debug
|
||||
@@ -99,9 +104,13 @@ start: $3;
|
||||
]AT_MAIN_DEFINE[
|
||||
]])
|
||||
|
||||
AT_FULL_COMPILE([[test]])
|
||||
AT_PARSER_CHECK([./test], 0, [$6
|
||||
], [stderr])
|
||||
AT_LANG_FOR_EACH_STD([
|
||||
$7
|
||||
AT_FULL_COMPILE([[test]])
|
||||
AT_PARSER_CHECK([[./test]], 0, [[$6
|
||||
]])
|
||||
])
|
||||
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
AT_CLEANUP
|
||||
])
|
||||
@@ -111,7 +120,8 @@ AT_CLEANUP
|
||||
# $3: PARSER-ACTION,
|
||||
# $4: INPUT,
|
||||
# $5: SCANNER-ACTION,
|
||||
# $6: RESULT)
|
||||
# $6: RESULT,
|
||||
# $7: REQUIREMENT)
|
||||
# --------------------------------------
|
||||
# Check with and without %defines, to avoid regressions. It turns out
|
||||
# that in that case yacc.c calls the set-up of the %union twice,
|
||||
@@ -121,8 +131,8 @@ AT_CLEANUP
|
||||
# a second time doubled the side-effects and resulted in a double
|
||||
# definition of the union members.
|
||||
m4_pushdef([AT_TEST],
|
||||
[_AT_TEST([$1], [$2], [$3], [$4], [$5], [$6])
|
||||
_AT_TEST([$1 %defines], [$2], [$3], [$4], [$5], [$6])
|
||||
[_AT_TEST([$1], [$2], [$3], [$4], [$5], [$6], [$7])
|
||||
_AT_TEST([$1 %defines], [$2], [$3], [$4], [$5], [$6], [$7])
|
||||
])
|
||||
|
||||
m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
|
||||
@@ -156,7 +166,7 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
|
||||
[if (res)
|
||||
{
|
||||
AT_VAL.ival = (res - '0') * 10;
|
||||
AT_VAL.fval = (res - '0') / 10.f;
|
||||
AT_VAL.fval = (float) (res - '0') / 10.f;
|
||||
}],
|
||||
[30 0.3])
|
||||
|
||||
@@ -175,8 +185,8 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
|
||||
};
|
||||
}
|
||||
%token <up->ival> '1' '2'
|
||||
%printer { ]AT_SKEL_CC_IF([[yyoutput << $$]],
|
||||
[[fprintf (yyo, "%d", $$)]])[; } <up->ival>
|
||||
%printer { ]AT_CXX_IF([[yyo << $$]],
|
||||
[[fprintf (yyo, "%d", $$)]])[; } <up->ival>
|
||||
],
|
||||
['1' '2'
|
||||
{
|
||||
@@ -231,10 +241,10 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
|
||||
%define api.value.type union],
|
||||
[%token <int> ONE 101;
|
||||
%token <float> TWO 102 THREE 103;
|
||||
%printer { ]AT_SKEL_CC_IF([[yyoutput << $$]],
|
||||
[[fprintf (yyo, "%d", $$)]])[; } <int>
|
||||
%printer { ]AT_SKEL_CC_IF([[yyoutput << $$]],
|
||||
[[fprintf (yyo, "%f", $$)]])[; } <float>
|
||||
%printer { ]AT_CXX_IF([[yyo << $$]],
|
||||
[[fprintf (yyo, "%d", $$)]])[; } <int>
|
||||
%printer { ]AT_CXX_IF([[yyo << $$]],
|
||||
[[fprintf (yyo, "%f", $$)]])[; } <float>
|
||||
],
|
||||
[ONE TWO THREE { printf ("%d %2.1f %2.1f\n", $1, $2, $3); }],
|
||||
[{ 101, 102, 103, EOF }],
|
||||
@@ -248,17 +258,53 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc], [glr.cc]],
|
||||
|
||||
# A Bison-defined variant, for lalr1.cc only.
|
||||
m4_if(b4_skel, [lalr1.cc], [
|
||||
AT_TEST([%skeleton "]b4_skel["
|
||||
%define api.value.type variant],
|
||||
[%token <int> '1';
|
||||
%token <std::string> '2';],
|
||||
['1' '2' { std::cout << $1 << ", " << $2 << '\n'; }],
|
||||
["12"],
|
||||
[if (res == '1')
|
||||
AT_VAL.build(10);
|
||||
else if (res == '2')
|
||||
AT_VAL.build<std::string>("two");],
|
||||
[10, two])])
|
||||
AT_TEST([%skeleton "]b4_skel["
|
||||
%define api.value.type variant],
|
||||
[%token <int> '1';
|
||||
%token <std::string> '2';],
|
||||
['1' '2' { std::cout << $1 << ", " << $2 << '\n'; }],
|
||||
["12"],
|
||||
[if (res == '1')
|
||||
AT_VAL.build (10);
|
||||
else if (res == '2')
|
||||
AT_VAL.build<std::string> ("two");],
|
||||
[10, two])
|
||||
|
||||
# Test a regression where we passed user types (we can include
|
||||
# commas) to a CPP macro.
|
||||
AT_TEST([%skeleton "]b4_skel["
|
||||
%define api.value.type variant],
|
||||
[%token <std::pair<int, int>> '1';
|
||||
%token <std::pair<std::string, std::string>> '2';],
|
||||
['1' '2'
|
||||
{
|
||||
std::cout << $1.first << ':' << $1.second << ", "
|
||||
<< $2.first << ':' << $2.second << '\n';
|
||||
}],
|
||||
["12"],
|
||||
[if (res == '1')
|
||||
AT_VAL.build (std::make_pair (10, 11));
|
||||
else if (res == '2')
|
||||
AT_VAL.build (std::make_pair<std::string, std::string> ("two", "deux"));],
|
||||
[10:11, two:deux])
|
||||
|
||||
# Move-only types.
|
||||
AT_TEST([%skeleton "]b4_skel["
|
||||
%code requires { #include <memory> }
|
||||
%define api.value.type variant],
|
||||
[[%token <std::unique_ptr<int>> '1';
|
||||
%token <std::unique_ptr<std::string>> '2';]],
|
||||
['1' '2' { std::cout << *$1 << ", " << *$2 << '\n'; }],
|
||||
["12"],
|
||||
[[if (res == '1')
|
||||
]AT_VAL[.emplace <std::unique_ptr<int>>
|
||||
(std::make_unique <int> (10));
|
||||
else if (res == '2')
|
||||
]AT_VAL[.emplace <std::unique_ptr<std::string>>
|
||||
(std::make_unique <std::string> ("two"));]],
|
||||
[10, two],
|
||||
[AT_REQUIRE_CXX_STD(14, [echo "$at_std not supported"; continue])])])
|
||||
])
|
||||
])
|
||||
|
||||
m4_popdef([AT_TEST])
|
||||
|
||||
Reference in New Issue
Block a user