├── .gitattributes ├── .gitignore ├── .gitmodules ├── .prev-version ├── .project ├── .x-sc_require_config_h ├── .x-sc_unmarked_diagnostics ├── .x-update-copyright ├── AUTHORS ├── COPYING ├── ChangeLog-1998 ├── ChangeLog-2012 ├── Makefile.am ├── NEWS ├── PACKAGING ├── README ├── README-alpha ├── README-hacking ├── REFERENCES ├── THANKS ├── TODO ├── bootstrap ├── bootstrap.conf ├── build-aux ├── .gitignore ├── cross-options.pl ├── git-log-fix ├── local.mk ├── move-if-change ├── prev-version.txt ├── update-b4-copyright └── update-package-copyright-year ├── cfg.mk ├── configure.ac ├── data ├── README ├── bison.m4 ├── c++-skel.m4 ├── c++.m4 ├── c-skel.m4 ├── c.m4 ├── glr.c ├── glr.cc ├── java-skel.m4 ├── java.m4 ├── lalr1.cc ├── lalr1.java ├── lalr1.php ├── local.mk ├── location.cc ├── m4sugar │ ├── foreach.m4 │ └── m4sugar.m4 ├── php-skel.m4 ├── php.m4 ├── stack.hh ├── variant.hh ├── xslt │ ├── bison.xsl │ ├── xml2dot.xsl │ ├── xml2text.xsl │ └── xml2xhtml.xsl └── yacc.c ├── djgpp ├── Makefile.maint ├── README.in ├── config.bat ├── config.sed ├── config.site ├── config_h.sed ├── djunpack.bat ├── fnchange.lst ├── local.mk ├── subpipe.c ├── subpipe.h └── testsuite.sed ├── doc ├── .gitignore ├── Doxyfile.in ├── bison.texinfo ├── bison.x ├── local.mk ├── refcard.tex └── yacc.1.in ├── etc ├── .gitignore ├── README ├── bench.pl.in ├── local.mk └── prefix-gnulib-mk ├── examples ├── calc++ │ ├── .gitignore │ ├── calc++.test │ ├── local.mk │ └── y.tab.h ├── extexi ├── local.mk ├── mfcalc │ ├── .gitignore │ ├── local.mk │ └── mfcalc.test ├── php │ └── calc │ │ ├── calc.php │ │ └── calc.y ├── rpcalc │ ├── .gitignore │ ├── local.mk │ └── rpcalc.test ├── test └── variant.yy ├── externals └── bootstrap.cfg ├── lib ├── .gitignore ├── abitset.c ├── abitset.h ├── bbitset.h ├── bitset.c ├── bitset.h ├── bitset_stats.c ├── bitset_stats.h ├── bitsetv-print.c ├── bitsetv-print.h ├── bitsetv.c ├── bitsetv.h ├── ebitset.c ├── ebitset.h ├── get-errno.c ├── get-errno.h ├── lbitset.c ├── lbitset.h ├── libiberty.h ├── local.mk ├── main.c ├── timevar.c ├── timevar.def ├── timevar.h ├── vbitset.c ├── vbitset.h └── yyerror.c ├── m4 ├── .gitignore ├── bison-i18n.m4 ├── c-working.m4 ├── cxx.m4 ├── dmalloc.m4 ├── m4.m4 ├── subpipe.m4 └── timevar.m4 ├── po ├── .gitignore └── POTFILES.in ├── runtime-po ├── .gitignore └── POTFILES.in ├── src ├── .gitignore ├── AnnotationList.c ├── AnnotationList.h ├── InadequacyList.c ├── InadequacyList.h ├── LR0.c ├── LR0.h ├── Sbitset.c ├── Sbitset.h ├── assoc.c ├── assoc.h ├── closure.c ├── closure.h ├── complain.c ├── complain.h ├── conflicts.c ├── conflicts.h ├── derives.c ├── derives.h ├── files.c ├── files.h ├── flex-scanner.h ├── getargs.c ├── getargs.h ├── gram.c ├── gram.h ├── graphviz.c ├── graphviz.h ├── ielr.c ├── ielr.h ├── lalr.c ├── lalr.h ├── local.mk ├── location.c ├── location.h ├── main.c ├── muscle-tab.c ├── muscle-tab.h ├── named-ref.c ├── named-ref.h ├── nullable.c ├── nullable.h ├── output.c ├── output.h ├── parse-gram.c ├── parse-gram.h ├── parse-gram.y ├── print-xml.c ├── print-xml.h ├── print.c ├── print.h ├── print_graph.c ├── print_graph.h ├── reader.c ├── reader.h ├── reduce.c ├── reduce.h ├── relation.c ├── relation.h ├── scan-code-c.c ├── scan-code.h ├── scan-code.l ├── scan-gram-c.c ├── scan-gram.h ├── scan-gram.l ├── scan-skel-c.c ├── scan-skel.h ├── scan-skel.l ├── state.c ├── state.h ├── symlist.c ├── symlist.h ├── symtab.c ├── symtab.h ├── system.h ├── tables.c ├── tables.h ├── uniqstr.c └── uniqstr.h └── tests ├── .gitignore ├── actions.at ├── atlocal.in ├── bison.in ├── c++.at ├── calc.at ├── conflicts.at ├── cxx-type.at ├── existing.at ├── glr-regression.at ├── headers.at ├── input.at ├── java.at ├── local.at ├── local.mk ├── named-refs.at ├── output.at ├── php.at ├── push.at ├── reduce.at ├── regression.at ├── sets.at ├── skeletons.at ├── synclines.at ├── testsuite.at └── torture.at /.gitattributes: -------------------------------------------------------------------------------- 1 | ChangeLog merge=merge-changelog 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /*.cache 2 | /*.flc 3 | /*.prj 4 | /*~ 5 | /.tarball-version 6 | /.version 7 | /ABOUT-NLS 8 | /COPYING 9 | /ChangeLog 10 | /GNUmakefile 11 | /INSTALL 12 | /Makefile 13 | /Makefile.in 14 | /_* 15 | /a.exe 16 | /a.out 17 | /aclocal.m4 18 | /b.out 19 | /bison-* 20 | /conf[0-9]* 21 | /confdefs* 22 | /config.log 23 | /config.status 24 | /configure 25 | /configure.lineno 26 | /conftest* 27 | /gnulib 28 | /javacomp.sh 29 | /javaexec.sh 30 | /maint.mk 31 | /patches 32 | /releases 33 | /stamp-h* 34 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "gnulib"] 2 | path = gnulib 3 | url = git://git.savannah.gnu.org/gnulib.git 4 | [submodule "submodules/autoconf"] 5 | path = submodules/autoconf 6 | url = git://git.sv.gnu.org/autoconf.git 7 | -------------------------------------------------------------------------------- /.prev-version: -------------------------------------------------------------------------------- 1 | 2.3b 2 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | patch_list='Bison Patches ' 2 | -------------------------------------------------------------------------------- /.x-sc_require_config_h: -------------------------------------------------------------------------------- 1 | data/glr.c 2 | data/yacc.c 3 | lib/yyerror.c 4 | -------------------------------------------------------------------------------- /.x-sc_unmarked_diagnostics: -------------------------------------------------------------------------------- 1 | doc/bison.texinfo 2 | -------------------------------------------------------------------------------- /.x-update-copyright: -------------------------------------------------------------------------------- 1 | COPYING 2 | ^bootstrap$ 3 | ^doc/fdl\.texi$ 4 | ^doc/gpl-3\.0\.texi$ 5 | ^doc/yacc\.1\.in$ 6 | ^src/parse-gram\.h$ 7 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Authors of GNU Bison. 2 | 3 | Bison was written primarily by Robert Corbett. 4 | 5 | Richard Stallman made it Yacc-compatible. 6 | 7 | Wilfred Hansen of Carnegie Mellon University added multicharacter 8 | string literals and other features (Bison 1.25, 1995). 9 | 10 | Akim Demaille rewrote the parser in Bison, and changed the back end to 11 | use M4 (1.50, 2002). 12 | 13 | Paul Hilfinger added GLR support (Bison 1.50, 2002). 14 | 15 | Joel E. Denny contributed canonical-LR support, and invented and added 16 | IELR and LAC (Lookahead Correction) support (Bison 2.5, 2011). 17 | 18 | Paolo Bonzini contributed Java support (Bison 2.4, 2008). 19 | 20 | Alex Rozenman added named reference support (Bison 2.5, 2011). 21 | 22 | Paul Eggert fixed a million portability issues, arbitrary limitations, 23 | and nasty bugs. 24 | 25 | ----- 26 | 27 | Copyright (C) 1998-2012 Free Software Foundation, Inc. 28 | 29 | This file is part of Bison, the GNU Compiler Compiler. 30 | 31 | This program is free software: you can redistribute it and/or modify 32 | it under the terms of the GNU General Public License as published by 33 | the Free Software Foundation, either version 3 of the License, or 34 | (at your option) any later version. 35 | 36 | This program is distributed in the hope that it will be useful, 37 | but WITHOUT ANY WARRANTY; without even the implied warranty of 38 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 39 | GNU General Public License for more details. 40 | 41 | You should have received a copy of the GNU General Public License 42 | along with this program. If not, see . 43 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in. 2 | 3 | # Copyright (C) 2001-2012 Free Software Foundation, Inc. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | AUTOMAKE_OPTIONS = subdir-objects 19 | ACLOCAL_AMFLAGS = -I m4 20 | 21 | SUBDIRS = po runtime-po . 22 | 23 | # Files installed for use by Automake. 24 | aclocaldir = @aclocaldir@ 25 | aclocal_DATA = m4/bison-i18n.m4 26 | 27 | EXTRA_DIST = .prev-version .version \ 28 | cfg.mk ChangeLog-1998 ChangeLog-2012 PACKAGING 29 | 30 | ## Running the bison from this tarball. To generate our own parser, 31 | ## but also to run the tests. Of course, you ought to keep a sane 32 | ## version of Bison nearby... 33 | BISON = $(top_builddir)/tests/bison 34 | BISON_IN = $(top_srcdir)/tests/bison.in 35 | YACC = $(BISON) -y 36 | AM_YFLAGS = -d -v --warnings=all,error --report=all 37 | 38 | # Initialization before completion by local.mk's. 39 | AM_CFLAGS = $(WARN_CFLAGS) 40 | # Find builddir/src/scan-code.c etc. 41 | AM_CPPFLAGS = -I. -Ilib -I$(top_srcdir) -I$(top_srcdir)/lib 42 | BUILT_SOURCES = 43 | DISTCLEANFILES = 44 | EXTRA_DIST += $(dist_TESTS) 45 | MOSTLYCLEANDIRS = 46 | MOSTLYCLEANFILES = 47 | SUFFIXES = 48 | TESTS = $(dist_TESTS) 49 | check_PROGRAMS = 50 | dist_TESTS = 51 | noinst_LIBRARIES = 52 | 53 | include build-aux/local.mk 54 | include data/local.mk 55 | include djgpp/local.mk 56 | include doc/local.mk 57 | include etc/local.mk 58 | include examples/local.mk 59 | include lib/local.mk 60 | include src/local.mk 61 | include tests/local.mk 62 | 63 | # See comments in build-aux/git-version-gen. However, we make .version depend 64 | # on configure so that .version and VERSION/PACKAGE_VERSION stay in sync in the 65 | # working copy (for example, when you run autoreconf && make). Allowing these 66 | # to fall out of sync appears to have little potential to improve Bison build 67 | # efficiency (even if we were to replace VERSION/PACKAGE_VERSION with .version 68 | # everywhere possible). On the other hand, it could be harmful. For example, 69 | # a developer might naively reference .version in a test case while the bison 70 | # executable still compiles with VERSION, and so the test case might fail or 71 | # pass incorrectly. 72 | BUILT_SOURCES += $(top_srcdir)/.version 73 | $(top_srcdir)/.version: configure 74 | echo $(VERSION) > $@-t && mv $@-t $@ 75 | dist-hook: gen-ChangeLog 76 | echo $(VERSION) > $(distdir)/.tarball-version 77 | 78 | .PHONY: update-b4-copyright update-package-copyright-year 79 | update-b4-copyright: 80 | find data -type f \ 81 | | grep -v -E '^data/bison.m4$$' \ 82 | | xargs $(build_aux)/$@ 83 | @echo 'warning: src/parse-gram.[hc] may need to be regenerated.' 84 | update-package-copyright-year: 85 | $(build_aux)/$@ configure.ac 86 | 87 | gen_start_date = 2012-01-16 88 | .PHONY: gen-ChangeLog 89 | gen-ChangeLog: 90 | $(AM_V_GEN)if test -d .git; then \ 91 | $(top_srcdir)/build-aux/gitlog-to-changelog \ 92 | --no-cluster \ 93 | --amend=$(srcdir)/build-aux/git-log-fix \ 94 | --since=$(gen_start_date) > $(distdir)/cl-t; \ 95 | rm -f $(distdir)/ChangeLog; \ 96 | mv $(distdir)/cl-t $(distdir)/ChangeLog; \ 97 | fi 98 | -------------------------------------------------------------------------------- /PACKAGING: -------------------------------------------------------------------------------- 1 | Packaging hints for binary package distributors 2 | =============================================== 3 | 4 | Although the source of the bison package comes as a single package, 5 | in distributions of binary packages the installed files should 6 | be split into two packages: 7 | 8 | bison-runtime 9 | Contents: Runtime libraries and programs. 10 | Audience: Anyone who wants to run internationalized programs 11 | that contain Bison-generated parsers. 12 | 13 | bison 14 | Contents: Tools and documentation for developers that use Bison. 15 | Audience: Anyone who wants to develop programs that use parsers. 16 | Dependencies: requires bison-runtime. 17 | 18 | The 'bison-runtime' binary package is much smaller than the 'bison' 19 | binary package. It should be included in any distribution that 20 | contains localized programs that use the diagnostics contained in 21 | Bison-generated parsers. 22 | 23 | If you want to install both packages at the same time, you simply do 24 | at the toplevel directory: 25 | 26 | ./configure 27 | make 28 | make install 29 | 30 | After installation, the file 31 | 32 | $prefix/share/locale/*/LC_MESSAGES/bison-runtime.mo 33 | 34 | belongs to the bison-runtime package; all other installed files belong 35 | to the bison package. 36 | 37 | ----- 38 | 39 | Copyright (C) 2002, 2005, 2009-2012 Free Software Foundation, Inc. 40 | 41 | This file is part of Bison, the GNU Compiler Compiler. 42 | 43 | This program is free software: you can redistribute it and/or modify 44 | it under the terms of the GNU General Public License as published by 45 | the Free Software Foundation, either version 3 of the License, or 46 | (at your option) any later version. 47 | 48 | This program is distributed in the hope that it will be useful, 49 | but WITHOUT ANY WARRANTY; without even the implied warranty of 50 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 51 | GNU General Public License for more details. 52 | 53 | You should have received a copy of the GNU General Public License 54 | along with this program. If not, see . 55 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This package contains the GNU Bison parser generator. 2 | 3 | * Installation 4 | ** Build 5 | See the file INSTALL for generic compilation and installation 6 | instructions. 7 | 8 | Bison requires GNU m4 1.4.6 or later. See: 9 | 10 | ftp://ftp.gnu.org/gnu/m4/m4-1.4.6.tar.gz 11 | 12 | ** Internationalization 13 | Bison supports two catalogues: one for Bison itself (i.e., for the 14 | maintainer-side parser generation), and one for the generated parsers 15 | (i.e., for the user-side parser execution). The requirements between 16 | both differ: bison needs ngettext, the generated parsers do not. To 17 | simplify the build system, neither are installed if ngettext is not 18 | supported, even if generated parsers could have been localized. See 19 | http://lists.gnu.org/archive/html/bug-bison/2009-08/msg00006.html for 20 | more details. 21 | 22 | * Questions 23 | See the section FAQ in the documentation (doc/bison.info) for 24 | frequently asked questions. The documentation is also available in 25 | PDF and HTML, provided you have a recent version of Texinfo installed: 26 | run "make pdf" or "make html". 27 | 28 | If you have questions about using Bison and the documentation does 29 | not answer them, please send mail to . 30 | 31 | * Bug reports 32 | Please send bug reports to . Please include the 33 | version number from `bison --version', and a complete, self-contained 34 | test case in each bug report. 35 | 36 | * Copyright statements 37 | For any copyright year range specified as YYYY-ZZZZ in this package, 38 | note that the range specifies every single year in that closed interval. 39 | 40 | 41 | Local Variables: 42 | mode: outline 43 | End: 44 | 45 | ----- 46 | 47 | Copyright (C) 1992, 1998-1999, 2003-2005, 2008-2012 Free Software 48 | Foundation, Inc. 49 | 50 | This file is part of Bison, the GNU Compiler Compiler. 51 | 52 | This program is free software: you can redistribute it and/or modify 53 | it under the terms of the GNU General Public License as published by 54 | the Free Software Foundation, either version 3 of the License, or 55 | (at your option) any later version. 56 | 57 | This program is distributed in the hope that it will be useful, 58 | but WITHOUT ANY WARRANTY; without even the implied warranty of 59 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 60 | GNU General Public License for more details. 61 | 62 | You should have received a copy of the GNU General Public License 63 | along with this program. If not, see . 64 | -------------------------------------------------------------------------------- /README-alpha: -------------------------------------------------------------------------------- 1 | -*- text -*- 2 | 3 | This is a test release of this package. Using it more or less 4 | implicitly signs you up to help us find whatever problems you report. 5 | 6 | The documentation still needs more work. Suggestions welcome. 7 | Patches even more welcome. 8 | 9 | Please send comments and problem reports about this test release to 10 | . This program will get better only if you report 11 | the problems you encounter. 12 | 13 | ----- 14 | 15 | Copyright (C) 2002, 2004, 2009-2012 Free Software Foundation, Inc. 16 | 17 | This file is part of GNU Bison. 18 | 19 | This program is free software: you can redistribute it and/or modify 20 | it under the terms of the GNU General Public License as published by 21 | the Free Software Foundation, either version 3 of the License, or 22 | (at your option) any later version. 23 | 24 | This program is distributed in the hope that it will be useful, 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | GNU General Public License for more details. 28 | 29 | You should have received a copy of the GNU General Public License 30 | along with this program. If not, see . 31 | -------------------------------------------------------------------------------- /REFERENCES: -------------------------------------------------------------------------------- 1 | From phr Tue Jul 8 10:36:19 1986 2 | Date: Tue, 8 Jul 86 00:52:24 EDT 3 | From: phr (Paul Rubin) 4 | To: riferguson%watmath.waterloo.edu@CSNET-RELAY.ARPA, tower 5 | Subject: Re: Bison documentation? 6 | 7 | The main difference between Bison and Yacc that I know of is that 8 | Bison supports the @N construction, which gives you access to 9 | the starting and ending line number and character number associated 10 | with any of the symbols in the current rule. 11 | 12 | Also, Bison supports the command `%expect N' which says not to mention 13 | the conflicts if there are N shift/reduce conflicts and no reduce/reduce 14 | conflicts. 15 | 16 | The differences in the algorithms stem mainly from the horrible 17 | kludges that Johnson had to perpetrate to make Yacc fit in a PDP-11. 18 | 19 | Also, Bison uses a faster but less space-efficient encoding for the 20 | parse tables (see Corbett's PhD thesis from Berkeley, "Static 21 | Semantics in Compiler Error Recovery", June 1985, Report No. UCB/CSD 22 | 85/251), and more modern technique for generating the lookahead sets. 23 | (See Frank DeRemer and Thomas Pennello, "Efficient Computation of 24 | LALR(1) Look-Ahead Sets", ACM Transactions on Programming Languages 25 | and Systems (TOPLAS) 4, 4 (October 1982), 615-649. Their 26 | technique is the standard one now.) 27 | 28 | paul rubin 29 | free software foundation 30 | 31 | 32 | [DeRemer-Pennello reference corrected by Paul Eggert , 33 | 2004-06-21.] 34 | -------------------------------------------------------------------------------- /bootstrap.conf: -------------------------------------------------------------------------------- 1 | # Bootstrap configuration. 2 | 3 | # Copyright (C) 2006-2012 Free Software Foundation, Inc. 4 | 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | # gnulib modules used by this package. 19 | gnulib_modules=' 20 | announce-gen argmatch assert calloc-posix close closeout config-h c-strcase 21 | configmake dirname error extensions fdl fopen-safer gendocs getopt-gnu 22 | gettext git-version-gen gitlog-to-changelog 23 | gpl-3.0 hash inttypes isnan javacomp-script 24 | javaexec-script ldexpl maintainer-makefile malloc-gnu mbschr mbsrchr 25 | mbswidth obstack perror pipe-posix progname 26 | quote quotearg realloc-posix 27 | spawn-pipe stdbool stpcpy strdup-posix strerror strtoul strverscmp 28 | unistd unistd-safer unlocked-io update-copyright unsetenv verify 29 | warnings xalloc xalloc-die xstrndup 30 | 31 | fprintf-posix printf-posix snprintf-posix sprintf-posix 32 | vsnprintf-posix vsprintf-posix 33 | ' 34 | 35 | # Additional xgettext options to use. Use "\\\newline" to break lines. 36 | XGETTEXT_OPTIONS=$XGETTEXT_OPTIONS'\\\ 37 | --from-code=UTF-8\\\ 38 | --flag=asprintf:2:c-format\\\ 39 | --flag=complain:1:c-format --flag=complain_at:2:c-format\\\ 40 | --flag=fatal:1:c-format --flag=fatal_at:2:c-format\\\ 41 | --flag=warn:1:c-format --flag=warn_at:2:c-format\\\ 42 | --flag=unexpected_end:2:c-format\\\ 43 | ' 44 | XGETTEXT_OPTIONS_RUNTIME=$XGETTEXT_OPTIONS'\\\ 45 | --keyword=YY_ \\\ 46 | ' 47 | 48 | # Gettext supplies these files, but we don't need them since 49 | # we don't have an intl subdirectory. 50 | excluded_files=' 51 | m4/glibc2.m4 52 | m4/intdiv0.m4 53 | m4/intl.m4 54 | m4/intldir.m4 55 | m4/intmax.m4 56 | m4/lcmessage.m4 57 | m4/lock.m4 58 | m4/longdouble.m4 59 | m4/signed.m4 60 | m4/uintmax_t.m4 61 | m4/ulonglong.m4 62 | m4/visibility.m4 63 | ' 64 | 65 | gnulib_tool_option_extras='--symlink --makefile-name=gnulib.mk' 66 | 67 | bootstrap_post_import_hook() 68 | { 69 | # Massage lib/gnulib.mk before using it later in the bootstrapping process. 70 | etc/prefix-gnulib-mk --lib-name=$gnulib_name lib/$gnulib_mk 71 | 72 | # Ensure that ChangeLog exists, for automake. 73 | test -f ChangeLog || touch ChangeLog 74 | } 75 | 76 | bootstrap_epilogue() 77 | { 78 | # Make sure we don't need src/bison, which usually doesn't exist at 79 | # the time of a bootstrap. 80 | touch src/parse-gram.[ch] 81 | } 82 | 83 | # Keep our bootstrap script in sync with gnulib's. If we ever need to 84 | # maintain our own bootstrap script again, set this to false, remove 85 | # the bootstrap entry from the file .x-update-copyright, and add any 86 | # needed copyright years to the copyright statement in the bootstrap 87 | # script. 88 | # FIXME: temporary bootstrap_sync=true 89 | -------------------------------------------------------------------------------- /build-aux/.gitignore: -------------------------------------------------------------------------------- 1 | /announce-gen 2 | /arg-nonnull.h 3 | /c++defs.h 4 | /compile 5 | /config.guess 6 | /config.rpath 7 | /config.sub 8 | /depcomp 9 | /gendocs.sh 10 | /git-version-gen 11 | /gitlog-to-changelog 12 | /install-sh 13 | /javacomp.sh.in 14 | /javaexec.sh.in 15 | /link-warning.h 16 | /mdate-sh 17 | /missing 18 | /texinfo.tex 19 | /update-copyright 20 | /useless-if-before-free 21 | /vc-list-files 22 | /warn-on-use.h 23 | /ylwrap 24 | -------------------------------------------------------------------------------- /build-aux/cross-options.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env perl 2 | 3 | use warnings; 4 | use 5.005; 5 | use strict; 6 | 7 | my %option; 8 | my %directive; 9 | my $scanner = `grep -i '"%[a-z]' $ARGV[0]`; 10 | $scanner =~ s/"\[-_\]"/-/g; 11 | while () 12 | { 13 | if (/^\s* # Initial spaces. 14 | (?:(-\w),\s+)? # $1: $short: Possible short option. 15 | (--[-\w]+) # $2: $long: Long option. 16 | (\[?) # $3: $opt: '[' iff the argument is optional. 17 | (?:=(\S+))? # $4: $arg: Possible argument name. 18 | \s # Spaces. 19 | /x) 20 | { 21 | my ($short, $long, $opt, $arg) = ($1, $2, $3, $4); 22 | $short = '' if ! defined $short; 23 | $short = '-d' if $long eq '--defines' && ! $short; 24 | my $dir = '%' . substr($long, 2); 25 | if (index ($scanner, "\"$dir\"") < 0) 26 | { 27 | if ($long eq '--force-define') { $dir = '%define'; } 28 | else { $dir = ''; } 29 | } 30 | if ($arg) 31 | { 32 | # if $opt, $arg contains the closing ]. 33 | substr ($arg, -1) = '' 34 | if $opt eq '['; 35 | $arg =~ s/^=//; 36 | $arg = lc ($arg); 37 | my $dir_arg = $arg; 38 | # If the argument is compite (e.g., for --define[=NAME[=VALUE]]), 39 | # put each word in @var, to build @var{name}[=@var{value}], not 40 | # @var{name[=value]}]. 41 | $arg =~ s/(\w+)/\@var{$1}/g; 42 | my $long_arg = "=$arg"; 43 | if ($opt eq '[') { 44 | $long_arg = "[$long_arg]"; 45 | $arg = "[$arg]"; 46 | } 47 | # For arguments of directives: this only works if all arguments 48 | # are strings and have the same syntax as on the command line. 49 | if ($dir_arg eq 'name[=value]') 50 | { 51 | $dir_arg = '@var{name} ["@var{value}"]'; 52 | } 53 | else 54 | { 55 | $dir_arg =~ s/(\w+)/\@var{"$1"}/g; 56 | $dir_arg = '[' . $dir_arg . ']' 57 | if $opt eq '['; 58 | } 59 | $long = "$long$long_arg"; 60 | $short = "$short $arg" if $short && $short ne '-d'; 61 | $dir = "$dir $dir_arg" if $dir; 62 | } 63 | $option{$long} = $short; 64 | $directive{$long} = $dir; 65 | } 66 | } 67 | 68 | my $sep = ''; 69 | foreach my $long (sort keys %option) 70 | { 71 | # Avoid trailing spaces. 72 | print $sep; 73 | $sep = "\n"; 74 | print '@item @option{', $long, "}\n\@tab"; 75 | print ' @option{', $option{$long}, '}' if $option{$long}; 76 | print "\n\@tab"; 77 | print ' @code{', $directive{$long}, '}' if $directive{$long}; 78 | print "\n"; 79 | } 80 | -------------------------------------------------------------------------------- /build-aux/git-log-fix: -------------------------------------------------------------------------------- 1 | # This file is expected to be used via gitlog-to-changelog's --amend=FILE 2 | # option. It specifies what changes to make to each given SHA1's commit 3 | # log and metadata, using Perl-eval'able expressions. 4 | -------------------------------------------------------------------------------- /build-aux/local.mk: -------------------------------------------------------------------------------- 1 | EXTRA_DIST += \ 2 | build-aux/cross-options.pl \ 3 | build-aux/move-if-change \ 4 | build-aux/prev-version.txt \ 5 | build-aux/update-b4-copyright 6 | -------------------------------------------------------------------------------- /build-aux/move-if-change: -------------------------------------------------------------------------------- 1 | ../gnulib/build-aux/move-if-change -------------------------------------------------------------------------------- /build-aux/prev-version.txt: -------------------------------------------------------------------------------- 1 | 2.0 2 | -------------------------------------------------------------------------------- /build-aux/update-package-copyright-year: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -0777 -pi 2 | 3 | # In configure.ac, update PACKAGE_COPYRIGHT_YEAR to the current year. 4 | 5 | # Copyright (C) 2010-2012 Free Software Foundation, Inc. 6 | # 7 | # This program is free software; you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation; either version 3, or (at your option) 10 | # any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | use strict; 21 | use warnings; 22 | 23 | my $this_year = $ENV{UPDATE_COPYRIGHT_YEAR}; 24 | if (!$this_year || $this_year !~ m/^\d{4}$/) 25 | { 26 | my ($sec, $min, $hour, $mday, $month, $year) = localtime (time ()); 27 | $this_year = $year + 1900; 28 | } 29 | my $old_re = <<'EOF' 30 | ( 31 | MACRO\( 32 | \[PACKAGE_COPYRIGHT_YEAR], 33 | \s*\[ 34 | ) 35 | (\d{4}) 36 | (?=]) 37 | EOF 38 | ; 39 | foreach my $macro ("AC_DEFINE", "AC_SUBST") 40 | { 41 | my $this_old_re = $old_re; 42 | $this_old_re =~ s/MACRO/$macro/; 43 | if (!s/$this_old_re/$1$this_year/x) 44 | { 45 | print STDERR 46 | "$ARGV: warning: failed to update PACKAGE_COPYRIGHT_YEAR in" 47 | . " $macro.\n"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /cfg.mk: -------------------------------------------------------------------------------- 1 | # Customize maint.mk -*- makefile -*- 2 | 3 | # Copyright (C) 2008-2012 Free Software Foundation, Inc. 4 | 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | # It's useful to run maintainer-*check* targets during development, but we 19 | # don't want to wait on a recompile because of an update to $(VERSION). Thus, 20 | # override the _is-dist-target from GNUmakefile so that maintainer-*check* 21 | # targets are filtered out. 22 | _is-dist-target = $(filter-out %clean maintainer-check% maintainer-%-check, \ 23 | $(filter maintainer-% dist% alpha beta major,$(MAKECMDGOALS))) 24 | 25 | # Use alpha.gnu.org for alpha and beta releases. 26 | # Use ftp.gnu.org for major releases. 27 | gnu_ftp_host-alpha = alpha.gnu.org 28 | gnu_ftp_host-beta = alpha.gnu.org 29 | gnu_ftp_host-major = ftp.gnu.org 30 | gnu_rel_host = $(gnu_ftp_host-$(RELEASE_TYPE)) 31 | 32 | url_dir_list = \ 33 | ftp://$(gnu_rel_host)/gnu/bison 34 | 35 | # Tests not to run as part of "make distcheck". 36 | local-checks-to-skip = \ 37 | sc_immutable_NEWS \ 38 | sc_prohibit_atoi_atof 39 | 40 | # The local directory containing the checked-out copy of gnulib used in 41 | # this release. Used solely to get a date for the "announcement" target. 42 | gnulib_dir = $(srcdir)/gnulib 43 | 44 | bootstrap-tools = autoconf,automake,flex,gettext,gnulib 45 | 46 | announcement_Cc_ = \ 47 | bug-bison@gnu.org, help-bison@gnu.org, bison-patches@gnu.org, \ 48 | coordinator@translationproject.org 49 | 50 | update-copyright: update-b4-copyright update-package-copyright-year 51 | update-copyright-env = \ 52 | UPDATE_COPYRIGHT_FORCE=1 UPDATE_COPYRIGHT_USE_INTERVALS=1 53 | 54 | exclude = $(foreach a,$(1),$(eval exclude_file_name_regexp--sc_$(a))) 55 | $(call exclude, \ 56 | bindtextdomain=^lib/main.c$$ \ 57 | program_name=^lib/main.c$$ \ 58 | prohibit_always-defined_macros=^data/yacc.c|^djgpp/ \ 59 | prohibit_always-defined_macros+=?|^src/(parse-gram.c|system.h)$$ \ 60 | prohibit_always-defined_macros+=?|^tests/regression.at$$ \ 61 | prohibit_empty_lines_at_EOF=^src/parse-gram.h$$ \ 62 | prohibit_strcmp=^doc/bison\.texinfo$$ \ 63 | require_config_h_first=^(lib/yyerror|data/(glr|yacc))\.c$$ \ 64 | space_tab=^tests/(input|c\+\+)\.at$$ \ 65 | unmarked_diagnostics=^djgpp/ \ 66 | ) 67 | -------------------------------------------------------------------------------- /data/README: -------------------------------------------------------------------------------- 1 | -*- outline -*- 2 | 3 | This directory contains data needed by Bison. 4 | 5 | * Skeletons 6 | Bison skeletons: the general shapes of the different parser kinds, 7 | that are specialized for specific grammars by the bison program. 8 | 9 | Currently, the supported skeletons are: 10 | 11 | - yacc.c 12 | It used to be named bison.simple: it corresponds to C Yacc 13 | compatible LALR(1) parsers. 14 | 15 | - lalr1.cc 16 | Produces a C++ parser class. 17 | 18 | - lalr1.java 19 | Produces a Java parser class. 20 | 21 | - lalr1.php 22 | Produces a PHP parser class. 23 | 24 | - glr.c 25 | A Generalized LR C parser based on Bison's LALR(1) tables. 26 | 27 | - glr.cc 28 | A Generalized LR C++ parser. Actually a C++ wrapper around glr.c. 29 | 30 | These skeletons are the only ones supported by the Bison team. 31 | Because the interface between skeletons and the bison program is not 32 | finished, *we are not bound to it*. In particular, Bison is not 33 | mature enough for us to consider that ``foreign skeletons'' are 34 | supported. 35 | 36 | * m4sugar 37 | This directory contains M4sugar, sort of an extended library for M4, 38 | which is used by Bison to instantiate the skeletons. 39 | 40 | * xslt 41 | This directory contains XSLT programs that transform Bison's XML output 42 | into various formats. 43 | 44 | - bison.xsl 45 | A library of routines used by the other XSLT programs. 46 | 47 | - xml2dot.xsl 48 | Conversion into GraphViz's dot format. 49 | 50 | - xml2text.xsl 51 | Conversion into text. 52 | 53 | - xml2xhtml.xsl 54 | Conversion into XHTML. 55 | 56 | ----- 57 | 58 | Copyright (C) 2002, 2008-2012 Free Software Foundation, Inc. 59 | 60 | This file is part of GNU Bison. 61 | 62 | This program is free software: you can redistribute it and/or modify 63 | it under the terms of the GNU General Public License as published by 64 | the Free Software Foundation, either version 3 of the License, or 65 | (at your option) any later version. 66 | 67 | This program is distributed in the hope that it will be useful, 68 | but WITHOUT ANY WARRANTY; without even the implied warranty of 69 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 70 | GNU General Public License for more details. 71 | 72 | You should have received a copy of the GNU General Public License 73 | along with this program. If not, see . 74 | -------------------------------------------------------------------------------- /data/c++-skel.m4: -------------------------------------------------------------------------------- 1 | -*- Autoconf -*- 2 | 3 | # C++ skeleton dispatching for Bison. 4 | 5 | # Copyright (C) 2006-2007, 2009-2012 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | b4_glr_if( [m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.cc]])]) 21 | b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.cc]])]) 22 | 23 | m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[lalr1.cc]]) 24 | m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) 25 | 26 | m4_include(b4_used_skeleton) 27 | -------------------------------------------------------------------------------- /data/c-skel.m4: -------------------------------------------------------------------------------- 1 | -*- Autoconf -*- 2 | 3 | # C skeleton dispatching for Bison. 4 | 5 | # Copyright (C) 2006-2007, 2009-2012 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | b4_glr_if( [m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.c]])]) 21 | b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.c]])]) 22 | 23 | m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[yacc.c]]) 24 | m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) 25 | 26 | m4_include(b4_used_skeleton) 27 | -------------------------------------------------------------------------------- /data/java-skel.m4: -------------------------------------------------------------------------------- 1 | -*- Autoconf -*- 2 | 3 | # Java skeleton dispatching for Bison. 4 | 5 | # Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | b4_glr_if( [b4_complain([%%glr-parser not supported for Java])]) 21 | b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for Java])]) 22 | 23 | m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[lalr1.java]]) 24 | m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) 25 | 26 | m4_include(b4_used_skeleton) 27 | -------------------------------------------------------------------------------- /data/local.mk: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2002, 2005-2012 Free Software Foundation, Inc. 2 | 3 | ## This program is free software: you can redistribute it and/or modify 4 | ## it under the terms of the GNU General Public License as published by 5 | ## the Free Software Foundation, either version 3 of the License, or 6 | ## (at your option) any later version. 7 | ## 8 | ## This program is distributed in the hope that it will be useful, 9 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | ## GNU General Public License for more details. 12 | ## 13 | ## You should have received a copy of the GNU General Public License 14 | ## along with this program. If not, see . 15 | 16 | dist_pkgdata_DATA = \ 17 | data/README \ 18 | data/bison.m4 \ 19 | data/c++-skel.m4 \ 20 | data/c++.m4 \ 21 | data/c-skel.m4 \ 22 | data/c.m4 \ 23 | data/glr.c \ 24 | data/glr.cc \ 25 | data/java-skel.m4 \ 26 | data/java.m4 \ 27 | data/lalr1.cc \ 28 | data/lalr1.java \ 29 | data/lalr1.php \ 30 | data/location.cc \ 31 | data/php-skel.m4 \ 32 | data/php.m4 \ 33 | data/stack.hh \ 34 | data/variant.hh \ 35 | data/yacc.c 36 | 37 | m4sugardir = $(pkgdatadir)/m4sugar 38 | dist_m4sugar_DATA = \ 39 | data/m4sugar/foreach.m4 \ 40 | data/m4sugar/m4sugar.m4 41 | 42 | xsltdir = $(pkgdatadir)/xslt 43 | dist_xslt_DATA = \ 44 | data/xslt/bison.xsl \ 45 | data/xslt/xml2dot.xsl \ 46 | data/xslt/xml2text.xsl \ 47 | data/xslt/xml2xhtml.xsl 48 | -------------------------------------------------------------------------------- /data/m4sugar/foreach.m4: -------------------------------------------------------------------------------- 1 | ../../submodules/autoconf/lib/m4sugar/foreach.m4 -------------------------------------------------------------------------------- /data/m4sugar/m4sugar.m4: -------------------------------------------------------------------------------- 1 | ../../submodules/autoconf/lib/m4sugar/m4sugar.m4 -------------------------------------------------------------------------------- /data/php-skel.m4: -------------------------------------------------------------------------------- 1 | -*- Autoconf -*- 2 | 3 | # PHP skeleton dispatching for Bison. 4 | 5 | # Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | b4_glr_if( [b4_complain([%%glr-parser not supported for PHP])]) 21 | b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for PHP])]) 22 | 23 | m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[lalr1.php]]) 24 | m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) 25 | 26 | m4_include(b4_used_skeleton) 27 | -------------------------------------------------------------------------------- /data/stack.hh: -------------------------------------------------------------------------------- 1 | # C++ skeleton for Bison 2 | 3 | # Copyright (C) 2002-2012 Free Software Foundation, Inc. 4 | 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | m4_pushdef([b4_copyright_years], 19 | [2002-2012]) 20 | 21 | # We do want M4 expansion after # for CPP macros. 22 | m4_changecom() 23 | m4_divert_push(0)dnl 24 | @output(b4_dir_prefix[]stack.hh@)@ 25 | b4_copyright([Stack handling for Bison parsers in C++])[ 26 | 27 | #ifndef BISON_STACK_HH 28 | # define BISON_STACK_HH 29 | 30 | #include 31 | 32 | ]b4_namespace_open[ 33 | template > 34 | class stack 35 | { 36 | public: 37 | // Hide our reversed order. 38 | typedef typename S::reverse_iterator iterator; 39 | typedef typename S::const_reverse_iterator const_iterator; 40 | 41 | stack () 42 | : seq_ () 43 | { 44 | } 45 | 46 | stack (unsigned int n) 47 | : seq_ (n) 48 | { 49 | } 50 | 51 | inline 52 | T& 53 | operator [] (unsigned int i) 54 | { 55 | return seq_[i]; 56 | } 57 | 58 | inline 59 | const T& 60 | operator [] (unsigned int i) const 61 | { 62 | return seq_[i]; 63 | } 64 | 65 | inline 66 | void 67 | push (const T& t) 68 | { 69 | seq_.push_front (t); 70 | } 71 | 72 | inline 73 | void 74 | pop (unsigned int n = 1) 75 | { 76 | for (; n; --n) 77 | seq_.pop_front (); 78 | } 79 | 80 | inline 81 | typename S::size_type 82 | size () const 83 | { 84 | return seq_.size (); 85 | } 86 | 87 | inline 88 | const_iterator 89 | begin () const 90 | { 91 | return seq_.rbegin (); 92 | } 93 | 94 | inline 95 | const_iterator 96 | end () const 97 | { 98 | return seq_.rend (); 99 | } 100 | 101 | private: 102 | /// The wrapped container. 103 | S seq_; 104 | }; 105 | 106 | /// Present a slice of the top of a stack. 107 | template > 108 | class slice 109 | { 110 | public: 111 | slice (const S& stack, unsigned int range) 112 | : stack_ (stack), 113 | range_ (range) 114 | { 115 | } 116 | 117 | inline 118 | const T& 119 | operator [] (unsigned int i) const 120 | { 121 | return stack_[range_ - i]; 122 | } 123 | 124 | private: 125 | const S& stack_; 126 | unsigned int range_; 127 | }; 128 | ]b4_namespace_close[ 129 | 130 | #endif // not BISON_STACK_HH[]dnl 131 | ] 132 | m4_divert_pop(0) 133 | m4_popdef([b4_copyright_years])dnl 134 | m4_changecom([#]) 135 | -------------------------------------------------------------------------------- /data/xslt/bison.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 23 | 24 | 27 | 28 | 33 | 38 | 43 | 49 | 55 | 56 | 57 | 58 | 59 | 60 | 67 | 68 | 69 | 70 | 71 | 75 | 79 | 80 | s 81 | 82 | 83 | r 84 | 85 | 86 | 87 | 88 | 89 | , 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /djgpp/Makefile.maint: -------------------------------------------------------------------------------- 1 | # DJGPP Maintainer's Makefile -*-Makefile-*- 2 | # Requires GNU sed 3 | 4 | ## Copyright (C) 2005-2012 Free Software Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | top_srcdir = .. 20 | srcdir = . 21 | 22 | SHELL = /bin/sh 23 | 24 | all: README 25 | 26 | README: README.in $(top_srcdir)/configure 27 | PACKAGE=`grep "^[ ]*PACKAGE=" $(top_srcdir)/configure | sed -e 's/^[ ]*PACKAGE=//' -e s/[\"\']//g`; \ 28 | VERSION=`grep "^[ ]*VERSION=" $(top_srcdir)/configure | sed -e 's/^[ ]*VERSION=//' -e s/[\"\']//g`; \ 29 | package_version=`echo "$${VERSION}" | sed 's/\.//g'`; \ 30 | tree_version=`echo "$${VERSION}" | sed 's/\.//2g'`; \ 31 | sed \ 32 | -e "s/@V@/$${PACKAGE}-$${VERSION}/g" \ 33 | -e "s/@VERSION@/$${VERSION}/g" \ 34 | -e "s/@PACKAGE_VERSION@/$$package_version/g" \ 35 | -e "s/@TREE_VERSION@/$$tree_version/g" \ 36 | $(srcdir)/README.in > t-$@ 37 | mv t-$@ $@ 38 | -------------------------------------------------------------------------------- /djgpp/config.site: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # This is the config.site file for configuring GNU packages 4 | # which are to be built with DJGPP tools. 5 | 6 | # Copyright (C) 2005-2012 Free Software Foundation, Inc. 7 | 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | 21 | 22 | # Include the djgpp subdirectory in PATH, so that getconf is found 23 | PATH="$srcdir/djgpp:$PATH" 24 | 25 | # These two variables are required, otherwise looking for 26 | # programs along the PATH will not work. 27 | PATH_SEPARATOR=: 28 | PATH_EXPAND=y 29 | 30 | # This is required in for "test -f foo" to find foo.exe 31 | export TEST_FINDS_EXE=y 32 | 33 | # The root of the DJGPP tree serves as the default prefix 34 | test "x$prefix" = xNONE && prefix='/dev/env/DJDIR' 35 | 36 | # This is required for config.status script to be run, since 37 | # ./configure runs it by invoking ${CONFIG_SHELL-/bin/sh} 38 | CONFIG_SHELL=${CONFIG_SHELL='sh'} 39 | 40 | # These are set here so the generated Makefile's will be good 41 | # for every DJGPP installation, not only the one where the 42 | # package was configured. 43 | # $INSTALL must be an absolute path name, otherwise config.status 44 | # will try to prepend ./ and ../ to it when it goes into subdirs. 45 | INSTALL=${INSTALL='/dev/env/DJDIR/bin/ginstall -c'} 46 | RANLIB=${RANLIB='ranlib'} 47 | GMSGFMT=${GMSGFMT='/dev/env/DJDIR/bin/msgfmt'} 48 | MSGFMT=${MSGFMT='/dev/env/DJDIR/bin/msgfmt'} 49 | XGETTEXT=${XGETTEXT='/dev/env/DJDIR/bin/xgettext'} 50 | AWK=${AWK='gawk'} 51 | 52 | # A sane default for emacs. 53 | ac_cv_path_EMACS=${EMACS='/dev/env/DJDIR/gnu/emacs/bin/emacs'} 54 | 55 | # A sane default for m4. 56 | ac_cv_path_M4=${M4='/dev/env/DJDIR/bin/m4'} 57 | 58 | # A sane default for grep. 59 | ac_cv_path_GREP=${GREP='/dev/env/DJDIR/bin/grep'} 60 | 61 | # A sane default for egrep. 62 | ac_cv_path_EGREP=${EGREP='/dev/env/DJDIR/bin/egrep'} 63 | 64 | # A sane default for fgrep. 65 | ac_cv_path_FGREP=${FGREP='/dev/env/DJDIR/bin/fgrep'} 66 | 67 | # A sane default for sed. 68 | ac_cv_path_SED=${SED='/dev/env/DJDIR/bin/sed'} 69 | 70 | # A sane default for mkdir. 71 | ac_cv_path_mkdir=${MKDIR_P='/dev/env/DJDIR/bin/mkdir -p'} 72 | 73 | # These are set here so the generated libtool will be good 74 | # for every DJGPP installation, not only the one where the 75 | # package was configured. 76 | NM=${NM='nm'} 77 | LD=${LD='ld'} 78 | 79 | # Force the test for 'ln -s' to report 'cp -pf'. 80 | ac_cv_prog_LN_S='cp -pf' 81 | 82 | # There is no fork and vfork functionality. 83 | ac_cv_func_fork=no 84 | ac_cv_func_vfork=no 85 | ac_cv_func_pipe=no 86 | -------------------------------------------------------------------------------- /djgpp/config_h.sed: -------------------------------------------------------------------------------- 1 | # sed script for DJGPP specific editing of config.hin 2 | 3 | # Copyright (C) 2005-2012 Free Software Foundation, Inc. 4 | 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | 19 | $ a\ 20 | \ 21 | \ 22 | /* DJGPP specific defines. */\ 23 | \ 24 | #include \ 25 | #define TAB_EXT ((pathconf(NULL, _PC_NAME_MAX) > 12) ? ".tab" : "_tab")\ 26 | #define OUTPUT_EXT ((pathconf(NULL, _PC_NAME_MAX) > 12) ? ".output" : ".out")\ 27 | \ 28 | #define DEFAULT_TMPDIR "/dev/env/DJDIR/tmp" 29 | -------------------------------------------------------------------------------- /djgpp/djunpack.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | Rem 3 | Rem WARNING WARNING WARNING: This file needs to have DOS CRLF end-of-line 4 | Rem format, or else stock DOS/Windows shells will refuse to run it. 5 | Rem 6 | Rem This batch file unpacks the Bison distribution while simultaneously 7 | Rem renaming some of the files whose names are invalid on DOS or conflict 8 | Rem with other file names after truncation to DOS 8+3 namespace. 9 | Rem 10 | Rem Copyright (C) 2005-2012 Free Software Foundation, Inc. 11 | Rem 12 | Rem This program is free software: you can redistribute it and/or modify 13 | Rem it under the terms of the GNU General Public License as published by 14 | Rem the Free Software Foundation, either version 3 of the License, or 15 | Rem (at your option) any later version. 16 | Rem 17 | Rem This program is distributed in the hope that it will be useful, 18 | Rem but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | Rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | Rem GNU General Public License for more details. 21 | Rem 22 | Rem You should have received a copy of the GNU General Public License 23 | Rem along with this program. If not, see . 24 | Rem 25 | Rem 26 | Rem Invoke like this: 27 | Rem 28 | Rem djunpack bison-XYZ.tar.gz 29 | Rem or 30 | Rem djunpack bison-XYZ.tar.bz2 31 | Rem 32 | Rem where XYZ is the version number. If the argument includes leading 33 | Rem directories, it MUST use backslashes, not forward slashes. 34 | Rem 35 | 36 | set ENVIRONMENT_SIZE_TEST_STRING=ENVIRONMENT_SIZE_TEST_STRING 37 | if "%ENVIRONMENT_SIZE_TEST_STRING%"=="ENVIRONMENT_SIZE_TEST_STRING" GoTo EnvOk 38 | Rem If their environment space is too small, re-exec with a larger one 39 | command.com /e:4096 /c %0 %1 40 | GoTo End 41 | 42 | :EnvOk 43 | set ENVIRONMENT_SIZE_TEST_STRING= 44 | if "%1" == "" GoTo NoArgument 45 | if not exist %1 GoTo NoArchive 46 | Rem Extract top src dir from archive file. 47 | djtar -t %1 > top_src.dir 48 | Rem The following uses a feature of COPY whereby it does not copy 49 | Rem empty files. We need that because the previous line will create 50 | Rem an empty fnchange.tmp even if the command failed for some reason. 51 | copy top_src.dir junk.tmp > nul 52 | if not exist junk.tmp GoTo NoDjTar 53 | del junk.tmp 54 | sed "1{s/^.*bison-/djtar -x -p -o bison-/;s|$|djgpp/fnchange.lst %%1 > fnchange.tmp|};2,$d" top_src.dir > ext_list.bat 55 | Rem See the comment above about the reason for using COPY. 56 | copy ext_list.bat junk.tmp > nul 57 | if not exist junk.tmp GoTo NoSed 58 | del junk.tmp 59 | Rem Extract fnchange.lst from archive. 60 | call ext_list.bat %1 61 | del ext_list.bat 62 | sed "1{s|^.*bison-|s/@V@/bison-|;s|$|g|};2,$d" top_src.dir > version.sed 63 | sed -f version.sed < fnchange.tmp > fnchange.lst 64 | del version.sed 65 | del fnchange.tmp 66 | del top_src.dir 67 | Rem unpack the source distribution 68 | djtar -x -n fnchange.lst %1 69 | del fnchange.lst 70 | GoTo End 71 | 72 | :NoSed 73 | del junk.tmp 74 | echo FAIL: Sed is not available. 75 | GoTo End 76 | :NoDjTar 77 | del junk.tmp 78 | echo FAIL: DJTAR is not available or no fnchange.lst file in %1. 79 | GoTo End 80 | :NoArchive 81 | echo FAIL: the file %1 does not seem to exist. 82 | echo Remember that %1 cannot use forward slashes, only backslashes. 83 | GoTo End 84 | :NoArgument 85 | echo FAIL: no archive file has been specified. 86 | echo Remember that the file name cannot use forward slashes, only backslashes. 87 | :End 88 | -------------------------------------------------------------------------------- /djgpp/fnchange.lst: -------------------------------------------------------------------------------- 1 | @V@/build-aux/javacomp.sh.in @V@/build-aux/javacomp.sh-in 2 | @V@/build-aux/javaexec.sh.in @V@/build-aux/javaexec.sh-in 3 | @V@/data/c++-skel.m4 @V@/data/cxx-skel.m4 4 | @V@/data/c++.m4 @V@/data/cxx.m4 5 | @V@/doc/yacc.1.in @V@/doc/yacc.1-in 6 | @V@/etc/bench.pl.in @V@/etc/bench.pl-in 7 | @V@/examples/calc++/ @V@/examples/calcxx/ 8 | @V@/examples/calc++/Makefile.am @V@/examples/calcxx/Makefile.am 9 | @V@/examples/calc++/Makefile.in @V@/examples/calcxx/Makefile.in 10 | @V@/examples/calc++/calc++-scanner.cc @V@/examples/calcxx/calcxx-scanner.cc 11 | @V@/examples/calc++/calc++-scanner.ll @V@/examples/calcxx/calcxx-scanner.ll 12 | @V@/examples/calc++/calc++.cc @V@/examples/calcxx/calcxx.cc 13 | @V@/examples/calc++/calc++-driver.hh @V@/examples/calcxx/calcxx-driver.hh 14 | @V@/examples/calc++/calc++-driver.cc @V@/examples/calcxx/calcxx-driver.cc 15 | @V@/examples/calc++/stack.hh @V@/examples/calcxx/stack.hh 16 | @V@/examples/calc++/position.hh @V@/examples/calcxx/position.hh 17 | @V@/examples/calc++/location.hh @V@/examples/calcxx/location.hh 18 | @V@/examples/calc++/calc++-parser.hh @V@/examples/calcxx/calcxx-parser.hh 19 | @V@/examples/calc++/calc++-parser.cc @V@/examples/calcxx/calcxx-parser.cc 20 | @V@/examples/calc++/calc++-parser.stamp @V@/examples/calcxx/calcxx-parser.stamp 21 | @V@/examples/calc++/calc++-parser.yy @V@/examples/calcxx/calcxx-parser.yy 22 | @V@/examples/calc++/test @V@/examples/calcxx/test 23 | @V@/po/Makefile.in.in @V@/po/Makefile.in-in 24 | @V@/runtime-po/Makefile.in.in @V@/runtime-po/Makefile.in-in 25 | @V@/src/scan-gram-c.c @V@/src/c-scan-gram.c 26 | @V@/src/scan-skel-c.c @V@/src/c-scan-skel.c 27 | @V@/tests/c++.at @V@/tests/cxx.at 28 | -------------------------------------------------------------------------------- /djgpp/local.mk: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2008-2012 Free Software Foundation, Inc. 2 | 3 | ## This program is free software: you can redistribute it and/or modify 4 | ## it under the terms of the GNU General Public License as published by 5 | ## the Free Software Foundation, either version 3 of the License, or 6 | ## (at your option) any later version. 7 | ## 8 | ## This program is distributed in the hope that it will be useful, 9 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | ## GNU General Public License for more details. 12 | ## 13 | ## You should have received a copy of the GNU General Public License 14 | ## along with this program. If not, see . 15 | 16 | EXTRA_DIST += \ 17 | djgpp/Makefile.maint \ 18 | djgpp/README.in \ 19 | djgpp/config.bat \ 20 | djgpp/config.sed \ 21 | djgpp/config.site \ 22 | djgpp/config_h.sed \ 23 | djgpp/djunpack.bat \ 24 | djgpp/fnchange.lst \ 25 | djgpp/subpipe.c \ 26 | djgpp/subpipe.h \ 27 | djgpp/testsuite.sed 28 | -------------------------------------------------------------------------------- /djgpp/subpipe.h: -------------------------------------------------------------------------------- 1 | /* Subprocesses with pipes. 2 | 3 | Copyright (C) 2005-2012 Free Software Foundation, Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . */ 17 | 18 | /* Written by Juan Manuel Guerrero . */ 19 | 20 | #if HAVE_SYS_TYPES_H 21 | # include 22 | #endif 23 | 24 | void init_subpipe(void); 25 | pid_t create_subpipe(char const * const *, int[2]); 26 | void end_of_output_subpipe(pid_t, int[2]); 27 | void reap_subpipe(pid_t, char const *); 28 | -------------------------------------------------------------------------------- /djgpp/testsuite.sed: -------------------------------------------------------------------------------- 1 | # DJGPP specific configuration file. 2 | # Sed script for additional DJGPP specific editing 3 | # of the testsuite script generated by autoconf 2.61. 4 | 5 | # Copyright (C) 2007-2012 Free Software Foundation, Inc. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | 21 | # Remove disallowed characters from file names. 22 | 23 | s/~!@#\\\$%^&\*()-=_+{}\[\]|\\\\:;<>, ./~!@#\\$%^\&()-=_+{}[];, ./g 24 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | /*.info* 2 | /*~ 3 | /.dirstamp 4 | /bison.1 5 | /bison.aux 6 | /bison.cp 7 | /bison.cps 8 | /bison.dvi 9 | /bison.fn 10 | /bison.help 11 | /bison.html 12 | /bison.ky 13 | /bison.log 14 | /bison.pdf 15 | /bison.pg 16 | /bison.ps 17 | /bison.toc 18 | /bison.tp 19 | /bison.vr 20 | /cross-options.texi 21 | /fdl.texi 22 | /gendocs_template 23 | /gpl-3.0.texi 24 | /refcard.dvi 25 | /refcard.log 26 | /refcard.ps 27 | /stamp-vti 28 | /version.texi 29 | /yacc.1 30 | -------------------------------------------------------------------------------- /doc/bison.x: -------------------------------------------------------------------------------- 1 | [name] 2 | bison \- GNU Project parser generator (yacc replacement) 3 | 4 | [description] 5 | .I Bison 6 | is a parser generator in the style of 7 | .IR yacc (1). 8 | It should be upwardly compatible with input files designed 9 | for 10 | .IR yacc . 11 | .PP 12 | Input files should follow the 13 | .I yacc 14 | convention of ending in 15 | .BR .y . 16 | Unlike 17 | .IR yacc , 18 | the generated files do not have fixed names, but instead use the prefix 19 | of the input file. 20 | Moreover, if you need to put 21 | .I C++ 22 | code in the input file, you can end his name by a C++-like extension 23 | (.ypp or .y++), then bison will follow your extension to name the 24 | output file (.cpp or .c++). 25 | For instance, a grammar description file named 26 | .B parse.yxx 27 | would produce the generated parser in a file named 28 | .BR parse.tab.cxx , 29 | instead of 30 | .IR yacc 's 31 | .B y.tab.c 32 | or old 33 | .I Bison 34 | version's 35 | .BR parse.tab.c . 36 | .PP 37 | This description of the options that can be given to 38 | .I bison 39 | is adapted from the node 40 | .B Invocation 41 | in the 42 | .B bison.texinfo 43 | manual, which should be taken as authoritative. 44 | .PP 45 | .I Bison 46 | supports both traditional single-letter options and mnemonic long 47 | option names. Long option names are indicated with 48 | .B \-\- 49 | instead of 50 | .BR \- . 51 | Abbreviations for option names are allowed as long as they 52 | are unique. When a long option takes an argument, like 53 | .BR \-\-file-prefix , 54 | connect the option name and the argument with 55 | .BR = . 56 | 57 | [see also] 58 | .BR lex (1), 59 | .BR flex (1), 60 | .BR yacc (1). 61 | -------------------------------------------------------------------------------- /doc/yacc.1.in: -------------------------------------------------------------------------------- 1 | .TH YACC "1" "November 2007" "@PACKAGE_STRING@" "User Commands" 2 | .SH NAME 3 | yacc \- GNU Project parser generator 4 | .SH SYNOPSIS 5 | .B yacc 6 | [\fIOPTION\fR]... \fIFILE\fR 7 | .SH DESCRIPTION 8 | .I Yacc 9 | (Yet Another Compiler Compiler) is a parser generator. This 10 | version is a simple wrapper around 11 | .IR bison (1). 12 | It passes option 13 | \fB\-y\fR, \fB\-\-yacc\fR 14 | to activate the upward compatibility mode. See 15 | .IR bison (1) 16 | for more information. 17 | .SH AUTHOR 18 | Written by Paul Eggert. 19 | .SH "REPORTING BUGS" 20 | Report bugs to <@PACKAGE_BUGREPORT@>. 21 | .SH COPYRIGHT 22 | Copyright \(co @PACKAGE_COPYRIGHT_YEAR@ Free Software Foundation, Inc. 23 | .br 24 | This is free software; see the source for copying conditions. There is NO 25 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 26 | .SH "SEE ALSO" 27 | .BR lex (1), 28 | .BR flex (1), 29 | .BR bison (1). 30 | .PP 31 | The full documentation for 32 | .B bison 33 | is maintained as a Texinfo manual. If the 34 | .B info 35 | and 36 | .B bison 37 | programs are properly installed at your site, the command 38 | .IP 39 | .B info bison 40 | .PP 41 | should give you access to the complete manual. 42 | -------------------------------------------------------------------------------- /etc/.gitignore: -------------------------------------------------------------------------------- 1 | /bench.pl 2 | -------------------------------------------------------------------------------- /etc/README: -------------------------------------------------------------------------------- 1 | A directory of tools provided to people using CVS Bison. None of 2 | these is distributed. 3 | 4 | * bench.pl 5 | A primitive Perl script to run benches. Currently its only bench is 6 | the usual calculator: it has a lightweight processing part (but not 7 | null), so it is really emphasizing the cost of the whole parsing 8 | (including scanning and I/O). 9 | 10 | Set the envvars BISON and CC to the programs and flags you want to 11 | use. They default to bison and gcc. To run a non-installed bison 12 | from a tarball built in _build, I suggest the following. 13 | 14 | BISON=_build/tests/bison CC='gcc -O2' ./bench.pl 15 | 16 | (The _build/tests/bison wrapper makes sure that _build/src/bison will 17 | use the tarballs' skeletons, not those already installed as a 18 | straightforward use of _build/src/bison would.) 19 | 20 | -- 21 | 22 | Copyright (C) 2006, 2009-2012 Free Software Foundation, Inc. 23 | 24 | This file is part of Bison, the GNU Compiler Compiler. 25 | 26 | This program is free software: you can redistribute it and/or modify 27 | it under the terms of the GNU General Public License as published by 28 | the Free Software Foundation, either version 3 of the License, or 29 | (at your option) any later version. 30 | 31 | This program is distributed in the hope that it will be useful, 32 | but WITHOUT ANY WARRANTY; without even the implied warranty of 33 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 34 | GNU General Public License for more details. 35 | 36 | You should have received a copy of the GNU General Public License 37 | along with this program. If not, see . 38 | 39 | Local Variables: 40 | mode: outline 41 | End: 42 | -------------------------------------------------------------------------------- /etc/local.mk: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2006, 2008-2012 Free Software Foundation, Inc. 2 | 3 | ## This program is free software: you can redistribute it and/or modify 4 | ## it under the terms of the GNU General Public License as published by 5 | ## the Free Software Foundation, either version 3 of the License, or 6 | ## (at your option) any later version. 7 | ## 8 | ## This program is distributed in the hope that it will be useful, 9 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | ## GNU General Public License for more details. 12 | ## 13 | ## You should have received a copy of the GNU General Public License 14 | ## along with this program. If not, see . 15 | 16 | nodist_noinst_SCRIPTS = etc/bench.pl 17 | -------------------------------------------------------------------------------- /examples/calc++/.gitignore: -------------------------------------------------------------------------------- 1 | /*.o 2 | /*.tmp 3 | /.deps 4 | /calc++ 5 | /calc++-driver.cc 6 | /calc++-driver.hh 7 | /calc++-parser.cc 8 | /calc++-parser.hh 9 | /calc++-parser.output 10 | /calc++-parser.stamp 11 | /calc++-parser.yy 12 | /calc++-scanner.cc 13 | /calc++-scanner.ll 14 | /calc++.cc 15 | /calc++.exe 16 | /calc.stamp 17 | /location.hh 18 | /position.hh 19 | /stack.hh 20 | -------------------------------------------------------------------------------- /examples/calc++/calc++.test: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Copyright (C) 2005-2012 Free Software Foundation, Inc. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | cat >input <input <input <input <. 15 | 16 | ## ------------------- ## 17 | ## Parser generation. ## 18 | ## ------------------- ## 19 | 20 | CLEANFILES += examples/calc++/calc++-parser.output *.tmp 21 | 22 | # Don't depend on $(BISON) otherwise we would rebuild these files 23 | # in srcdir, including during distcheck, which is forbidden. 24 | examples/calc++/calc++-parser.stamp: $(BISON_IN) 25 | SUFFIXES += .yy .stamp 26 | .yy.stamp: 27 | $(AM_V_YACC)rm -f $@ 28 | $(AM_V_at)touch $@.tmp 29 | $(AM_V_at)$(YACCCOMPILE) -o $*.cc $< 30 | $(AM_V_at)mv -f $@.tmp $@ 31 | 32 | $(calc_sources_generated): examples/calc++/calc++-parser.stamp 33 | @test -f $@ || rm -f examples/calc++/calc++-parser.stamp 34 | @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) examples/calc++/calc++-parser.stamp 35 | 36 | 37 | ## -------------------- ## 38 | ## Building & testing. ## 39 | ## -------------------- ## 40 | 41 | # Avoid using BUILT_SOURCES which is too global. 42 | $(examples_calc___calc___OBJECTS): $(calc_sources_generated) 43 | 44 | calc_sources_extracted = \ 45 | examples/calc++/calc++-driver.cc \ 46 | examples/calc++/calc++-driver.hh \ 47 | examples/calc++/calc++-scanner.ll \ 48 | examples/calc++/calc++.cc 49 | calc_extracted = \ 50 | $(calc_sources_extracted) \ 51 | examples/calc++/calc++-parser.yy 52 | extracted += $(calc_extracted) 53 | calc_sources_generated = \ 54 | examples/calc++/calc++-parser.cc \ 55 | examples/calc++/calc++-parser.hh \ 56 | examples/calc++/location.hh \ 57 | examples/calc++/position.hh \ 58 | examples/calc++/stack.hh 59 | calc_sources = \ 60 | $(calc_sources_extracted) \ 61 | $(calc_sources_generated) 62 | 63 | if BISON_CXX_WORKS 64 | check_PROGRAMS += examples/calc++/calc++ 65 | nodist_examples_calc___calc___SOURCES = \ 66 | $(calc_sources) 67 | 68 | examples_calc___calc___CPPFLAGS = -I$(top_builddir)/examples/calc++ 69 | dist_TESTS += examples/calc++/calc++.test 70 | endif 71 | -------------------------------------------------------------------------------- /examples/calc++/y.tab.h: -------------------------------------------------------------------------------- 1 | // Work around an Automake 1.11.2 bug: it asks for the creation of 2 | // y.tab.c and y.tab.h and then renames them as calc++-parser.cc and 3 | // calc++-parser.h, but in the former it does not convert the 4 | // #include "y.tab.h". We don't want this to show in the 5 | // documentation. 6 | #include "calc++-parser.hh" 7 | -------------------------------------------------------------------------------- /examples/extexi: -------------------------------------------------------------------------------- 1 | # Extract all examples from the manual source. -*- AWK -*- 2 | 3 | # This file is part of GNU Bison 4 | 5 | # Copyright (C) 1992, 2000-2001, 2005-2006, 2009-2012 Free Software 6 | # Foundation, Inc. 7 | # 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | 21 | # This script is for use with any Awk that conforms to POSIX. 22 | # It was derived from a similar script tests/generate.awk in GNU m4. 23 | # 24 | # Usage: extexi input-file.texi ... -- [FILES to extract] 25 | BEGIN { 26 | if (!output_dir) 27 | output_dir = "."; 28 | for (argc = 1; argc < ARGC; ++argc) 29 | if (ARGV[argc] == "--") 30 | break; 31 | for (i = argc + 1; i < ARGC; ++i) 32 | file_wanted[basename(ARGV[i])] = ARGV[i]; 33 | ARGC = argc; 34 | } 35 | 36 | /^@node / { 37 | if (seq > 0) 38 | print "AT_CLEANUP"; 39 | 40 | split ($0, tmp, ","); 41 | node = substr(tmp[1], 7); 42 | seq = 0; 43 | } 44 | 45 | /^@comment file: / { 46 | if (file = file_wanted[$3]) 47 | message(" GEN " file); 48 | else 49 | message("SKIP " $3); 50 | } 51 | 52 | /^@(small)?example$/, /^@end (small)?example$/ { 53 | if (!file) 54 | next; 55 | 56 | if ($0 ~ /^@(small)?example$/) 57 | { 58 | input = files_output[file] ? "\n" : ""; 59 | 60 | # FNR is starting at 0 instead of 1, and 61 | # #line report the line number of the *next* line. 62 | # => + 2. 63 | # Note that recent Bison support it, but not Flex. 64 | if (file ~ /\.[chy]*$/) 65 | input = "#line " (FNR + 1) " \"" FILENAME "\"\n"; 66 | next; 67 | } 68 | 69 | if ($0 ~ /^@end (small)?example$/) 70 | { 71 | if (input == "") 72 | fatal("no contents: " file); 73 | 74 | input = normalize(input); 75 | # No spurious end of line: use printf. 76 | if (files_output[file]) 77 | # The parens around the output file seem to be required 78 | # by awk on Mac OS X Tiger (darwin 8.4.6). 79 | printf ("%s", input) >> (output_dir "/" file); 80 | else 81 | printf ("%s", input) > (output_dir "/" file); 82 | close (output_dir "/" file); 83 | files_output[file] = 1; 84 | 85 | file = input = ""; 86 | next; 87 | } 88 | 89 | input = input $0 "\n"; 90 | } 91 | 92 | 93 | # We have to handle CONTENTS line per line, since anchors in AWK are 94 | # referring to the whole string, not the lines. 95 | function normalize(contents, i, lines, n, line, res) { 96 | # Remove the Texinfo tags. 97 | n = split (contents, lines, "\n"); 98 | # We don't want the last field which empty: it's behind the last \n. 99 | for (i = 1; i < n; ++i) 100 | { 101 | line = lines[i]; 102 | 103 | # Whole line commands. 104 | if (line ~ /^@(c |comment|dots|end (ignore|group)|ignore|group)/) 105 | # Gperf accepts empty lines as valid input!!! 106 | if (file ~ /\.gperf$/) 107 | continue; 108 | else 109 | line = ""; 110 | 111 | gsub (/"@value\{VERSION\}"/, "\"" VERSION "\"", line) 112 | gsub (/^@result\{\}/, "", line); 113 | gsub (/^@error\{\}/, "", line); 114 | gsub ("@[{]", "{", line); 115 | gsub ("@}", "}", line); 116 | gsub ("@@", "@", line); 117 | gsub ("@comment.*", "", line); 118 | 119 | res = res line "\n"; 120 | } 121 | return res; 122 | } 123 | 124 | 125 | function basename(name, a, n) { 126 | n = split (name, a, "/"); 127 | return a[n]; 128 | } 129 | 130 | function message(msg) { 131 | if (! message_printed[msg]) 132 | { 133 | print "extexi: " msg > "/dev/stderr"; 134 | message_printed[msg] = 1; 135 | } 136 | } 137 | 138 | function fatal(msg) { 139 | message(msg); 140 | exit 1 141 | } 142 | -------------------------------------------------------------------------------- /examples/local.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2005, 2008-2012 Free Software Foundation, Inc. 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | dist_noinst_SCRIPTS = examples/extexi examples/test 17 | TEST_LOG_COMPILER = $(top_srcdir)/examples/test 18 | 19 | ## ------------ ## 20 | ## Extracting. ## 21 | ## ------------ ## 22 | 23 | doc = $(top_srcdir)/doc/bison.texinfo 24 | extexi = $(top_srcdir)/examples/extexi 25 | extract = $(AWK) -f $(extexi) -v VERSION="$(VERSION)" $(doc) -- 26 | extracted = 27 | MAINTAINERCLEANFILES += $(extracted) 28 | examples/extracted.stamp: $(doc) $(extexi) 29 | $(AM_V_GEN)rm -f $@ $@.tmp 30 | $(AM_V_at)touch $@.tmp 31 | $(AM_V_at)$(extract) $(extracted) 32 | $(AM_V_at)mv $@.tmp $@ 33 | 34 | $(extracted): examples/extracted.stamp 35 | @test -f $@ || rm -f examples/extracted.stamp 36 | @test -f $@ || $(MAKE) $(AM_MAKEFLAGS) examples/extracted.stamp 37 | 38 | include examples/calc++/local.mk 39 | include examples/mfcalc/local.mk 40 | include examples/rpcalc/local.mk 41 | -------------------------------------------------------------------------------- /examples/mfcalc/.gitignore: -------------------------------------------------------------------------------- 1 | /*.o 2 | /*.tmp 3 | /.deps 4 | /calc.h 5 | /mfcalc 6 | /mfcalc.c 7 | /mfcalc.exe 8 | /mfcalc.h 9 | /mfcalc.output 10 | /mfcalc.stamp 11 | /mfcalc.y 12 | -------------------------------------------------------------------------------- /examples/mfcalc/local.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2005-2006, 2008-2012 Free Software Foundation, Inc. 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | ## -------------------- ## 17 | ## Building & testing. ## 18 | ## -------------------- ## 19 | 20 | BUILT_SOURCES += $(mfcalc_sources) 21 | 22 | mfcalc_extracted = \ 23 | examples/mfcalc/calc.h \ 24 | examples/mfcalc/mfcalc.y 25 | mfcalc_sources = \ 26 | $(mfcalc_extracted) 27 | extracted += $(mfcalc_extracted) 28 | 29 | check_PROGRAMS += examples/mfcalc/mfcalc 30 | examples_mfcalc_mfcalc_LDADD = -lm 31 | nodist_examples_mfcalc_mfcalc_SOURCES = \ 32 | $(mfcalc_sources) 33 | 34 | examples_mfcalc_mfcalc_CPPFLAGS = -I$(top_builddir)/examples/mfcalc 35 | dist_TESTS += examples/mfcalc/mfcalc.test 36 | -------------------------------------------------------------------------------- /examples/mfcalc/mfcalc.test: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Copyright (C) 2005-2012 Free Software Foundation, Inc. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | cat >input <input <buffer = stream_get_contents ($is); 39 | $this->yypos = new Position (1, 0); 40 | } 41 | 42 | public function getStartPos() { 43 | return $this->yypos; 44 | } 45 | 46 | public function getEndPos() { 47 | return $this->yypos; 48 | } 49 | 50 | public function yyerror (Location $l, $s) 51 | { 52 | if (is_null ($l)) 53 | fputs (STDERR, $s . "\n"); 54 | else 55 | fputs (STDERR, $l . ": " . $s . "\n"); 56 | } 57 | 58 | private $yylval; 59 | 60 | public function getLVal() { 61 | return $this->yylval; 62 | } 63 | 64 | public function yylex () 65 | { 66 | $this->yypos = new Position ($this->yypos->lineno (), $this->yypos->token () + 1); 67 | 68 | $this->buffer = preg_replace ("/^[\\t ]+/", "", $this->buffer); 69 | 70 | if (strlen ($this->buffer) == 0) 71 | return LexerInterface::EOF; 72 | else 73 | if (substr ($this->buffer, 0, 1) == "\n") 74 | { 75 | $this->yypos = new Position ($this->yypos->lineno () + 1, 0); 76 | $this->buffer = substr ($this->buffer, 1); 77 | return ord ("\n"); 78 | } 79 | else 80 | if (preg_match ("/^([0-9]+)/", $this->buffer, $matches)) 81 | { 82 | $this->yylval = $matches [1]; 83 | $this->buffer = substr ($this->buffer, strlen ($matches [1])); 84 | return self::NUM; 85 | } 86 | else 87 | { 88 | $tt = substr ($this->buffer, 0, 1); 89 | $this->buffer = substr ($this->buffer, 1); 90 | return ord ($tt); 91 | } 92 | } 93 | }; 94 | %% 95 | class Position { 96 | public $line; 97 | public $token; 98 | 99 | public function __construct ($l = 0, $t = 0) 100 | { 101 | $this->line = $l; 102 | $this->token = $t; 103 | } 104 | 105 | public function equals (Position $l) 106 | { 107 | return $l->line == $this->line && $l->token == $this->token; 108 | } 109 | 110 | public function __toString () 111 | { 112 | return $this->line . "." . $this->token; 113 | } 114 | 115 | public function lineno () 116 | { 117 | return $this->line; 118 | } 119 | 120 | public function token () 121 | { 122 | return $this->token; 123 | } 124 | } 125 | 126 | $p = new Calc (STDIN, new Exception ()); 127 | $p->parse (); 128 | -------------------------------------------------------------------------------- /examples/rpcalc/.gitignore: -------------------------------------------------------------------------------- 1 | /calc.h 2 | /rpcalc.c 3 | /rpcalc.h 4 | /rpcalc.output 5 | /rpcalc.stamp 6 | /rpcalc.y 7 | -------------------------------------------------------------------------------- /examples/rpcalc/local.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2005-2006, 2008-2012 Free Software Foundation, Inc. 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | ## -------------------- ## 17 | ## Building & testing. ## 18 | ## -------------------- ## 19 | 20 | BUILT_SOURCES += $(rpcalc_sources) 21 | 22 | rpcalc_extracted = \ 23 | examples/rpcalc/rpcalc.y 24 | rpcalc_sources = \ 25 | $(rpcalc_extracted) 26 | extracted += $(rpcalc_extracted) 27 | 28 | check_PROGRAMS += examples/rpcalc/rpcalc 29 | examples_rpcalc_rpcalc_LDADD = -lm 30 | nodist_examples_rpcalc_rpcalc_SOURCES = \ 31 | $(rpcalc_sources) 32 | 33 | examples_rpcalc_rpcalc_CPPFLAGS = -I$(top_builddir)/examples/rpcalc 34 | dist_TESTS += examples/rpcalc/rpcalc.test 35 | -------------------------------------------------------------------------------- /examples/rpcalc/rpcalc.test: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Copyright (C) 2005-2012 Free Software Foundation, Inc. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | cat >input <input <input <input <input <input <. 17 | 18 | me=`basename $1 .test` 19 | 20 | # Number of the current test. 21 | number=1 22 | 23 | # Exit status of this script. 24 | exit=true 25 | 26 | # top_buiddir. 27 | cwd=`pwd` 28 | 29 | # The exercised program. 30 | prog=$cwd/examples/$me/$me 31 | 32 | # cleanup 33 | # ------- 34 | cleanup () 35 | { 36 | local status=$? 37 | if test -z "$DEBUG"; then 38 | cd $cwd 39 | rm -rf $$.dir 40 | fi 41 | exit $status 42 | } 43 | trap cleanup 0 1 2 13 15 44 | mkdir $$.dir 45 | cd $$.dir 46 | 47 | # run EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS] 48 | # --------------------------------------------------------- 49 | run () 50 | { 51 | # Expected exit status. 52 | local sta_exp=$1 53 | shift 54 | # Expected output. 55 | local out_exp=$1 56 | shift 57 | $prog "$@" - out_eff 58 | # Effective exit status. 59 | local sta_eff=$? 60 | # Effective output. 61 | local out_eff=`cat out_eff` 62 | if test $sta_eff -eq $sta_exp; then 63 | if test "$out_eff" = "$out_exp"; then 64 | echo "$me: PASS: $number" 65 | else 66 | echo "$me: FAIL: $number (expected output: $out_exp, effective: $out_eff)" 67 | exit=false 68 | fi 69 | else 70 | echo "$me: FAIL: $number (expected status: $sta_exp, effective: $sta_eff)" 71 | exit=false 72 | fi 73 | number=`expr $number + 1` 74 | } 75 | 76 | # We have cd'd one level deeper. 77 | . "../$1" 78 | 79 | $exit 80 | -------------------------------------------------------------------------------- /examples/variant.yy: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2008-2012 Free Software Foundation, Inc. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | %debug 19 | %skeleton "lalr1.cc" 20 | %defines 21 | %define parse.assert 22 | %define variant 23 | %define lex_symbol 24 | %locations 25 | 26 | %code requires // *.hh 27 | { 28 | #include 29 | #include 30 | typedef std::list strings_type; 31 | } 32 | 33 | %code // *.cc 34 | { 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | // Prototype of the yylex function providing subsequent tokens. 41 | static yy::parser::symbol_type yylex (); 42 | 43 | // Printing a list of strings. 44 | // Koening look up will look into std, since that's an std::list. 45 | namespace std 46 | { 47 | std::ostream& 48 | operator<< (std::ostream& o, const strings_type& s) 49 | { 50 | std::copy (s.begin (), s.end (), 51 | std::ostream_iterator (o, "\n")); 52 | return o; 53 | } 54 | } 55 | 56 | // Conversion to string. 57 | template 58 | inline 59 | std::string 60 | string_cast (const T& t) 61 | { 62 | std::ostringstream o; 63 | o << t; 64 | return o.str (); 65 | } 66 | } 67 | 68 | %token <::std::string> TEXT; 69 | %token NUMBER; 70 | %printer { debug_stream () << $$; } 71 | <::std::string> <::std::list>; 72 | %token END_OF_FILE 0; 73 | 74 | %type <::std::string> item; 75 | %type <::std::list> list; 76 | 77 | %% 78 | 79 | result: 80 | list { std::cout << $1 << std::endl; } 81 | ; 82 | 83 | list: 84 | /* nothing */ { /* Generates an empty string list */ } 85 | | list item { std::swap ($$, $1); $$.push_back ($2); } 86 | ; 87 | 88 | item: 89 | TEXT { std::swap ($$, $1); } 90 | | NUMBER { $$ = string_cast ($1); } 91 | ; 92 | %% 93 | 94 | // The yylex function providing subsequent tokens: 95 | // TEXT "I have three numbers for you:" 96 | // NUMBER 1 97 | // NUMBER 2 98 | // NUMBER 3 99 | // TEXT " and that's all!" 100 | // END_OF_FILE 101 | 102 | static 103 | yy::parser::symbol_type 104 | yylex () 105 | { 106 | static int stage = -1; 107 | ++stage; 108 | yy::parser::location_type loc(0, stage + 1, stage + 1); 109 | switch (stage) 110 | { 111 | case 0: 112 | return yy::parser::make_TEXT ("I have three numbers for you.", loc); 113 | case 1: 114 | case 2: 115 | case 3: 116 | return yy::parser::make_NUMBER (stage, loc); 117 | case 4: 118 | return yy::parser::make_TEXT ("And that's all!", loc); 119 | default: 120 | return yy::parser::make_END_OF_FILE (loc); 121 | } 122 | } 123 | 124 | // Mandatory error function 125 | void 126 | yy::parser::error (const yy::parser::location_type& loc, const std::string& msg) 127 | { 128 | std::cerr << loc << ": " << msg << std::endl; 129 | } 130 | 131 | int 132 | main () 133 | { 134 | yy::parser p; 135 | p.set_debug_level (!!getenv ("YYDEBUG")); 136 | return p.parse (); 137 | } 138 | 139 | // Local Variables: 140 | // mode: C++ 141 | // End: 142 | -------------------------------------------------------------------------------- /externals/bootstrap.cfg: -------------------------------------------------------------------------------- 1 | external: gnulib 2 | -------------------------------------------------------------------------------- /lib/abitset.h: -------------------------------------------------------------------------------- 1 | /* Functions to support abitsets. 2 | 3 | Copyright (C) 2002, 2004, 2009-2012 Free Software Foundation, Inc. 4 | 5 | Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef _ABITSET_H 21 | #define _ABITSET_H 22 | 23 | #include "bitset.h" 24 | 25 | extern size_t abitset_bytes (bitset_bindex); 26 | 27 | extern bitset abitset_init (bitset, bitset_bindex); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/bitset_stats.h: -------------------------------------------------------------------------------- 1 | /* Functions to support bitset statistics. 2 | 3 | Copyright (C) 2002-2004, 2009-2012 Free Software Foundation, Inc. 4 | 5 | Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef _BITSET_STATS_H 21 | #define _BITSET_STATS_H 22 | 23 | #include "bbitset.h" 24 | 25 | extern bool bitset_stats_enabled; 26 | 27 | extern enum bitset_type bitset_stats_type_get (bitset); 28 | 29 | extern size_t bitset_stats_bytes (void); 30 | 31 | extern bitset bitset_stats_init (bitset, bitset_bindex, enum bitset_type); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /lib/bitsetv-print.c: -------------------------------------------------------------------------------- 1 | /* Bitset vectors. 2 | 3 | Copyright (C) 2001-2002, 2004, 2006, 2009-2012 Free Software 4 | Foundation, Inc. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . */ 18 | 19 | #include 20 | 21 | #include "bitsetv-print.h" 22 | 23 | #include 24 | 25 | /*--------------------------------------------------------. 26 | | Display the MATRIX array of SIZE bitsets of size SIZE. | 27 | `--------------------------------------------------------*/ 28 | 29 | void 30 | bitsetv_matrix_dump (FILE * out, const char *title, bitsetv bset) 31 | { 32 | bitset_bindex i, j; 33 | bitset_bindex hsize = bitset_size (bset[0]); 34 | 35 | /* Title. */ 36 | fprintf (out, "%s BEGIN\n", title); 37 | 38 | /* Column numbers. */ 39 | fputs (" ", out); 40 | for (i = 0; i < hsize; ++i) 41 | putc (i / 10 ? '0' + i / 10 : ' ', out); 42 | putc ('\n', out); 43 | fputs (" ", out); 44 | for (i = 0; i < hsize; ++i) 45 | fprintf (out, "%d", (int) (i % 10)); 46 | putc ('\n', out); 47 | 48 | /* Bar. */ 49 | fputs (" .", out); 50 | for (i = 0; i < hsize; ++i) 51 | putc ('-', out); 52 | fputs (".\n", out); 53 | 54 | /* Contents. */ 55 | for (i = 0; bset[i]; ++i) 56 | { 57 | fprintf (out, "%2lu|", (unsigned long int) i); 58 | for (j = 0; j < hsize; ++j) 59 | fputs (bitset_test (bset[i], j) ? "1" : " ", out); 60 | fputs ("|\n", out); 61 | } 62 | 63 | /* Bar. */ 64 | fputs (" `", out); 65 | for (i = 0; i < hsize; ++i) 66 | putc ('-', out); 67 | fputs ("'\n", out); 68 | 69 | /* End title. */ 70 | fprintf (out, "%s END\n\n", title); 71 | } 72 | -------------------------------------------------------------------------------- /lib/bitsetv-print.h: -------------------------------------------------------------------------------- 1 | /* Bitset vectors. 2 | 3 | Copyright (C) 2002, 2004, 2009-2012 Free Software Foundation, Inc. 4 | 5 | Contributed by Akim Demaille (akim@freefriends.org). 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef _BITSETV_PRINT_H 21 | #define _BITSETV_PRINT_H 22 | 23 | #include "bitsetv.h" 24 | 25 | /* Dump vector of bitsets as a matrix. */ 26 | extern void bitsetv_matrix_dump (FILE *, const char *, bitsetv); 27 | 28 | #endif /* _BITSETV_H */ 29 | -------------------------------------------------------------------------------- /lib/bitsetv.h: -------------------------------------------------------------------------------- 1 | /* Bitset vectors. 2 | 3 | Copyright (C) 2002, 2004, 2009-2012 Free Software Foundation, Inc. 4 | 5 | Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef _BITSETV_H 21 | #define _BITSETV_H 22 | 23 | #include "bitset.h" 24 | 25 | typedef bitset * bitsetv; 26 | 27 | /* Create a vector of N_VECS bitsets, each of N_BITS, and of 28 | type TYPE. */ 29 | extern bitsetv bitsetv_alloc (bitset_bindex, bitset_bindex, enum bitset_type); 30 | 31 | /* Create a vector of N_VECS bitsets, each of N_BITS, and with 32 | attribute hints specified by ATTR. */ 33 | extern bitsetv bitsetv_create (bitset_bindex, bitset_bindex, unsigned int); 34 | 35 | /* Free vector of bitsets. */ 36 | extern void bitsetv_free (bitsetv); 37 | 38 | /* Zero vector of bitsets. */ 39 | extern void bitsetv_zero (bitsetv); 40 | 41 | /* Set vector of bitsets. */ 42 | extern void bitsetv_ones (bitsetv); 43 | 44 | /* Given a vector BSETV of N bitsets of size N, modify its contents to 45 | be the transitive closure of what was given. */ 46 | extern void bitsetv_transitive_closure (bitsetv); 47 | 48 | /* Given a vector BSETV of N bitsets of size N, modify its contents to 49 | be the reflexive transitive closure of what was given. This is 50 | the same as transitive closure but with all bits on the diagonal 51 | of the bit matrix set. */ 52 | extern void bitsetv_reflexive_transitive_closure (bitsetv); 53 | 54 | /* Dump vector of bitsets. */ 55 | extern void bitsetv_dump (FILE *, const char *, const char *, bitsetv); 56 | 57 | /* Function to debug vector of bitsets from debugger. */ 58 | extern void debug_bitsetv (bitsetv); 59 | 60 | #endif /* _BITSETV_H */ 61 | -------------------------------------------------------------------------------- /lib/ebitset.h: -------------------------------------------------------------------------------- 1 | /* Functions to support ebitsets. 2 | 3 | Copyright (C) 2002, 2004, 2009-2012 Free Software Foundation, Inc. 4 | 5 | Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef _EBITSET_H 21 | #define _EBITSET_H 22 | 23 | #include "bitset.h" 24 | 25 | extern size_t ebitset_bytes (bitset_bindex); 26 | 27 | extern bitset ebitset_init (bitset, bitset_bindex); 28 | 29 | extern void ebitset_release_memory (void); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /lib/get-errno.c: -------------------------------------------------------------------------------- 1 | /* get-errno.c - get and set errno. 2 | 3 | Copyright (C) 2002, 2006, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . */ 17 | 18 | /* Written by Paul Eggert. */ 19 | 20 | #include 21 | 22 | #include "get-errno.h" 23 | 24 | #include 25 | 26 | /* Get and set errno. A source file that needs to set or get errno, 27 | but doesn't need to test for specific errno values, can use these 28 | functions to avoid namespace pollution. For example, a file that 29 | defines EQUAL should not include , since might 30 | define EQUAL; such a file can include instead. */ 31 | 32 | int 33 | get_errno (void) 34 | { 35 | return errno; 36 | } 37 | 38 | void 39 | set_errno (int e) 40 | { 41 | errno = e; 42 | } 43 | -------------------------------------------------------------------------------- /lib/get-errno.h: -------------------------------------------------------------------------------- 1 | /* get-errno.h - get and set errno. 2 | 3 | Copyright (C) 2002, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . */ 17 | 18 | extern int get_errno (void); 19 | extern void set_errno (int); 20 | -------------------------------------------------------------------------------- /lib/lbitset.h: -------------------------------------------------------------------------------- 1 | /* Functions to support lbitsets. 2 | 3 | Copyright (C) 2002, 2004, 2009-2012 Free Software Foundation, Inc. 4 | 5 | Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef _LBITSET_H 21 | #define _LBITSET_H 22 | 23 | #include "bitset.h" 24 | 25 | extern size_t lbitset_bytes (bitset_bindex); 26 | 27 | extern bitset lbitset_init (bitset, bitset_bindex); 28 | 29 | extern void lbitset_release_memory (void); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /lib/libiberty.h: -------------------------------------------------------------------------------- 1 | /* Fake libiberty.h for Bison. 2 | 3 | Copyright (C) 2002-2004, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . */ 17 | 18 | 19 | /* Bison depends on libiberty's implementation of bitsets, which 20 | requires a `libiberty.h' file. This file provides the minimum 21 | services. */ 22 | 23 | #ifndef BISON_LIBIBERTY_H_ 24 | # define BISON_LIBIBERTY_H_ 1 25 | 26 | # ifndef __attribute__ 27 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ 28 | # define __attribute__(x) 29 | # endif 30 | # endif 31 | 32 | # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) 33 | 34 | # include "xalloc.h" 35 | 36 | #endif /* ! BISON_LIBIBERTY_H_ */ 37 | -------------------------------------------------------------------------------- /lib/local.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2001-2012 Free Software Foundation, Inc. 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | include lib/gnulib.mk 17 | 18 | # Implementation of bitsets. 19 | lib_libbison_a_SOURCES += \ 20 | lib/abitset.c \ 21 | lib/abitset.h \ 22 | lib/bbitset.h \ 23 | lib/bitset.c \ 24 | lib/bitset.h \ 25 | lib/bitset_stats.c \ 26 | lib/bitset_stats.h \ 27 | lib/bitsetv.c \ 28 | lib/bitsetv.h \ 29 | lib/ebitset.c \ 30 | lib/ebitset.h \ 31 | lib/lbitset.c \ 32 | lib/lbitset.h \ 33 | lib/libiberty.h \ 34 | lib/vbitset.c \ 35 | lib/vbitset.h 36 | 37 | # Additional bitset operations. 38 | lib_libbison_a_SOURCES += \ 39 | lib/bitsetv-print.h \ 40 | lib/bitsetv-print.c 41 | 42 | # timevars, stolen from GCC. 43 | lib_libbison_a_SOURCES += \ 44 | lib/timevar.h \ 45 | lib/timevar.c \ 46 | lib/timevar.def 47 | 48 | # Non-gnulib sources in Bison's internal library. 49 | lib_libbison_a_SOURCES += \ 50 | lib/get-errno.h \ 51 | lib/get-errno.c 52 | 53 | # The Yacc compatibility library. 54 | lib_LIBRARIES = $(YACC_LIBRARY) 55 | EXTRA_LIBRARIES = lib/liby.a 56 | lib_liby_a_SOURCES = lib/main.c lib/yyerror.c 57 | -------------------------------------------------------------------------------- /lib/main.c: -------------------------------------------------------------------------------- 1 | /* Yacc library main function. 2 | 3 | Copyright (C) 2002, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #include 21 | 22 | #if HAVE_LOCALE_H 23 | # include 24 | #endif 25 | #if ! HAVE_SETLOCALE 26 | # define setlocale(Category, Locale) 27 | #endif 28 | 29 | int yyparse (void); 30 | 31 | int 32 | main (void) 33 | { 34 | setlocale (LC_ALL, ""); 35 | return yyparse (); 36 | } 37 | -------------------------------------------------------------------------------- /lib/timevar.def: -------------------------------------------------------------------------------- 1 | /* This file contains the definitions for timing variables used to -*- C -*- 2 | measure run-time performance of the compiler. 3 | 4 | Copyright (C) 2002, 2007, 2009-2012 Free Software Foundation, Inc. 5 | 6 | Contributed by Akim Demaille . 7 | 8 | This file is part of Bison, the GNU Compiler Compiler. 9 | 10 | This program is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU General Public License for more details. 19 | 20 | You should have received a copy of the GNU General Public License 21 | along with this program. If not, see . */ 22 | 23 | /* This file contains timing variable definitions, used by timevar.h 24 | and timevar.c. 25 | 26 | Syntax: 27 | 28 | DEFTIMEVAR (id, name) 29 | 30 | where ID is the enumeral value used to identify the timing 31 | variable, and NAME is a character string describing its purpose. */ 32 | 33 | /* The total execution time. */ 34 | DEFTIMEVAR (TV_TOTAL , "total time") 35 | 36 | /* Time spent in the reader. */ 37 | DEFTIMEVAR (TV_READER , "reader") 38 | DEFTIMEVAR (TV_SCANNING , "scanner") 39 | DEFTIMEVAR (TV_PARSING , "parser") 40 | 41 | /* Time spent handling the grammar. */ 42 | DEFTIMEVAR (TV_REDUCE , "reducing the grammar") 43 | DEFTIMEVAR (TV_SETS , "computing the sets") 44 | DEFTIMEVAR (TV_LR0 , "LR(0)") 45 | DEFTIMEVAR (TV_LALR , "LALR(1)") 46 | DEFTIMEVAR (TV_IELR_PHASE1 , "IELR(1) Phase 1") 47 | DEFTIMEVAR (TV_IELR_PHASE2 , "IELR(1) Phase 2") 48 | DEFTIMEVAR (TV_IELR_PHASE3 , "IELR(1) Phase 3") 49 | DEFTIMEVAR (TV_IELR_PHASE4 , "IELR(1) Phase 4") 50 | DEFTIMEVAR (TV_CONFLICTS , "conflicts") 51 | 52 | /* Time spent outputing results. */ 53 | DEFTIMEVAR (TV_REPORT , "outputing report") 54 | DEFTIMEVAR (TV_GRAPH , "outputing graph") 55 | DEFTIMEVAR (TV_XML , "outputing xml") 56 | DEFTIMEVAR (TV_ACTIONS , "parser action tables") 57 | DEFTIMEVAR (TV_PARSER , "outputing parser") 58 | DEFTIMEVAR (TV_M4 , "running m4") 59 | 60 | /* Time spent by freeing the memory :). */ 61 | DEFTIMEVAR (TV_FREE , "freeing") 62 | -------------------------------------------------------------------------------- /lib/timevar.h: -------------------------------------------------------------------------------- 1 | /* Timing variables for measuring compiler performance. 2 | 3 | Copyright (C) 2000, 2002, 2004, 2009-2012 Free Software Foundation, 4 | Inc. 5 | 6 | Contributed by Alex Samuel 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | #ifndef GCC_TIMEVAR_H 22 | #define GCC_TIMEVAR_H 23 | 24 | /* Timing variables are used to measure elapsed time in various 25 | portions of the compiler. Each measures elapsed user, system, and 26 | wall-clock time, as appropriate to and supported by the host 27 | system. 28 | 29 | Timing variables are defined using the DEFTIMEVAR macro in 30 | timevar.def. Each has an enumeral identifier, used when referring 31 | to the timing variable in code, and a character string name. 32 | 33 | Timing variables can be used in two ways: 34 | 35 | - On the timing stack, using timevar_push and timevar_pop. 36 | Timing variables may be pushed onto the stack; elapsed time is 37 | attributed to the topmost timing variable on the stack. When 38 | another variable is pushed on, the previous topmost variable is 39 | `paused' until the pushed variable is popped back off. 40 | 41 | - As a standalone timer, using timevar_start and timevar_stop. 42 | All time elapsed between the two calls is attributed to the 43 | variable. 44 | */ 45 | 46 | /* This structure stores the various varieties of time that can be 47 | measured. Times are stored in seconds. The time may be an 48 | absolute time or a time difference; in the former case, the time 49 | base is undefined, except that the difference between two times 50 | produces a valid time difference. */ 51 | 52 | struct timevar_time_def 53 | { 54 | /* User time in this process. */ 55 | float user; 56 | 57 | /* System time (if applicable for this host platform) in this 58 | process. */ 59 | float sys; 60 | 61 | /* Wall clock time. */ 62 | float wall; 63 | }; 64 | 65 | /* An enumeration of timing variable identifiers. Constructed from 66 | the contents of timevar.def. */ 67 | 68 | #define DEFTIMEVAR(identifier__, name__) \ 69 | identifier__, 70 | typedef enum 71 | { 72 | #include "timevar.def" 73 | TIMEVAR_LAST 74 | } 75 | timevar_id_t; 76 | #undef DEFTIMEVAR 77 | 78 | extern void init_timevar (void); 79 | extern void timevar_push (timevar_id_t); 80 | extern void timevar_pop (timevar_id_t); 81 | extern void timevar_start (timevar_id_t); 82 | extern void timevar_stop (timevar_id_t); 83 | extern void timevar_get (timevar_id_t, struct timevar_time_def *); 84 | extern void timevar_print (FILE *); 85 | 86 | /* Provided for backward compatibility. */ 87 | extern long get_run_time (void); 88 | extern void print_time (const char *, long); 89 | 90 | extern int timevar_report; 91 | 92 | #endif /* ! GCC_TIMEVAR_H */ 93 | -------------------------------------------------------------------------------- /lib/vbitset.h: -------------------------------------------------------------------------------- 1 | /* Functions to support vbitsets. 2 | 3 | Copyright (C) 2002, 2004, 2009-2012 Free Software Foundation, Inc. 4 | 5 | Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef _VBITSET_H 21 | #define _VBITSET_H 22 | 23 | #include "bitset.h" 24 | 25 | extern size_t vbitset_bytes (bitset_bindex); 26 | 27 | extern bitset vbitset_init (bitset, bitset_bindex); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /lib/yyerror.c: -------------------------------------------------------------------------------- 1 | /* Yacc library error-printing function. 2 | 3 | Copyright (C) 2002, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #include 21 | 22 | int yyerror (char const *); 23 | 24 | int 25 | yyerror (char const *message) 26 | { 27 | fputs (message, stderr); 28 | fputc ('\n', stderr); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /m4/.gitignore: -------------------------------------------------------------------------------- 1 | /00gnulib.m4 2 | /alloca.m4 3 | /argmatch.m4 4 | /asm-underscore.m4 5 | /assert.m4 6 | /calloc.m4 7 | /cloexec.m4 8 | /close-stream.m4 9 | /close.m4 10 | /closeout.m4 11 | /codeset.m4 12 | /config-h.m4 13 | /configmake.m4 14 | /dirname.m4 15 | /dos.m4 16 | /double-slash-root.m4 17 | /dup2.m4 18 | /environ.m4 19 | /errno_h.m4 20 | /error.m4 21 | /exponentd.m4 22 | /exponentf.m4 23 | /exponentl.m4 24 | /extensions.m4 25 | /fatal-signal.m4 26 | /fclose.m4 27 | /fcntl-o.m4 28 | /fcntl.m4 29 | /fcntl_h.m4 30 | /float_h.m4 31 | /fopen.m4 32 | /fpending.m4 33 | /fpieee.m4 34 | /fprintf-posix.m4 35 | /frexp.m4 36 | /frexpl.m4 37 | /fstat.m4 38 | /getdtablesize.m4 39 | /getopt.m4 40 | /gettext.m4 41 | /glibc21.m4 42 | /gnulib-cache.m4 43 | /gnulib-common.m4 44 | /gnulib-comp.m4 45 | /gnulib-tool.m4 46 | /hash.m4 47 | /iconv.m4 48 | /include_next.m4 49 | /inline.m4 50 | /intlmacosx.m4 51 | /intmax_t.m4 52 | /inttypes-pri.m4 53 | /inttypes.m4 54 | /inttypes_h.m4 55 | /ioctl.m4 56 | /isnan.m4 57 | /isnand.m4 58 | /isnanf.m4 59 | /isnanl.m4 60 | /iswblank.m4 61 | /javacomp.m4 62 | /javaexec.m4 63 | /largefile.m4 64 | /ldexp.m4 65 | /ldexpl.m4 66 | /lib-ld.m4 67 | /lib-link.m4 68 | /lib-prefix.m4 69 | /libunistring-base.m4 70 | /localcharset.m4 71 | /locale-fr.m4 72 | /locale-ja.m4 73 | /locale-zh.m4 74 | /longlong.m4 75 | /malloc.m4 76 | /math_h.m4 77 | /mbchar.m4 78 | /mbiter.m4 79 | /mbrtowc.m4 80 | /mbsinit.m4 81 | /mbstate_t.m4 82 | /mbswidth.m4 83 | /memchr.m4 84 | /mmap-anon.m4 85 | /mode_t.m4 86 | /msvc-inval.m4 87 | /msvc-nothrow.m4 88 | /multiarch.m4 89 | /nls.m4 90 | /nocrash.m4 91 | /open.m4 92 | /pathmax.m4 93 | /perror.m4 94 | /pipe.m4 95 | /pipe2.m4 96 | /po.m4 97 | /posix_spawn.m4 98 | /printf-frexp.m4 99 | /printf-frexpl.m4 100 | /printf-posix-rpl.m4 101 | /printf-posix.m4 102 | /printf.m4 103 | /progtest.m4 104 | /quote.m4 105 | /quotearg.m4 106 | /raise.m4 107 | /rawmemchr.m4 108 | /realloc.m4 109 | /sched_h.m4 110 | /setenv.m4 111 | /sig_atomic_t.m4 112 | /sigaction.m4 113 | /signal_h.m4 114 | /signalblocking.m4 115 | /signbit.m4 116 | /size_max.m4 117 | /snprintf-posix.m4 118 | /snprintf.m4 119 | /socklen.m4 120 | /sockpfaf.m4 121 | /spawn-pipe.m4 122 | /spawn_h.m4 123 | /sprintf-posix.m4 124 | /ssize_t.m4 125 | /stat.m4 126 | /stdbool.m4 127 | /stddef_h.m4 128 | /stdint.m4 129 | /stdint_h.m4 130 | /stdio-safer.m4 131 | /stdio_h.m4 132 | /stdlib_h.m4 133 | /stpcpy.m4 134 | /strchrnul.m4 135 | /strdup.m4 136 | /strerror.m4 137 | /strerror_r.m4 138 | /string_h.m4 139 | /strndup.m4 140 | /strnlen.m4 141 | /strtol.m4 142 | /strtoul.m4 143 | /strverscmp.m4 144 | /sys_ioctl_h.m4 145 | /sys_socket_h.m4 146 | /sys_stat_h.m4 147 | /sys_wait_h.m4 148 | /threadlib.m4 149 | /time_h.m4 150 | /unistd-safer.m4 151 | /unistd_h.m4 152 | /unlocked-io.m4 153 | /vasnprintf.m4 154 | /vfprintf-posix.m4 155 | /vsnprintf-posix.m4 156 | /vsnprintf.m4 157 | /vsprintf-posix.m4 158 | /wait-process.m4 159 | /waitpid.m4 160 | /warn-on-use.m4 161 | /warnings.m4 162 | /wchar_h.m4 163 | /wchar_t.m4 164 | /wctype_h.m4 165 | /wcwidth.m4 166 | /wint_t.m4 167 | /xalloc.m4 168 | /xsize.m4 169 | /xstrndup.m4 170 | /sysexits.m4 171 | -------------------------------------------------------------------------------- /m4/bison-i18n.m4: -------------------------------------------------------------------------------- 1 | # bison-i18n.m4 serial 2 2 | 3 | dnl Copyright (C) 2005-2006, 2009-2012 Free Software Foundation, Inc. 4 | 5 | dnl This file is free software; the Free Software Foundation 6 | dnl gives unlimited permission to copy and/or distribute it, 7 | dnl with or without modifications, as long as this notice is preserved. 8 | 9 | dnl From Bruno Haible. 10 | 11 | dnl Support for internationalization of bison-generated parsers. 12 | 13 | dnl BISON_I18N 14 | dnl should be used in configure.ac, after AM_GNU_GETTEXT. If USE_NLS is yes, it 15 | dnl sets BISON_LOCALEDIR to indicate where to find the bison-runtime.mo files 16 | dnl and defines YYENABLE_NLS if there are bison-runtime.mo files at all. 17 | AC_DEFUN([BISON_I18N], 18 | [ 19 | if test -z "$USE_NLS"; then 20 | echo "The BISON-I18N macro is used without being preceded by AM-GNU-GETTEXT." 1>&2 21 | exit 1 22 | fi 23 | BISON_LOCALEDIR= 24 | BISON_USE_NLS=no 25 | if test "$USE_NLS" = yes; then 26 | dnl Determine bison's localedir. 27 | dnl AC_PROG_YACC sets the YACC variable; other macros set the BISON variable. 28 | dnl But even is YACC is called "yacc", it may be a script that invokes bison 29 | dnl and accepts the --print-localedir option. 30 | dnl YACC's default value is empty; BISON's default value is :. 31 | if (${YACC-${BISON-:}} --print-localedir) >/dev/null 2>&1; then 32 | BISON_LOCALEDIR=`${YACC-${BISON-:}} --print-localedir` 33 | fi 34 | AC_SUBST([BISON_LOCALEDIR]) 35 | if test -n "$BISON_LOCALEDIR"; then 36 | dnl There is no need to enable internationalization if the user doesn't 37 | dnl want message catalogs. So look at the language/locale names for 38 | dnl which the user wants message catalogs. This is $LINGUAS. If unset 39 | dnl or empty, he wants all of them. 40 | USER_LINGUAS="${LINGUAS-%UNSET%}" 41 | if test -n "$USER_LINGUAS"; then 42 | BISON_USE_NLS=yes 43 | fi 44 | fi 45 | fi 46 | if test $BISON_USE_NLS = yes; then 47 | AC_DEFINE([YYENABLE_NLS], 1, 48 | [Define to 1 to internationalize bison runtime messages.]) 49 | fi 50 | ]) 51 | -------------------------------------------------------------------------------- /m4/c-working.m4: -------------------------------------------------------------------------------- 1 | # Sanity test a C compiler. 2 | 3 | # Copyright (C) 2006, 2009-2012 Free Software Foundation, Inc. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | # Written by Paul Eggert. 19 | 20 | AC_DEFUN([BISON_TEST_FOR_WORKING_C_COMPILER], [ 21 | AC_COMPILE_IFELSE( 22 | [AC_LANG_PROGRAM( 23 | [[#include 24 | int test_array[CHAR_BIT];]])], 25 | [], 26 | [AC_MSG_FAILURE([cannot compile a simple C program])]) 27 | ]) 28 | -------------------------------------------------------------------------------- /m4/cxx.m4: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Sanity-test a C++ compiler. 3 | # 4 | # Copyright (C) 2004, 2006, 2009-2012 Free Software Foundation, Inc. 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | # Written by Paul Eggert. 20 | 21 | AC_DEFUN([BISON_TEST_FOR_WORKING_CXX_COMPILER], 22 | [ 23 | AC_CACHE_CHECK([whether $CXX builds executables that work], 24 | bison_cv_cxx_works, 25 | [AC_LANG_PUSH([C++]) 26 | bison_cv_cxx_works=no 27 | AC_COMPILE_IFELSE( 28 | [AC_LANG_PROGRAM( 29 | [#include 30 | #include 31 | #include 32 | #include 33 | using namespace std;], 34 | [std::cerr << ""; 35 | cout << ""; 36 | typedef std::pair uipair; 37 | std::map m; 38 | std::map::iterator i; 39 | m.insert (uipair (4, -4)); 40 | for (i = m.begin (); i != m.end (); ++i) 41 | if (i->first != 4) 42 | return 1;])], 43 | [AS_IF([AC_TRY_COMMAND([$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_objext $LIBS >&AS_MESSAGE_LOG_FD])], 44 | [AS_IF([test "$cross_compiling" = yes], 45 | [bison_cv_cxx_works=cross], 46 | [AS_IF([AC_TRY_COMMAND(./conftest$ac_exeext)], 47 | [bison_cv_cxx_works=yes])])]) 48 | rm -f conftest$ac_exeext]) 49 | AC_LANG_POP([C++])]) 50 | 51 | case $bison_cv_cxx_works in 52 | yes) 53 | BISON_CXX_WORKS=':';; 54 | no | cross) 55 | BISON_CXX_WORKS='exit 77';; 56 | esac 57 | 58 | AC_SUBST([BISON_CXX_WORKS]) 59 | AM_CONDITIONAL(BISON_CXX_WORKS, test $bison_cv_cxx_works = yes) 60 | ]) 61 | -------------------------------------------------------------------------------- /m4/dmalloc.m4: -------------------------------------------------------------------------------- 1 | ## ----------------------------------- ## 2 | ## Check if --with-dmalloc was given. ## 3 | ## From Franc,ois Pinard ## 4 | ## ----------------------------------- ## 5 | 6 | # serial 1 7 | 8 | AC_DEFUN([AM_WITH_DMALLOC], 9 | [AC_MSG_CHECKING([if malloc debugging is wanted]) 10 | AC_ARG_WITH(dmalloc, 11 | [ --with-dmalloc use dmalloc, as in 12 | http://www.dmalloc.com/dmalloc.tar.gz], 13 | [if test "$withval" = yes; then 14 | AC_MSG_RESULT(yes) 15 | AC_DEFINE([WITH_DMALLOC],1, 16 | [Define if using the dmalloc debugging malloc package]) 17 | LIBS="$LIBS -ldmalloc" 18 | LDFLAGS="$LDFLAGS -g" 19 | else 20 | AC_MSG_RESULT(no) 21 | fi], [AC_MSG_RESULT(no)]) 22 | ]) 23 | -------------------------------------------------------------------------------- /m4/m4.m4: -------------------------------------------------------------------------------- 1 | ../submodules/autoconf/m4/m4.m4 -------------------------------------------------------------------------------- /m4/subpipe.m4: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Checks required to run `subpipe'. 3 | # 4 | # Copyright (C) 2002-2003, 2005, 2009-2012 Free Software Foundation, 5 | # Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | # Written by Paul Eggert . 21 | 22 | AC_DEFUN([BISON_PREREQ_SUBPIPE], 23 | [ 24 | AC_TYPE_PID_T 25 | AC_HEADER_SYS_WAIT 26 | AC_CHECK_FUNCS(dup2 waitpid) 27 | AC_FUNC_FORK 28 | ]) 29 | -------------------------------------------------------------------------------- /m4/timevar.m4: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Checks required to run `timevar', a time tracker. 3 | # 4 | # Copyright (C) 2002-2003, 2009-2012 Free Software Foundation, Inc. 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | # serial 2 20 | 21 | AC_DEFUN([BISON_PREREQ_TIMEVAR], 22 | [AC_CHECK_HEADERS([sys/time.h sys/times.h]) 23 | AC_CHECK_HEADERS([sys/resource.h],,, 24 | [$ac_includes_default 25 | #if HAVE_SYS_TIME_H 26 | # include 27 | #endif 28 | #ifdef HAVE_SYS_TIMES_H 29 | # include 30 | #endif 31 | ]) 32 | AC_CHECK_FUNCS([times]) 33 | 34 | AC_CHECK_DECLS([getrusage, times, clock, sysconf], [], [], 35 | [$ac_includes_default 36 | #if HAVE_SYS_TIME_H 37 | # include 38 | #endif 39 | #if HAVE_SYS_TIMES_H 40 | # include 41 | #endif 42 | #if HAVE_SYS_RESOURCE_H 43 | # include 44 | #endif 45 | ]) 46 | 47 | AC_CHECK_TYPES([clock_t, struct tms], [], [], 48 | [$ac_includes_default 49 | #if HAVE_SYS_TIME_H 50 | # include 51 | #endif 52 | #if HAVE_SYS_TIMES_H 53 | # include 54 | #endif 55 | #if HAVE_SYS_RESOURCE_H 56 | # include 57 | #endif 58 | ]) 59 | ]) 60 | -------------------------------------------------------------------------------- /po/.gitignore: -------------------------------------------------------------------------------- 1 | /*.gmo 2 | /*.po 3 | /*.po~ 4 | /.reference 5 | /LINGUAS 6 | /Makefile 7 | /Makefile.in 8 | /Makefile.in.in 9 | /Makevars 10 | /Makevars.template 11 | /POTFILES 12 | /Rules-quot 13 | /bison.pot 14 | /boldquot.sed 15 | /en@boldquot.header 16 | /en@quot.header 17 | /insert-header.sed 18 | /insert-header.sin 19 | /quot.sed 20 | /remove-potcdate.sed 21 | /remove-potcdate.sin 22 | /stamp-po 23 | -------------------------------------------------------------------------------- /po/POTFILES.in: -------------------------------------------------------------------------------- 1 | src/complain.c 2 | src/conflicts.c 3 | src/files.c 4 | src/getargs.c 5 | src/gram.c 6 | src/graphviz.c 7 | src/location.c 8 | src/main.c 9 | src/muscle-tab.c 10 | src/parse-gram.y 11 | src/print.c 12 | src/reader.c 13 | src/reduce.c 14 | src/scan-code.l 15 | src/scan-gram.l 16 | src/scan-skel.l 17 | src/symlist.c 18 | src/symtab.c 19 | 20 | djgpp/subpipe.c 21 | lib/argmatch.c 22 | lib/bitset_stats.c 23 | lib/closeout.c 24 | lib/error.c 25 | lib/getopt.c 26 | lib/obstack.c 27 | lib/spawn-pipe.c 28 | lib/quotearg.c 29 | lib/timevar.c 30 | lib/w32spawn.h 31 | lib/wait-process.c 32 | lib/xalloc-die.c 33 | -------------------------------------------------------------------------------- /runtime-po/.gitignore: -------------------------------------------------------------------------------- 1 | /*.gmo 2 | /*.po 3 | /*.po~ 4 | /.reference 5 | /LINGUAS 6 | /Makefile 7 | /Makefile.in 8 | /Makefile.in.in 9 | /Makevars 10 | /Makevars.template 11 | /POTFILES 12 | /Rules-quot 13 | /bison-runtime.pot 14 | /boldquot.sed 15 | /en@boldquot.header 16 | /en@quot.header 17 | /insert-header.sed 18 | /insert-header.sin 19 | /quot.sed 20 | /remove-potcdate.sed 21 | /remove-potcdate.sin 22 | /stamp-po 23 | -------------------------------------------------------------------------------- /runtime-po/POTFILES.in: -------------------------------------------------------------------------------- 1 | data/glr.c 2 | data/lalr1.cc 3 | data/yacc.c 4 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | /*.flc 2 | /*.log 3 | /*.o 4 | /*.output 5 | /.deps 6 | /.dirstamp 7 | /bison 8 | /bison.exe 9 | /scan-code.c 10 | /scan-gram.c 11 | /scan-skel.c 12 | /yacc 13 | -------------------------------------------------------------------------------- /src/InadequacyList.c: -------------------------------------------------------------------------------- 1 | /* IELR's inadequacy list. 2 | 3 | Copyright (C) 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #include 21 | #include "system.h" 22 | 23 | #include "InadequacyList.h" 24 | 25 | ContributionIndex const ContributionIndex__none = -1; 26 | ContributionIndex const ContributionIndex__error_action = -2; 27 | 28 | InadequacyList * 29 | InadequacyList__new_conflict (state *manifesting_state, symbol *token, 30 | bitset actions, 31 | InadequacyListNodeCount *node_count) 32 | { 33 | InadequacyList *result = xmalloc (sizeof *result); 34 | result->id = (*node_count)++; 35 | aver (*node_count != 0); 36 | result->next = NULL; 37 | result->manifestingState = manifesting_state; 38 | result->contributionCount = bitset_count (actions); 39 | result->inadequacy.conflict.token = token; 40 | result->inadequacy.conflict.actions = actions; 41 | return result; 42 | } 43 | 44 | void 45 | InadequacyList__delete (InadequacyList *self) 46 | { 47 | while (self) 48 | { 49 | InadequacyList *node = self; 50 | self = self->next; 51 | bitset_free (node->inadequacy.conflict.actions); 52 | free (node); 53 | } 54 | } 55 | 56 | ContributionIndex 57 | InadequacyList__getShiftContributionIndex (InadequacyList const *self) 58 | { 59 | if (!bitset_test (self->inadequacy.conflict.actions, 60 | self->manifestingState->reductions->num)) 61 | return ContributionIndex__none; 62 | return self->contributionCount - 1; 63 | } 64 | 65 | symbol * 66 | InadequacyList__getContributionToken (InadequacyList const *self, 67 | ContributionIndex i) 68 | { 69 | aver (0 <= i && i < self->contributionCount); 70 | return self->inadequacy.conflict.token; 71 | } 72 | 73 | void 74 | InadequacyList__prependTo (InadequacyList *self, InadequacyList **list) 75 | { 76 | InadequacyList *head_old = *list; 77 | *list = self; 78 | self->next = head_old; 79 | } 80 | -------------------------------------------------------------------------------- /src/LR0.h: -------------------------------------------------------------------------------- 1 | /* Generate the LR(0) parser states for Bison. 2 | 3 | Copyright (C) 1984, 1986, 1989, 2000-2002, 2009-2012 Free Software 4 | Foundation, Inc. 5 | 6 | This file is part of Bison, the GNU Compiler Compiler. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | #ifndef LR0_H_ 22 | # define LR0_H_ 23 | 24 | # include "state.h" 25 | 26 | void generate_states (void); 27 | 28 | #endif /* !LR0_H_ */ 29 | -------------------------------------------------------------------------------- /src/Sbitset.c: -------------------------------------------------------------------------------- 1 | /* A simple, memory-efficient bitset implementation. 2 | 3 | Copyright (C) 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #include 21 | #include "system.h" 22 | 23 | #include "Sbitset.h" 24 | 25 | Sbitset 26 | Sbitset__new (Sbitset__Index nbits) 27 | { 28 | /* Some functions, like Sbitset__last_byte_mask, will fail if nbits = 0. */ 29 | aver (nbits); 30 | return xcalloc (1, Sbitset__nbytes (nbits)); 31 | } 32 | 33 | Sbitset 34 | Sbitset__new_on_obstack (Sbitset__Index nbits, struct obstack *obstackp) 35 | { 36 | Sbitset result; 37 | Sbitset ptr; 38 | Sbitset end; 39 | aver (nbits); 40 | result = obstack_alloc (obstackp, Sbitset__nbytes (nbits)); 41 | for (ptr = result, end = result + Sbitset__nbytes (nbits); ptr < end; ++ptr) 42 | *ptr = 0; 43 | return result; 44 | } 45 | 46 | void 47 | Sbitset__delete (Sbitset self) 48 | { 49 | free (self); 50 | } 51 | 52 | bool 53 | Sbitset__isEmpty (Sbitset self, Sbitset__Index nbits) 54 | { 55 | Sbitset last = self + Sbitset__nbytes (nbits) - 1; 56 | for (; self < last; ++self) 57 | if (*self != 0) 58 | return false; 59 | return ((*last) & Sbitset__last_byte_mask (nbits)) == 0; 60 | } 61 | 62 | void 63 | Sbitset__fprint(Sbitset self, Sbitset__Index nbits, FILE *file) 64 | { 65 | Sbitset__Index i; 66 | Sbitset itr; 67 | bool first = true; 68 | fprintf (file, 69 | "nbits = %" SBITSET__INDEX__CONVERSION_SPEC ", set = {", 70 | nbits); 71 | SBITSET__FOR_EACH (self, nbits, itr, i) 72 | { 73 | if (first) 74 | first = false; 75 | else 76 | fprintf (file, ","); 77 | fprintf (file, " %" SBITSET__INDEX__CONVERSION_SPEC, i); 78 | } 79 | fprintf (file, " }"); 80 | } 81 | -------------------------------------------------------------------------------- /src/Sbitset.h: -------------------------------------------------------------------------------- 1 | /* A simple, memory-efficient bitset implementation. 2 | 3 | Copyright (C) 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef SBITSET_H_ 21 | # define SBITSET_H_ 22 | 23 | typedef unsigned char *Sbitset; 24 | typedef size_t Sbitset__Index; 25 | #define SBITSET__INDEX__CONVERSION_SPEC "zu" 26 | 27 | #define Sbitset__nbytes(NBITS) \ 28 | (((NBITS) + CHAR_BIT - 1) / CHAR_BIT) 29 | #define Sbitset__byteAddress(SELF, INDEX) \ 30 | (((SELF) + (INDEX) / CHAR_BIT)) 31 | #define Sbitset__bit_mask(INDEX) \ 32 | (1 << (CHAR_BIT - 1 - (INDEX) % CHAR_BIT)) 33 | #define Sbitset__last_byte_mask(NBITS) \ 34 | (UCHAR_MAX << (CHAR_BIT - 1 - ((NBITS) - 1) % CHAR_BIT)) 35 | 36 | /* nbits must not be 0. */ 37 | Sbitset Sbitset__new (Sbitset__Index nbits); 38 | Sbitset Sbitset__new_on_obstack (Sbitset__Index nbits, 39 | struct obstack *obstackp); 40 | void Sbitset__delete (Sbitset self); 41 | 42 | #define Sbitset__test(SELF, INDEX) \ 43 | ((*Sbitset__byteAddress ((SELF), (INDEX)) & Sbitset__bit_mask (INDEX)) != 0) 44 | 45 | bool Sbitset__isEmpty (Sbitset self, Sbitset__Index nbits); 46 | 47 | void Sbitset__fprint(Sbitset self, Sbitset__Index nbits, FILE *file); 48 | 49 | #define Sbitset__set(SELF, INDEX) \ 50 | do { \ 51 | *Sbitset__byteAddress ((SELF), (INDEX)) = \ 52 | *Sbitset__byteAddress ((SELF), (INDEX)) | Sbitset__bit_mask (INDEX); \ 53 | } while(0) 54 | 55 | #define Sbitset__reset(SELF, INDEX) \ 56 | do { \ 57 | *Sbitset__byteAddress ((SELF), (INDEX)) = \ 58 | *Sbitset__byteAddress ((SELF), (INDEX)) & ~Sbitset__bit_mask (INDEX); \ 59 | } while(0) 60 | 61 | /* NBITS is the size of the bitset. More than NBITS bits might be reset. */ 62 | #define Sbitset__zero(SELF, NBITS) \ 63 | do { \ 64 | memset (SELF, 0, Sbitset__nbytes (NBITS)); \ 65 | } while(0) 66 | 67 | /* NBITS is the size of the bitset. More than NBITS bits might be set. */ 68 | #define Sbitset__ones(SELF, NBITS) \ 69 | do { \ 70 | memset (SELF, UCHAR_MAX, Sbitset__nbytes (NBITS)); \ 71 | } while(0) 72 | 73 | /* NBITS is the size of every bitset. More than NBITS bits might be set. */ 74 | #define Sbitset__or(SELF, OTHER1, OTHER2, NBITS) \ 75 | do { \ 76 | Sbitset ptr_self = (SELF); \ 77 | Sbitset ptr_other1 = (OTHER1); \ 78 | Sbitset ptr_other2 = (OTHER2); \ 79 | Sbitset end_self = ptr_self + Sbitset__nbytes (NBITS); \ 80 | for (; ptr_self < end_self; ++ptr_self, ++ptr_other1, ++ptr_other2) \ 81 | *ptr_self = *ptr_other1 | *ptr_other2; \ 82 | } while(0) 83 | 84 | #define SBITSET__FOR_EACH(SELF, NBITS, ITER, INDEX) \ 85 | for ((ITER) = (SELF); (ITER) < (SELF) + Sbitset__nbytes (NBITS); ++(ITER)) \ 86 | if (*(ITER) != 0) \ 87 | for ((INDEX) = ((ITER)-(SELF))*CHAR_BIT; \ 88 | (INDEX) < (NBITS) && (SELF)+(INDEX)/CHAR_BIT < (ITER)+1; \ 89 | ++(INDEX)) \ 90 | if (((*ITER) & Sbitset__bit_mask (INDEX)) != 0) 91 | 92 | #endif /* !SBITSET_H_ */ 93 | -------------------------------------------------------------------------------- /src/assoc.c: -------------------------------------------------------------------------------- 1 | /* Associativity information. 2 | 3 | Copyright (C) 2002, 2005-2006, 2008-2012 Free Software Foundation, 4 | Inc. 5 | 6 | This file is part of Bison, the GNU Compiler Compiler. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | #include 22 | #include "system.h" 23 | 24 | #include "assoc.h" 25 | 26 | 27 | const char * 28 | assoc_to_string (assoc a) 29 | { 30 | switch (a) 31 | { 32 | default: 33 | abort (); 34 | 35 | case undef_assoc: 36 | return "undefined associativity"; 37 | 38 | case right_assoc: 39 | return "%right"; 40 | 41 | case left_assoc: 42 | return "%left"; 43 | 44 | case non_assoc: 45 | return "%nonassoc"; 46 | 47 | case precedence_assoc: 48 | return "%precedence"; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/assoc.h: -------------------------------------------------------------------------------- 1 | /* Associativity information. 2 | 3 | Copyright (C) 2002, 2006, 2008-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef ASSOC_H_ 21 | # define ASSOC_H_ 22 | 23 | /* Associativity values for tokens and rules. */ 24 | typedef enum 25 | { 26 | undef_assoc, /** Not defined. */ 27 | right_assoc, /** %right */ 28 | left_assoc, /** %left */ 29 | non_assoc, /** %nonassoc */ 30 | precedence_assoc /** %precedence */ 31 | } assoc; 32 | 33 | char const *assoc_to_string (assoc a); 34 | 35 | #endif /* !ASSOC_H_ */ 36 | -------------------------------------------------------------------------------- /src/closure.h: -------------------------------------------------------------------------------- 1 | /* Subroutines for bison 2 | 3 | Copyright (C) 1984, 1989, 2000-2002, 2007, 2009-2012 Free Software 4 | Foundation, Inc. 5 | 6 | This file is part of Bison, the GNU Compiler Compiler. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | #ifndef CLOSURE_H_ 22 | # define CLOSURE_H_ 23 | 24 | # include "gram.h" 25 | 26 | /* Allocates the itemset and ruleset vectors, and precomputes useful 27 | data so that closure can be called. n is the number of elements to 28 | allocate for itemset. */ 29 | 30 | void new_closure (unsigned int n); 31 | 32 | 33 | /* Given the kernel (aka core) of a state (a sorted vector of item numbers 34 | ITEMS, of length N), set up RULESET and ITEMSET to indicate what 35 | rules could be run and which items could be accepted when those 36 | items are the active ones. 37 | 38 | RULESET contains a bit for each rule. CLOSURE sets the bits for 39 | all rules which could potentially describe the next input to be 40 | read. 41 | 42 | ITEMSET is a sorted vector of item numbers; NITEMSET is its size 43 | (actually, points to just beyond the end of the part of it that is 44 | significant). CLOSURE places there the indices of all items which 45 | represent units of input that could arrive next. */ 46 | 47 | void closure (item_number *items, size_t n); 48 | 49 | 50 | /* Frees ITEMSET, RULESET and internal data. */ 51 | 52 | void free_closure (void); 53 | 54 | extern item_number *itemset; 55 | extern size_t nitemset; 56 | 57 | #endif /* !CLOSURE_H_ */ 58 | -------------------------------------------------------------------------------- /src/complain.h: -------------------------------------------------------------------------------- 1 | /* Declaration for error-reporting function for Bison. 2 | 3 | Copyright (C) 2000-2002, 2006, 2009-2012 Free Software Foundation, 4 | Inc. 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . */ 18 | 19 | #ifndef COMPLAIN_H_ 20 | # define COMPLAIN_H_ 1 21 | 22 | # include "location.h" 23 | 24 | # ifdef __cplusplus 25 | extern "C" { 26 | # endif 27 | 28 | /** Record that a warning is about to be issued, and treat it as an 29 | error if warnings_flag & warnings_error. This is exported 30 | only for the sake of Yacc-compatible conflict reports in conflicts.c. 31 | All other warnings should be implemented in complain.c and should use 32 | the normal warning format. */ 33 | void set_warning_issued (void); 34 | 35 | /** Informative messages, but we proceed. Report iff 36 | warnings_flag & warnings_other. */ 37 | 38 | void warn (char const *format, ...) 39 | __attribute__ ((__format__ (__printf__, 1, 2))); 40 | 41 | void warn_at (location loc, char const *format, ...) 42 | __attribute__ ((__format__ (__printf__, 2, 3))); 43 | 44 | /* Generate a message aligned by an indent. 45 | When *indent == 0, assign message's indent to *indent, 46 | When *indent > 0, align the message by *indent value. */ 47 | void warn_at_indent (location loc, unsigned *indent, 48 | char const *format, ...) 49 | __attribute__ ((__format__ (__printf__, 3, 4))); 50 | 51 | /** An error, but we continue and die later. */ 52 | 53 | void complain (char const *format, ...) 54 | __attribute__ ((__format__ (__printf__, 1, 2))); 55 | 56 | void complain_at (location loc, char const *format, ...) 57 | __attribute__ ((__format__ (__printf__, 2, 3))); 58 | 59 | /* Generate a message aligned by an indent. 60 | When *indent == 0, assign message's indent to *indent, 61 | When *indent > 0, align the message by *indent value. */ 62 | void complain_at_indent (location loc, unsigned *indent, 63 | char const *format, ...) 64 | __attribute__ ((__format__ (__printf__, 3, 4))); 65 | 66 | /** An incompatibility with POSIX Yacc: mapped either to warn* or 67 | complain* depending on yacc_flag. */ 68 | 69 | void yacc_at (location loc, char const *format, ...) 70 | __attribute__ ((__format__ (__printf__, 2, 3))); 71 | 72 | /** A midrule-value warning. Report iff 73 | warnings_flag & warnings_midrule_values. */ 74 | 75 | void midrule_value_at (location loc, char const *format, ...) 76 | __attribute__ ((__format__ (__printf__, 2, 3))); 77 | 78 | /** A fatal error, causing immediate exit. */ 79 | 80 | void fatal (char const *format, ...) 81 | __attribute__ ((__noreturn__, __format__ (__printf__, 1, 2))); 82 | 83 | void fatal_at (location loc, char const *format, ...) 84 | __attribute__ ((__noreturn__, __format__ (__printf__, 2, 3))); 85 | 86 | /** Whether an error was reported. */ 87 | extern bool complaint_issued; 88 | 89 | # ifdef __cplusplus 90 | } 91 | # endif 92 | 93 | #endif /* !COMPLAIN_H_ */ 94 | -------------------------------------------------------------------------------- /src/conflicts.h: -------------------------------------------------------------------------------- 1 | /* Find and resolve or report lookahead conflicts for bison, 2 | 3 | Copyright (C) 2000-2002, 2004, 2007, 2009-2012 Free Software 4 | Foundation, Inc. 5 | 6 | This file is part of Bison, the GNU Compiler Compiler. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | #ifndef CONFLICTS_H_ 22 | # define CONFLICTS_H_ 23 | # include "state.h" 24 | 25 | void conflicts_solve (void); 26 | 27 | /** 28 | * Update state numbers recorded in internal arrays such that: 29 | * - \c nstates_old is the old number of states. 30 | * - Where \c i is the old state number, old_to_new[i] is either: 31 | * - \c nstates_old if state \c i is removed because it is unreachable. 32 | * - The new state number. 33 | * - The highest new state number is the number of remaining states - 1. 34 | * - The numerical order of the remaining states has not changed. 35 | */ 36 | void conflicts_update_state_numbers (state_number old_to_new[], 37 | state_number nstates_old); 38 | 39 | void conflicts_print (void); 40 | int conflicts_total_count (void); 41 | void conflicts_output (FILE *out); 42 | void conflicts_free (void); 43 | 44 | /* Were there conflicts? */ 45 | extern int expected_sr_conflicts; 46 | extern int expected_rr_conflicts; 47 | #endif /* !CONFLICTS_H_ */ 48 | -------------------------------------------------------------------------------- /src/derives.c: -------------------------------------------------------------------------------- 1 | /* Match rules with nonterminals for bison, 2 | 3 | Copyright (C) 1984, 1989, 2000-2003, 2005, 2009-2012 Free Software 4 | Foundation, Inc. 5 | 6 | This file is part of Bison, the GNU Compiler Compiler. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | #include 22 | #include "system.h" 23 | 24 | #include "getargs.h" 25 | 26 | #include "derives.h" 27 | #include "gram.h" 28 | #include "reader.h" 29 | #include "symtab.h" 30 | 31 | /* Linked list of rule numbers. */ 32 | typedef struct rule_list 33 | { 34 | struct rule_list *next; 35 | rule *value; 36 | } rule_list; 37 | 38 | rule ***derives; 39 | 40 | static void 41 | print_derives (void) 42 | { 43 | int i; 44 | 45 | fputs ("DERIVES\n", stderr); 46 | 47 | for (i = ntokens; i < nsyms; i++) 48 | { 49 | rule **rp; 50 | fprintf (stderr, "\t%s derives\n", symbols[i]->tag); 51 | for (rp = derives[i - ntokens]; *rp; ++rp) 52 | { 53 | fprintf (stderr, "\t\t%3d ", (*rp)->user_number); 54 | rule_rhs_print (*rp, stderr); 55 | } 56 | } 57 | 58 | fputs ("\n\n", stderr); 59 | } 60 | 61 | 62 | void 63 | derives_compute (void) 64 | { 65 | symbol_number i; 66 | rule_number r; 67 | rule **q; 68 | 69 | /* DSET[NTERM - NTOKENS] -- A linked list of the numbers of the rules 70 | whose LHS is NTERM. */ 71 | rule_list **dset = xcalloc (nvars, sizeof *dset); 72 | 73 | /* DELTS[RULE] -- There are NRULES rule number to attach to nterms. 74 | Instead of performing NRULES allocations for each, have an array 75 | indexed by rule numbers. */ 76 | rule_list *delts = xnmalloc (nrules, sizeof *delts); 77 | 78 | for (r = nrules - 1; r >= 0; --r) 79 | { 80 | symbol_number lhs = rules[r].lhs->number; 81 | rule_list *p = &delts[r]; 82 | /* A new LHS is found. */ 83 | p->next = dset[lhs - ntokens]; 84 | p->value = &rules[r]; 85 | dset[lhs - ntokens] = p; 86 | } 87 | 88 | /* DSET contains what we need under the form of a linked list. Make 89 | it a single array. */ 90 | 91 | derives = xnmalloc (nvars, sizeof *derives); 92 | q = xnmalloc (nvars + nrules, sizeof *q); 93 | 94 | for (i = ntokens; i < nsyms; i++) 95 | { 96 | rule_list *p = dset[i - ntokens]; 97 | derives[i - ntokens] = q; 98 | while (p) 99 | { 100 | *q++ = p->value; 101 | p = p->next; 102 | } 103 | *q++ = NULL; 104 | } 105 | 106 | if (trace_flag & trace_sets) 107 | print_derives (); 108 | 109 | free (dset); 110 | free (delts); 111 | } 112 | 113 | 114 | void 115 | derives_free (void) 116 | { 117 | free (derives[0]); 118 | free (derives); 119 | } 120 | -------------------------------------------------------------------------------- /src/derives.h: -------------------------------------------------------------------------------- 1 | /* Match rules with nonterminals for bison, 2 | 3 | Copyright (C) 1984, 1989, 2000-2002, 2009-2012 Free Software 4 | Foundation, Inc. 5 | 6 | This file is part of Bison, the GNU Compiler Compiler. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | #ifndef DERIVES_H_ 22 | # define DERIVES_H_ 23 | 24 | # include "gram.h" 25 | 26 | /* DERIVES[SYMBOL - NTOKENS] points to a vector of the rules that 27 | SYMBOL derives, terminated with NULL. */ 28 | extern rule ***derives; 29 | 30 | /* Compute DERIVES. */ 31 | 32 | void derives_compute (void); 33 | void derives_free (void); 34 | 35 | #endif /* !DERIVES_H_ */ 36 | -------------------------------------------------------------------------------- /src/files.h: -------------------------------------------------------------------------------- 1 | /* File names and variables for bison, 2 | 3 | Copyright (C) 1984, 1989, 2000-2002, 2006-2007, 2009-2012 Free 4 | Software Foundation, Inc. 5 | 6 | This file is part of Bison, the GNU Compiler Compiler. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | #ifndef FILES_H_ 22 | # define FILES_H_ 23 | 24 | # include "uniqstr.h" 25 | 26 | /* File name specified with -o for the output file, or 0 if no -o. */ 27 | extern char const *spec_outfile; 28 | 29 | /* File name for the parser (i.e., the one above, or its default.) */ 30 | extern char *parser_file_name; 31 | 32 | /* Symbol prefix specified with -p, or 0 if no -p. */ 33 | extern const char *spec_name_prefix; 34 | 35 | /* File name prefix specified with -b, or 0 if no -b. */ 36 | extern char const *spec_file_prefix; 37 | 38 | /* --verbose. */ 39 | extern char *spec_verbose_file; 40 | 41 | /* File name specified for the output graph. */ 42 | extern char *spec_graph_file; 43 | 44 | /* File name specified for the xml output. */ 45 | extern char *spec_xml_file; 46 | 47 | /* File name specified with --defines. */ 48 | extern char *spec_defines_file; 49 | 50 | /* Directory prefix of output file names. */ 51 | extern char *dir_prefix; 52 | 53 | /* The file name as given on the command line. 54 | Not named "input_file" because Flex uses this name for an argument, 55 | and therefore GCC warns about a name clash. */ 56 | extern uniqstr grammar_file; 57 | 58 | /* The current file name. Might change with %include, or with #line. */ 59 | extern uniqstr current_file; 60 | 61 | /* The computed base for output file names. */ 62 | extern char *all_but_ext; 63 | 64 | void compute_output_file_names (void); 65 | void output_file_names_free (void); 66 | void output_file_name_check (char **file_name); 67 | 68 | FILE *xfopen (const char *name, const char *mode); 69 | void xfclose (FILE *ptr); 70 | 71 | #endif /* !FILES_H_ */ 72 | -------------------------------------------------------------------------------- /src/flex-scanner.h: -------------------------------------------------------------------------------- 1 | /* Common parts between scan-code.l, scan-gram.l, and scan-skel.l. 2 | 3 | Copyright (C) 2006, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef FLEX_PREFIX 21 | # error "FLEX_PREFIX not defined" 22 | #endif 23 | 24 | /* Pacify "gcc -Wmissing-prototypes" when flex 2.5.31 is used. */ 25 | int FLEX_PREFIX (get_lineno) (void); 26 | FILE *FLEX_PREFIX (get_in) (void); 27 | FILE *FLEX_PREFIX (get_out) (void); 28 | int FLEX_PREFIX (get_leng) (void); 29 | char *FLEX_PREFIX (get_text) (void); 30 | void FLEX_PREFIX (set_lineno) (int); 31 | void FLEX_PREFIX (set_in) (FILE *); 32 | void FLEX_PREFIX (set_out) (FILE *); 33 | int FLEX_PREFIX (get_debug) (void); 34 | void FLEX_PREFIX (set_debug) (int); 35 | int FLEX_PREFIX (lex_destroy) (void); 36 | 37 | #define last_string FLEX_PREFIX (last_string) 38 | 39 | /* It seems to be a nice "feature" of Flex that one cannot use yytext, 40 | yyleng etc. when a prefix is given, since there is no longer a 41 | #define, but rather the token is actually changed in the output. 42 | However, this is not true for Flex 2.5.4. */ 43 | #ifndef yyleng 44 | # define yyleng FLEX_PREFIX (leng) 45 | #endif 46 | #ifndef yytext 47 | # define yytext FLEX_PREFIX (text) 48 | #endif 49 | 50 | /* Non-reentrant scanners generated by Flex 2.5.9 and later (and some earlier 51 | versions according to the Flex manual) leak memory if yylex_destroy is not 52 | invoked. However, yylex_destroy is not defined before Flex 2.5.9, so give 53 | an implementation here that at least appears to work with Flex 2.5.4. */ 54 | #if !defined YY_FLEX_MAJOR_VERSION || YY_FLEX_MAJOR_VERSION < 2 \ 55 | || (YY_FLEX_MAJOR_VERSION == 2 \ 56 | && (!defined YY_FLEX_MINOR_VERSION || YY_FLEX_MINOR_VERSION < 5 \ 57 | || (YY_FLEX_MINOR_VERSION == 5 \ 58 | && (!defined YY_FLEX_SUBMINOR_VERSION \ 59 | || YY_FLEX_SUBMINOR_VERSION < 9)))) 60 | # define yylex_destroy() yy_delete_buffer (YY_CURRENT_BUFFER) 61 | #endif 62 | 63 | /* OBSTACK_FOR_STRING -- Used to store all the characters that we need to 64 | keep (to construct ID, STRINGS etc.). Use the following macros to 65 | use it. 66 | 67 | Use STRING_GROW to append what has just been matched, and 68 | STRING_FINISH to end the string (it puts the ending 0). 69 | STRING_FINISH also stores this string in LAST_STRING, which can be 70 | used, and which is used by STRING_FREE to free the last string. */ 71 | 72 | #ifndef FLEX_NO_OBSTACK 73 | 74 | static struct obstack obstack_for_string; 75 | 76 | #define STRING_GROW \ 77 | obstack_grow (&obstack_for_string, yytext, yyleng) 78 | 79 | #define STRING_FINISH \ 80 | do { \ 81 | obstack_1grow (&obstack_for_string, '\0'); \ 82 | last_string = obstack_finish (&obstack_for_string); \ 83 | } while (0) 84 | 85 | #define STRING_FREE \ 86 | obstack_free (&obstack_for_string, last_string) 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /src/graphviz.c: -------------------------------------------------------------------------------- 1 | /* Output Graphviz specification of a state machine generated by Bison. 2 | 3 | Copyright (C) 2006-2007, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | /* Written by Paul Eggert and Satya Kiran Popuri. */ 21 | 22 | #include 23 | #include "system.h" 24 | 25 | #include 26 | 27 | #include "files.h" 28 | #include "graphviz.h" 29 | 30 | /* Return an unambiguous printable representation for NAME, suitable 31 | for C strings. Use slot 2 since the user may use slots 0 and 1. */ 32 | 33 | static char const * 34 | quote (char const *name) 35 | { 36 | return quotearg_n_style (2, c_quoting_style, name); 37 | } 38 | 39 | void 40 | start_graph (FILE *fout) 41 | { 42 | fprintf (fout, 43 | _("// Generated by %s.\n" 44 | "// Report bugs to <%s>.\n" 45 | "// Home page: <%s>.\n" 46 | "\n"), 47 | PACKAGE_STRING, 48 | PACKAGE_BUGREPORT, 49 | PACKAGE_URL); 50 | fprintf (fout, 51 | "digraph %s\n" 52 | "{\n", 53 | quote (grammar_file)); 54 | } 55 | 56 | void 57 | output_node (int id, char const *label, FILE *fout) 58 | { 59 | fprintf (fout, " %d [label=%s]\n", id, quote (label)); 60 | } 61 | 62 | void 63 | output_edge (int source, int destination, char const *label, 64 | char const *style, FILE *fout) 65 | { 66 | fprintf (fout, " %d -> %d [style=%s", source, destination, style); 67 | if (label) 68 | fprintf (fout, " label=%s", quote (label)); 69 | fputs ("]\n", fout); 70 | } 71 | 72 | void 73 | finish_graph (FILE *fout) 74 | { 75 | fputs ("}\n", fout); 76 | } 77 | -------------------------------------------------------------------------------- /src/graphviz.h: -------------------------------------------------------------------------------- 1 | /* Output Graphviz specification of a state machine generated by Bison. 2 | 3 | Copyright (C) 2006, 2010-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | /* Written by Paul Eggert and Satya Kiran Popuri. */ 21 | 22 | #ifndef GRAPHVIZ_H_ 23 | # define GRAPHVIZ_H_ 24 | 25 | /// Begin a Dot graph. 26 | /// \param fout output stream. 27 | void start_graph (FILE *fout); 28 | 29 | /// Output a Dot node. 30 | /// \param id identifier of the node 31 | /// \param label human readable label of the node (no Dot escaping needed). 32 | /// \param fout output stream. 33 | void output_node (int id, char const *label, FILE *fout); 34 | 35 | /// Output a Dot edge. 36 | /// \param source id of the source node 37 | /// \param destination id of the target node 38 | /// \param label human readable label of the edge 39 | /// (no Dot escaping needed). Can be 0. 40 | /// \param style Dot style of the edge (e.g., "dotted" or "solid"). 41 | /// \param fout output stream. 42 | void output_edge (int source, int destination, char const *label, 43 | char const *style, FILE *fout); 44 | 45 | /// End a Dot graph. 46 | /// \param fout output stream. 47 | void finish_graph (FILE *fout); 48 | 49 | #endif /* ! GRAPHVIZ_H_ */ 50 | -------------------------------------------------------------------------------- /src/ielr.h: -------------------------------------------------------------------------------- 1 | /* IELR main implementation. 2 | 3 | Copyright (C) 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef IELR_H_ 21 | # define IELR_H_ 22 | 23 | #include 24 | 25 | #include "state.h" 26 | 27 | /** 28 | * \pre 29 | * - \c ::states is of size \c ::nstates and defines an LR(0) parser 30 | * for the users's grammar. 31 | * - \c ::ntokens is the number of tokens in the grammar. 32 | * \post 33 | * - \c ::states is of size \c ::nstates (which might be greater than 34 | * ::nstates \@pre) and defines the type of parser specified by 35 | * the value of the \c \%define variable \c lr.type. Its value can be: 36 | * - \c "lalr". 37 | * - \c "ielr". 38 | * - \c "canonical-lr". 39 | */ 40 | void ielr (void); 41 | 42 | bool ielr_item_has_lookahead (state *s, symbol_number lhs, size_t item, 43 | symbol_number lookahead, state ***predecessors, 44 | bitset **item_lookahead_sets); 45 | 46 | #endif /* !IELR_H_ */ 47 | -------------------------------------------------------------------------------- /src/lalr.h: -------------------------------------------------------------------------------- 1 | /* Compute lookahead criteria for bison, 2 | 3 | Copyright (C) 1984, 1986, 1989, 2000, 2002, 2004, 2006-2007, 4 | 2009-2012 Free Software Foundation, Inc. 5 | 6 | This file is part of Bison, the GNU Compiler Compiler. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | #ifndef LALR_H_ 22 | # define LALR_H_ 23 | 24 | # include 25 | # include 26 | 27 | /* Import the definition of RULE_T. */ 28 | # include "gram.h" 29 | 30 | /* Import the definition of CORE, TRANSITIONS and REDUCTIONS. */ 31 | # include "state.h" 32 | 33 | 34 | /** Build the LALR(1) automaton. 35 | 36 | Find which rules need lookahead in each state, and which lookahead 37 | tokens they accept. 38 | 39 | Also builds: 40 | - #goto_map 41 | - #from_state 42 | - #to_state 43 | - #goto_follows 44 | */ 45 | void lalr (void); 46 | 47 | /** 48 | * Set #nLA and allocate all reduction lookahead sets. Normally invoked by 49 | * #lalr. 50 | */ 51 | void initialize_LA (void); 52 | 53 | /** 54 | * Build only: 55 | * - #goto_map 56 | * - #from_state 57 | * - #to_state 58 | * Normally invoked by #lalr. 59 | */ 60 | void set_goto_map (void); 61 | 62 | /** 63 | * Update state numbers recorded in #goto_map, #from_state, and #to_state such 64 | * that: 65 | * - \c nstates_old is the old number of states. 66 | * - Where \c i is the old state number, old_to_new[i] is either: 67 | * - \c nstates_old if state \c i is removed because it is unreachable. 68 | * Thus, remove all goto entries involving this state. 69 | * - The new state number. 70 | */ 71 | void lalr_update_state_numbers (state_number old_to_new[], 72 | state_number nstates_old); 73 | 74 | 75 | /** Release the information related to lookahead tokens. 76 | 77 | Can be performed once the action tables are computed. */ 78 | void lalr_free (void); 79 | 80 | typedef size_t goto_number; 81 | # define GOTO_NUMBER_MAXIMUM ((goto_number) -1) 82 | 83 | /** Index into #from_state and #to_state. 84 | 85 | All the transitions that accept a particular variable are grouped 86 | together and GOTO_MAP[I - NTOKENS] is the index in FROM_STATE and 87 | TO_STATE of the first of them. */ 88 | extern goto_number *goto_map; 89 | 90 | /** The size of #from_state and #to_state. */ 91 | extern goto_number ngotos; 92 | 93 | /** State number which a transition leads from. */ 94 | extern state_number *from_state; 95 | 96 | /** State number it leads to. */ 97 | extern state_number *to_state; 98 | 99 | /** Map a state/symbol pair into its numeric representation. */ 100 | goto_number map_goto (state_number s0, symbol_number sym); 101 | 102 | /* goto_follows[i] is the set of tokens following goto i. */ 103 | extern bitsetv goto_follows; 104 | 105 | 106 | #endif /* !LALR_H_ */ 107 | -------------------------------------------------------------------------------- /src/location.h: -------------------------------------------------------------------------------- 1 | /* Locations for Bison 2 | 3 | Copyright (C) 2002, 2004-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef LOCATION_H_ 21 | # define LOCATION_H_ 22 | 23 | # include "uniqstr.h" 24 | 25 | /* A boundary between two characters. */ 26 | typedef struct 27 | { 28 | /* The name of the file that contains the boundary. */ 29 | uniqstr file; 30 | 31 | /* If nonnegative, the (origin-1) line that contains the boundary. 32 | If this is INT_MAX, the line number has overflowed. 33 | 34 | Meaningless and not displayed if negative. 35 | */ 36 | int line; 37 | 38 | /* If nonnegative, the (origin-1) column just after the boundary. 39 | This is neither a byte count, nor a character count; it is a 40 | column count. If this is INT_MAX, the column number has 41 | overflowed. 42 | 43 | Meaningless and not displayed if negative. 44 | */ 45 | int column; 46 | 47 | } boundary; 48 | 49 | /* Set the position of \a a. */ 50 | static inline void 51 | boundary_set (boundary *b, const char *f, int l, int c) 52 | { 53 | b->file = f; 54 | b->line = l; 55 | b->column = c; 56 | } 57 | 58 | /* Return -1, 0, 1, depending whether a is before, equal, or 59 | after b. */ 60 | static inline int 61 | boundary_cmp (boundary a, boundary b) 62 | { 63 | int res = strcmp (a.file, b.file); 64 | if (!res) 65 | res = a.line - b.line; 66 | if (!res) 67 | res = a.column - b.column; 68 | return res; 69 | } 70 | 71 | /* Return nonzero if A and B are equal boundaries. */ 72 | static inline bool 73 | equal_boundaries (boundary a, boundary b) 74 | { 75 | return (a.column == b.column 76 | && a.line == b.line 77 | && UNIQSTR_EQ (a.file, b.file)); 78 | } 79 | 80 | /* A location, that is, a region of source code. */ 81 | typedef struct 82 | { 83 | /* Boundary just before the location starts. */ 84 | boundary start; 85 | 86 | /* Boundary just after the location ends. */ 87 | boundary end; 88 | 89 | } location; 90 | 91 | #define YYLTYPE location 92 | 93 | #define EMPTY_LOCATION_INIT {{NULL, 0, 0}, {NULL, 0, 0}} 94 | extern location const empty_location; 95 | 96 | /* Set *LOC and adjust scanner cursor to account for token TOKEN of 97 | size SIZE. */ 98 | void location_compute (location *loc, 99 | boundary *cur, char const *token, size_t size); 100 | 101 | /* Print location to file. Return number of actually printed 102 | characters. */ 103 | unsigned location_print (FILE *out, location loc); 104 | 105 | /* Return -1, 0, 1, depending whether a is before, equal, or 106 | after b. */ 107 | static inline int 108 | location_cmp (location a, location b) 109 | { 110 | int res = boundary_cmp (a.start, b.start); 111 | if (!res) 112 | res = boundary_cmp (a.end, b.end); 113 | return res; 114 | } 115 | 116 | /* LOC_STR must be formatted as `file:line.column', it will be modified. */ 117 | void boundary_set_from_string (boundary *bound, char *loc_str); 118 | 119 | #endif /* ! defined LOCATION_H_ */ 120 | -------------------------------------------------------------------------------- /src/named-ref.c: -------------------------------------------------------------------------------- 1 | /* Named symbol references for Bison 2 | 3 | Copyright (C) 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #include 21 | #include "system.h" 22 | 23 | #include "named-ref.h" 24 | 25 | named_ref * 26 | named_ref_new (uniqstr id, location loc) 27 | { 28 | named_ref *res = xmalloc (sizeof *res); 29 | 30 | res->id = id; 31 | res->loc = loc; 32 | 33 | return res; 34 | } 35 | 36 | named_ref * 37 | named_ref_copy (const named_ref *r) 38 | { 39 | return named_ref_new (r->id, r->loc); 40 | } 41 | 42 | void 43 | named_ref_free (named_ref *r) 44 | { 45 | free (r); 46 | } 47 | -------------------------------------------------------------------------------- /src/named-ref.h: -------------------------------------------------------------------------------- 1 | /* Named symbol references for Bison 2 | 3 | Copyright (C) 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef NAMED_REF_H_ 21 | # define NAMED_REF_H_ 22 | 23 | #include "location.h" 24 | #include "uniqstr.h" 25 | 26 | /* Named reference object. Keeps information about 27 | a symbolic name of a symbol in a rule. */ 28 | typedef struct named_ref 29 | { 30 | /* Symbolic named given by user. */ 31 | uniqstr id; 32 | 33 | /* Location of the symbolic name. Not including brackets. */ 34 | location loc; 35 | } named_ref; 36 | 37 | /* Allocate a named reference object. */ 38 | named_ref *named_ref_new (uniqstr id, location loc); 39 | 40 | /* Allocate and return a copy. */ 41 | named_ref *named_ref_copy (const named_ref *r); 42 | 43 | /* Free a named reference object. */ 44 | void named_ref_free (named_ref *r); 45 | 46 | #endif /* !NAMED_REF_H_ */ 47 | -------------------------------------------------------------------------------- /src/nullable.h: -------------------------------------------------------------------------------- 1 | /* Part of the bison parser generator, 2 | 3 | Copyright (C) 2000, 2002, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef NULLABLE_H_ 21 | # define NULLABLE_H_ 22 | 23 | /* A vector saying which nonterminals can expand into the null string. 24 | NULLABLE[I - NTOKENS] is nonzero if symbol I can do so. */ 25 | extern bool *nullable; 26 | 27 | /* Set up NULLABLE. */ 28 | extern void nullable_compute (void); 29 | 30 | /* Free NULLABLE. */ 31 | extern void nullable_free (void); 32 | #endif /* !NULLABLE_H_ */ 33 | -------------------------------------------------------------------------------- /src/output.h: -------------------------------------------------------------------------------- 1 | /* Output the generated parsing program for bison, 2 | 3 | Copyright (C) 2000-2003, 2006-2007, 2009-2012 Free Software 4 | Foundation, Inc. 5 | 6 | This file is part of Bison, the GNU Compiler Compiler. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | #ifndef OUTPUT_H_ 22 | # define OUTPUT_H_ 23 | 24 | /* Output the parsing tables and the parser code to FTABLE. */ 25 | void output (void); 26 | char const *compute_pkgdatadir (void); 27 | 28 | #endif /* !OUTPUT_H_ */ 29 | -------------------------------------------------------------------------------- /src/print-xml.h: -------------------------------------------------------------------------------- 1 | /* Output an xml of the generated parser, for Bison. 2 | 3 | Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef PRINT_XML_H_ 21 | # define PRINT_XML_H_ 22 | 23 | void xml_indent (FILE *out, int level); 24 | void xml_puts (FILE *, int, char const *); 25 | void xml_printf (FILE *, int, char const *, ...); 26 | char const *xml_escape_n (int n, char const *str); 27 | char const *xml_escape (char const *str); 28 | void print_xml (void); 29 | 30 | #endif /* !PRINT_XML_H_ */ 31 | -------------------------------------------------------------------------------- /src/print.h: -------------------------------------------------------------------------------- 1 | /* Print information on generated parser, for bison, 2 | 3 | Copyright (C) 2000, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef PRINT_H_ 21 | # define PRINT_H_ 22 | 23 | void print_results (void); 24 | 25 | #endif /* !PRINT_H_ */ 26 | -------------------------------------------------------------------------------- /src/print_graph.h: -------------------------------------------------------------------------------- 1 | /* Output a graph of the generated parser, for Bison. 2 | 3 | Copyright (C) 2000, 2006, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef PRINT_GRAPH_H_ 21 | # define PRINT_GRAPH_H_ 22 | 23 | void print_graph (void); 24 | 25 | #endif /* !PRINT_GRAPH_H_ */ 26 | -------------------------------------------------------------------------------- /src/reader.h: -------------------------------------------------------------------------------- 1 | /* Input parser for Bison 2 | 3 | Copyright (C) 2000-2003, 2005-2007, 2009-2012 Free Software 4 | Foundation, Inc. 5 | 6 | This file is part of Bison, the GNU Compiler Compiler. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | #ifndef READER_H_ 22 | # define READER_H_ 23 | 24 | # include "location.h" 25 | # include "symlist.h" 26 | # include "named-ref.h" 27 | 28 | # include "parse-gram.h" 29 | 30 | typedef struct merger_list 31 | { 32 | struct merger_list* next; 33 | uniqstr name; 34 | uniqstr type; 35 | location type_declaration_location; 36 | } merger_list; 37 | 38 | /* From the parser. */ 39 | extern int gram_debug; 40 | int gram_parse (void); 41 | char const *token_name (int type); 42 | 43 | 44 | /* From reader.c. */ 45 | void grammar_start_symbol_set (symbol *sym, location loc); 46 | void grammar_current_rule_begin (symbol *lhs, location loc, 47 | named_ref *lhs_named_ref); 48 | void grammar_current_rule_end (location loc); 49 | void grammar_midrule_action (void); 50 | void grammar_current_rule_prec_set (symbol *precsym, location loc); 51 | void grammar_current_rule_dprec_set (int dprec, location loc); 52 | void grammar_current_rule_merge_set (uniqstr name, location loc); 53 | void grammar_current_rule_symbol_append (symbol *sym, location loc, 54 | named_ref *named_ref); 55 | void grammar_current_rule_action_append (const char *action, location loc, 56 | named_ref *named_ref, bool); 57 | void reader (void); 58 | void free_merger_functions (void); 59 | 60 | extern merger_list *merge_functions; 61 | 62 | /* Was %union seen? */ 63 | extern bool union_seen; 64 | 65 | /* Was a tag seen? */ 66 | extern bool tag_seen; 67 | 68 | /* Should rules have a default precedence? */ 69 | extern bool default_prec; 70 | 71 | #endif /* !READER_H_ */ 72 | -------------------------------------------------------------------------------- /src/reduce.h: -------------------------------------------------------------------------------- 1 | /* Grammar reduction for Bison. 2 | 3 | Copyright (C) 2000-2002, 2007, 2009-2012 Free Software Foundation, 4 | Inc. 5 | 6 | This file is part of Bison, the GNU Compiler Compiler. 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . */ 20 | 21 | #ifndef REDUCE_H_ 22 | # define REDUCE_H_ 23 | 24 | void reduce_grammar (void); 25 | void reduce_output (FILE *out); 26 | bool reduce_token_unused_in_grammar (symbol_number i); 27 | bool reduce_nonterminal_useless_in_grammar (symbol_number i); 28 | void reduce_free (void); 29 | 30 | extern symbol_number nuseless_nonterminals; 31 | extern rule_number nuseless_productions; 32 | #endif /* !REDUCE_H_ */ 33 | -------------------------------------------------------------------------------- /src/relation.h: -------------------------------------------------------------------------------- 1 | /* Binary relations. 2 | 3 | Copyright (C) 2002, 2004, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | 21 | #ifndef RELATION_H_ 22 | # define RELATION_H_ 23 | 24 | /* Performing operations on graphs coded as list of adjacency. 25 | 26 | If GRAPH is a relation, then GRAPH[Node] is a list of adjacent 27 | nodes, ended with END_NODE. */ 28 | 29 | #define END_NODE ((relation_node) -1) 30 | 31 | typedef size_t relation_node; 32 | typedef relation_node *relation_nodes; 33 | typedef relation_nodes *relation; 34 | 35 | 36 | /* Report a relation R that has SIZE vertices. */ 37 | void relation_print (relation r, relation_node size, FILE *out); 38 | 39 | /* Compute the transitive closure of the FUNCTION on the relation R 40 | with SIZE vertices. 41 | 42 | If R (NODE-1, NODE-2) then on exit FUNCTION[NODE - 1] was extended 43 | (unioned) with FUNCTION[NODE - 2]. */ 44 | void relation_digraph (relation r, relation_node size, bitsetv *function); 45 | 46 | /* Destructively transpose *R_ARG, of size N. */ 47 | void relation_transpose (relation *R_arg, relation_node n); 48 | 49 | #endif /* ! RELATION_H_ */ 50 | -------------------------------------------------------------------------------- /src/scan-code-c.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "system.h" 3 | #include "src/scan-code.c" 4 | -------------------------------------------------------------------------------- /src/scan-gram-c.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "system.h" 3 | #include "src/scan-gram.c" 4 | -------------------------------------------------------------------------------- /src/scan-gram.h: -------------------------------------------------------------------------------- 1 | /* Bison Grammar Scanner 2 | 3 | Copyright (C) 2006-2007, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef SCAN_GRAM_H_ 21 | # define SCAN_GRAM_H_ 22 | 23 | /* From the scanner. */ 24 | extern FILE *gram_in; 25 | extern int gram__flex_debug; 26 | void gram_scanner_initialize (void); 27 | void gram_scanner_free (void); 28 | void gram_scanner_last_string_free (void); 29 | 30 | /* These are declared by the scanner, but not used. We put them here 31 | to pacify "make syntax-check". */ 32 | extern FILE *gram_out; 33 | extern int gram_lineno; 34 | 35 | # define GRAM_LEX_DECL int gram_lex (YYSTYPE *val, location *loc) 36 | GRAM_LEX_DECL; 37 | 38 | #endif /* !SCAN_GRAM_H_ */ 39 | -------------------------------------------------------------------------------- /src/scan-skel-c.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "system.h" 3 | #include "src/scan-skel.c" 4 | -------------------------------------------------------------------------------- /src/scan-skel.h: -------------------------------------------------------------------------------- 1 | /* Scan Bison Skeletons. 2 | 3 | Copyright (C) 2005-2007, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | void scan_skel (FILE *); 21 | 22 | /* Pacify "make syntax-check". */ 23 | extern FILE *skel_in; 24 | extern FILE *skel_out; 25 | extern int skel__flex_debug; 26 | extern int skel_lineno; 27 | void skel_scanner_free (void); 28 | -------------------------------------------------------------------------------- /src/uniqstr.c: -------------------------------------------------------------------------------- 1 | /* Keep a unique copy of strings. 2 | 3 | Copyright (C) 2002-2005, 2009-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #include 21 | #include "system.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "uniqstr.h" 29 | 30 | /*-----------------------. 31 | | A uniqstr hash table. | 32 | `-----------------------*/ 33 | 34 | /* Initial capacity of uniqstr hash table. */ 35 | #define HT_INITIAL_CAPACITY 257 36 | 37 | static struct hash_table *uniqstrs_table = NULL; 38 | 39 | /*-------------------------------------. 40 | | Create the uniqstr for S if needed. | 41 | `-------------------------------------*/ 42 | 43 | uniqstr 44 | uniqstr_new (char const *str) 45 | { 46 | uniqstr res = hash_lookup (uniqstrs_table, str); 47 | if (!res) 48 | { 49 | /* First insertion in the hash. */ 50 | res = xstrdup (str); 51 | if (!hash_insert (uniqstrs_table, res)) 52 | xalloc_die (); 53 | } 54 | return res; 55 | } 56 | 57 | uniqstr 58 | uniqstr_vsprintf (char const *format, ...) 59 | { 60 | va_list args; 61 | size_t length; 62 | va_start (args, format); 63 | length = vsnprintf (NULL, 0, format, args); 64 | va_end (args); 65 | 66 | char res[length + 1]; 67 | va_start (args, format); 68 | vsprintf (res, format, args); 69 | va_end (args); 70 | return uniqstr_new (res); 71 | } 72 | 73 | /*------------------------------. 74 | | Abort if S is not a uniqstr. | 75 | `------------------------------*/ 76 | 77 | void 78 | uniqstr_assert (char const *str) 79 | { 80 | if (!hash_lookup (uniqstrs_table, str)) 81 | { 82 | error (0, 0, 83 | "not a uniqstr: %s", quotearg (str)); 84 | abort (); 85 | } 86 | } 87 | 88 | 89 | /*--------------------. 90 | | Print the uniqstr. | 91 | `--------------------*/ 92 | 93 | static inline bool 94 | uniqstr_print (uniqstr ustr) 95 | { 96 | fprintf (stderr, "%s\n", ustr); 97 | return true; 98 | } 99 | 100 | static bool 101 | uniqstr_print_processor (void *ustr, void *null ATTRIBUTE_UNUSED) 102 | { 103 | return uniqstr_print (ustr); 104 | } 105 | 106 | 107 | /*-----------------------. 108 | | A uniqstr hash table. | 109 | `-----------------------*/ 110 | 111 | static bool 112 | hash_compare_uniqstr (void const *m1, void const *m2) 113 | { 114 | return STREQ (m1, m2); 115 | } 116 | 117 | static size_t 118 | hash_uniqstr (void const *m, size_t tablesize) 119 | { 120 | return hash_string (m, tablesize); 121 | } 122 | 123 | /*----------------------------. 124 | | Create the uniqstrs table. | 125 | `----------------------------*/ 126 | 127 | void 128 | uniqstrs_new (void) 129 | { 130 | uniqstrs_table = hash_initialize (HT_INITIAL_CAPACITY, 131 | NULL, 132 | hash_uniqstr, 133 | hash_compare_uniqstr, 134 | free); 135 | } 136 | 137 | 138 | /*-------------------------------------. 139 | | Perform a task on all the uniqstrs. | 140 | `-------------------------------------*/ 141 | 142 | static void 143 | uniqstrs_do (Hash_processor processor, void *processor_data) 144 | { 145 | hash_do_for_each (uniqstrs_table, processor, processor_data); 146 | } 147 | 148 | 149 | /*-----------------. 150 | | Print them all. | 151 | `-----------------*/ 152 | 153 | void 154 | uniqstrs_print (void) 155 | { 156 | uniqstrs_do (uniqstr_print_processor, NULL); 157 | } 158 | 159 | 160 | /*--------------------. 161 | | Free the uniqstrs. | 162 | `--------------------*/ 163 | 164 | void 165 | uniqstrs_free (void) 166 | { 167 | hash_free (uniqstrs_table); 168 | } 169 | -------------------------------------------------------------------------------- /src/uniqstr.h: -------------------------------------------------------------------------------- 1 | /* Keeping a unique copy of strings. 2 | 3 | Copyright (C) 2002-2003, 2008-2012 Free Software Foundation, Inc. 4 | 5 | This file is part of Bison, the GNU Compiler Compiler. 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . */ 19 | 20 | #ifndef UNIQSTR_H_ 21 | # define UNIQSTR_H_ 22 | 23 | /*-----------------------------------------. 24 | | Pointers to unique copies of C strings. | 25 | `-----------------------------------------*/ 26 | 27 | typedef char const *uniqstr; 28 | 29 | /* Return the uniqstr for STR. */ 30 | uniqstr uniqstr_new (char const *str); 31 | 32 | /* Return a uniqstr built by vsprintf. In order to simply concatenate 33 | strings, use UNIQSTR_CONCAT, which is a convenient wrapper around 34 | this function. */ 35 | uniqstr uniqstr_vsprintf (char const *format, ...) 36 | __attribute__ ((__format__ (__printf__, 1, 2))); 37 | 38 | /* Two uniqstr values have the same value iff they are the same. */ 39 | #define UNIQSTR_EQ(USTR1, USTR2) ((USTR1) == (USTR2)) 40 | 41 | /* Compare two uniqstr a la strcmp: negative for <, nul for =, and 42 | positive for >. Undefined order, relies on addresses. */ 43 | #define UNIQSTR_CMP(USTR1, USTR2) ((USTR1) - (USTR2)) 44 | 45 | /*--------------------------------------. 46 | | Initializing, destroying, debugging. | 47 | `--------------------------------------*/ 48 | 49 | /* Create the string table. */ 50 | void uniqstrs_new (void); 51 | 52 | /* Die if STR is not a uniqstr. */ 53 | void uniqstr_assert (char const *str); 54 | 55 | /* Free all the memory allocated for symbols. */ 56 | void uniqstrs_free (void); 57 | 58 | /* Report them all. */ 59 | void uniqstrs_print (void); 60 | 61 | /*----------------. 62 | | Concatenation. | 63 | `----------------*/ 64 | 65 | /* Concatenate at most 20 strings and return a uniqstr. The goal of 66 | this macro is to make the caller's code a little more succinct 67 | without a trivial uniqstr_vsprintf format string to maintain 68 | (for example, "%s%s%s") while still benefitting from gcc's type 69 | checking. Unfortunately, because of the missing format string in the 70 | macro invocation, the argument number reported by gcc for a bad 71 | argument type is 1 too large. */ 72 | #define UNIQSTR_CONCAT(...) \ 73 | uniqstr_vsprintf (UNIQSTR_GEN_FORMAT (__VA_ARGS__, \ 74 | "%s", "%s", "%s", "%s", "%s", \ 75 | "%s", "%s", "%s", "%s", "%s", \ 76 | "%s", "%s", "%s", "%s", "%s", \ 77 | "%s", "%s", "%s", "%s", "%s"), \ 78 | __VA_ARGS__) 79 | 80 | #define UNIQSTR_GEN_FORMAT(F1, F2, F3, F4, F5, \ 81 | F6, F7, F8, F9, F10, \ 82 | F11, F12, F13, F14, F15, \ 83 | F16, F17, F18, F19, F20, \ 84 | ...) \ 85 | UNIQSTR_GEN_FORMAT_ (__VA_ARGS__, \ 86 | "", "", "", "", "", \ 87 | "", "", "", "", "", \ 88 | "", "", "", "", "", \ 89 | "", "", "", "", "") 90 | 91 | #define UNIQSTR_GEN_FORMAT_(F1, F2, F3, F4, F5, \ 92 | F6, F7, F8, F9, F10, \ 93 | F11, F12, F13, F14, F15, \ 94 | F16, F17, F18, F19, F20, ...) \ 95 | F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 \ 96 | F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 97 | 98 | #endif /* ! defined UNIQSTR_H_ */ 99 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | /*.dot 2 | /*.output 3 | /atconfig 4 | /atlocal 5 | /autom4te.cache 6 | /bison 7 | /calc 8 | /calc.[chy] 9 | /calc.tab.* 10 | /package.m4 11 | /testsuite 12 | /testsuite.dir 13 | /testsuite.log 14 | -------------------------------------------------------------------------------- /tests/atlocal.in: -------------------------------------------------------------------------------- 1 | # @configure_input@ -*- shell-script -*- 2 | # Configurable variable values for Bison test suite. 3 | 4 | # Copyright (C) 2000-2012 Free Software Foundation, Inc. 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | # We need a C compiler. 20 | : ${CC='@CC@'} 21 | 22 | # We want no optimization. 23 | CFLAGS='@O0CFLAGS@ @WARN_CFLAGS_TEST@ @WERROR_CFLAGS@' 24 | 25 | # Sometimes a test group needs to ignore gcc warnings, so it locally 26 | # sets CFLAGS to this. 27 | NO_WERROR_CFLAGS='@O0CFLAGS@ @WARN_CFLAGS_TEST@' 28 | 29 | # We need `config.h'. 30 | CPPFLAGS="-I$abs_top_builddir/lib @CPPFLAGS@" 31 | 32 | # Is the compiler GCC? 33 | GCC='@GCC@' 34 | 35 | # The C++ compiler. 36 | : ${CXX='@CXX@'} 37 | 38 | # If 'exit 77'; skip all C++ tests; otherwise ':'. 39 | BISON_CXX_WORKS='@BISON_CXX_WORKS@' 40 | 41 | # We want no optimization with C++, too. 42 | CXXFLAGS='@O0CXXFLAGS@ @WARN_CXXFLAGS_TEST@ @WERROR_CFLAGS@' 43 | 44 | # Are special link options needed? 45 | LDFLAGS='@LDFLAGS@' 46 | 47 | # Are special libraries needed? 48 | LIBS="$abs_top_builddir/lib/libbison.a @LIBS@ @INTLLIBS@" 49 | 50 | # Empty if no javac was found 51 | CONF_JAVAC='@CONF_JAVAC@' 52 | 53 | # Empty if no Java VM was found 54 | CONF_JAVA='@CONF_JAVA@' 55 | 56 | # Empty if no xsltproc was found 57 | : ${XSLTPROC='@XSLTPROC@'} 58 | 59 | # We need egrep. 60 | : ${EGREP='@EGREP@'} 61 | -------------------------------------------------------------------------------- /tests/bison.in: -------------------------------------------------------------------------------- 1 | #! @SHELL@ 2 | # @configure_input@ 3 | # Wrapper around a non installed bison to make it work as an installed one. 4 | 5 | # Copyright (C) 2001-2012 Free Software Foundation, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | abs_top_srcdir='@abs_top_srcdir@' 21 | abs_top_builddir='@abs_top_builddir@' 22 | 23 | : ${PERL=perl} 24 | 25 | # Use the shipped files, not those installed. 26 | BISON_PKGDATADIR=$abs_top_srcdir/data 27 | export BISON_PKGDATADIR 28 | 29 | trap 'rm -f /tmp/bison.$$.*; exit $status' 0 1 2 13 15 30 | $PREBISON "$abs_top_builddir/src/bison" ${1+"$@"} 2>/tmp/bison.$$.err 31 | status=$? 32 | # Protect from gettextized quotes. See quotearg.c's gettext_quote for 33 | # the UTF-8 sequences. For context, see 34 | # http://lists.gnu.org/archive/html/bug-bison/2012-01/msg00120.html 35 | # 36 | # In UTF-8 the quoting quote are not ', so bison use them to quote the 37 | # ' character. When using ASCII quotes, bison issues "'". 38 | $PERL -p \ 39 | -e "s{\\xe2\\x80\\x98|\\xe2\\x80\\x99|\\xa1\\ae|\\xa1\\xaf}{'}g;" \ 40 | -e "s{'''}{\"'\"}g;" \ 41 | /tmp/bison.$$.err >&2 42 | 43 | # As a special dark magic, if we are actually using this wrapper to 44 | # compile Bison's src/parse-gram.y, post-process the synclines to 45 | # avoid dependencies on the user's set up (srcdir vs. builddir). 46 | for i 47 | do 48 | case $i in 49 | */src/parse-gram.y) 50 | if $PERL --version >/dev/null; then 51 | # We are called by ylwrap which still uses y.tab.*, and 52 | # post-processes the synclines on y.tab.c itself. Don't let it 53 | # do it. Besides, it leaves "parse-gram.y" as the source, 54 | # dropping the src/ part. 55 | $PERL -pi -e 's{"y\.tab\.}{"src/parse-gram.}g;' \ 56 | -e 's{".*/(parse-gram\.y)"}{"src/$1"}g;' \ 57 | y.tab.[ch] 58 | fi 59 | ;; 60 | esac 61 | done 62 | 63 | exit $status 64 | 65 | # Local Variables: 66 | # mode: shell-script 67 | # End: 68 | -------------------------------------------------------------------------------- /tests/headers.at: -------------------------------------------------------------------------------- 1 | # Bison Parser Headers. -*- Autotest -*- 2 | 3 | # Copyright (C) 2001-2002, 2006-2007, 2009-2012 Free Software 4 | # Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | AT_BANNER([[Parser Headers.]]) 20 | 21 | 22 | ## ---------------------- ## 23 | ## %union and --defines. ## 24 | ## ---------------------- ## 25 | 26 | 27 | AT_SETUP([%union and --defines]) 28 | 29 | AT_DATA([input.y], 30 | [%union 31 | { 32 | int integer; 33 | char *string ; 34 | } 35 | %% 36 | exp: {}; 37 | ]) 38 | 39 | AT_BISON_CHECK([--defines input.y]) 40 | 41 | AT_CLEANUP 42 | 43 | 44 | 45 | ## --------------------- ## 46 | ## Invalid CPP headers. ## 47 | ## --------------------- ## 48 | 49 | # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE) 50 | # ------------------------------------- 51 | m4_define([AT_TEST_CPP_GUARD_H], 52 | [AT_SETUP([Invalid CPP guards: $1]) 53 | 54 | # Possibly create inner directories. 55 | dirname=`AS_DIRNAME([$1])` 56 | AS_MKDIR_P([$dirname]) 57 | 58 | AT_DATA_GRAMMAR([$1.y], 59 | [%{ 60 | #include <$1.h> 61 | void yyerror (const char *); 62 | int yylex (void); 63 | %} 64 | %% 65 | dummy:; 66 | %% 67 | #include <$1.h> 68 | ]) 69 | 70 | AT_BISON_CHECK([--defines=$1.h --output=y.tab.c $1.y]) 71 | 72 | AT_COMPILE([y.tab.o], [-I. -c y.tab.c]) 73 | 74 | AT_CLEANUP 75 | ]) 76 | 77 | AT_TEST_CPP_GUARD_H([input/input]) 78 | AT_TEST_CPP_GUARD_H([9foo]) 79 | 80 | 81 | 82 | ## ---------------- ## 83 | ## export YYLTYPE. ## 84 | ## ---------------- ## 85 | 86 | 87 | AT_SETUP([export YYLTYPE]) 88 | 89 | AT_DATA_GRAMMAR([input.y], 90 | [%locations 91 | 92 | %name-prefix "my_" 93 | %{ 94 | #include 95 | #include 96 | 97 | static int 98 | my_lex (void) 99 | { 100 | return EOF; 101 | } 102 | 103 | static void 104 | my_error (const char *msg) 105 | { 106 | fprintf (stderr, "%s\n", msg); 107 | } 108 | 109 | %} 110 | %% 111 | exp:; 112 | ]) 113 | 114 | AT_BISON_CHECK([--defines -o input.c input.y]) 115 | 116 | # YYLTYPE should be defined, and MY_LLOC declared. 117 | AT_DATA([caller.c], 118 | [[#include "input.h" 119 | YYLTYPE *my_llocp = &my_lloc; 120 | 121 | int my_parse (void); 122 | 123 | int 124 | main (void) 125 | { 126 | return my_parse (); 127 | } 128 | ]]) 129 | 130 | # Link and execute, just to make sure everything is fine (and in 131 | # particular, that MY_LLOC is indeed defined somewhere). 132 | AT_COMPILE([caller.o], [-c caller.c]) 133 | AT_COMPILE([input.o], [-c input.c]) 134 | AT_COMPILE([caller], [caller.o input.o]) 135 | AT_PARSER_CHECK([./caller]) 136 | 137 | AT_CLEANUP 138 | -------------------------------------------------------------------------------- /tests/push.at: -------------------------------------------------------------------------------- 1 | # Checking Push Parsing. -*- Autotest -*- 2 | 3 | # Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc. 4 | 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | AT_BANNER([[Push Parsing Tests]]) 19 | 20 | ## -------------------------------- ## 21 | ## Memory Leak for Early Deletion. ## 22 | ## -------------------------------- ## 23 | 24 | AT_SETUP([[Memory Leak for Early Deletion]]) 25 | 26 | # Requires Valgrind. 27 | 28 | AT_DATA_GRAMMAR([[input.y]], 29 | [[ 30 | %{ 31 | #include 32 | #include 33 | #define YYINITDEPTH 1 34 | void yyerror (char const *msg); 35 | %} 36 | 37 | %define api.pure %define api.push-pull push 38 | 39 | %% 40 | 41 | start: 'a' 'b' 'c' ; 42 | 43 | %% 44 | 45 | void 46 | yyerror (char const *msg) 47 | { 48 | fprintf (stderr, "%s\n", msg); 49 | } 50 | 51 | int 52 | main (void) 53 | { 54 | yypstate *ps; 55 | 56 | /* Make sure we don't try to free ps->yyss in this case. */ 57 | ps = yypstate_new (); 58 | yypstate_delete (ps); 59 | 60 | /* yypstate_delete used to leak ps->yyss if the stack was reallocated but the 61 | parse did not return on success, syntax error, or memory exhaustion. */ 62 | ps = yypstate_new (); 63 | assert (yypush_parse (ps, 'a', NULL) == YYPUSH_MORE); 64 | yypstate_delete (ps); 65 | 66 | ps = yypstate_new (); 67 | assert (yypush_parse (ps, 'a', NULL) == YYPUSH_MORE); 68 | assert (yypush_parse (ps, 'b', NULL) == YYPUSH_MORE); 69 | yypstate_delete (ps); 70 | 71 | return 0; 72 | } 73 | ]]) 74 | 75 | AT_BISON_CHECK([[-o input.c input.y]]) 76 | AT_COMPILE([[input]]) 77 | AT_PARSER_CHECK([[./input]]) 78 | 79 | AT_CLEANUP 80 | 81 | ## --------------------------- ## 82 | ## Multiple impure instances. ## 83 | ## --------------------------- ## 84 | 85 | AT_SETUP([[Multiple impure instances]]) 86 | 87 | m4_pushdef([AT_MULTIPLE_IMPURE_INSTANCES_CHECK], [ 88 | AT_DATA_GRAMMAR([[input.y]], 89 | [[ 90 | %{ 91 | #include 92 | #include 93 | void yyerror (char const *msg); 94 | int yylex (void); 95 | %} 96 | 97 | %define api.push-pull ]$1[ 98 | 99 | %% 100 | 101 | start: ; 102 | 103 | %% 104 | 105 | void 106 | yyerror (char const *msg) 107 | { 108 | fprintf (stderr, "%s\n", msg); 109 | } 110 | 111 | int 112 | yylex (void) 113 | { 114 | return 0; 115 | } 116 | 117 | int 118 | main (void) 119 | { 120 | yypstate *ps; 121 | int i; 122 | 123 | for (i = 0; i < 2; ++i) 124 | { 125 | ps = yypstate_new (); 126 | assert (ps); 127 | assert (yypstate_new () == NULL); 128 | ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[; 129 | yychar = 0; 130 | assert (yypush_parse (ps) == 0); 131 | assert (yypstate_new () == NULL); 132 | ]m4_if([$1], [[both]], [[assert (yyparse () == 2)]])[; 133 | yypstate_delete (ps); 134 | } 135 | 136 | return 0; 137 | } 138 | ]]) 139 | 140 | AT_BISON_CHECK([[-o input.c input.y]]) 141 | AT_COMPILE([[input]]) 142 | AT_PARSER_CHECK([[./input]]) 143 | ]) 144 | 145 | AT_MULTIPLE_IMPURE_INSTANCES_CHECK([[both]]) 146 | AT_MULTIPLE_IMPURE_INSTANCES_CHECK([[push]]) 147 | 148 | m4_popdef([AT_MULTIPLE_IMPURE_INSTANCES_CHECK]) 149 | 150 | AT_CLEANUP 151 | 152 | ## ----------------------- ## 153 | ## Unsupported Skeletons. ## 154 | ## ----------------------- ## 155 | 156 | AT_SETUP([[Unsupported Skeletons]]) 157 | 158 | AT_DATA([[input.y]], 159 | [[%glr-parser 160 | %define api.push-pull push 161 | %% 162 | start: ; 163 | ]]) 164 | 165 | AT_BISON_CHECK([[input.y]], [[1]], [], 166 | [[input.y:2.9-21: %define variable 'api.push-pull' is not used 167 | ]]) 168 | 169 | AT_CLEANUP 170 | -------------------------------------------------------------------------------- /tests/testsuite.at: -------------------------------------------------------------------------------- 1 | # Test suite for GNU Bison. -*- Autotest -*- 2 | 3 | # Copyright (C) 2000-2004, 2006-2007, 2009-2012 Free Software 4 | # Foundation, Inc. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | 20 | # Testing resistance to user bugs. 21 | m4_include([input.at]) 22 | 23 | # Testing named references. 24 | m4_include([named-refs.at]) 25 | 26 | # Testing output file names. 27 | m4_include([output.at]) 28 | 29 | # Testing skeleton support. 30 | m4_include([skeletons.at]) 31 | 32 | # Testing the part of the engine that computes FOLLOW etc. 33 | m4_include([sets.at]) 34 | 35 | # Testing grammar reduction. 36 | m4_include([reduce.at]) 37 | 38 | # Testing that #lines are correct. 39 | m4_include([synclines.at]) 40 | 41 | # Testing that headers are sane. 42 | m4_include([headers.at]) 43 | 44 | # Testing that user actions are properly performed. 45 | m4_include([actions.at]) 46 | 47 | # Testing conflicts detection and resolution. 48 | m4_include([conflicts.at]) 49 | 50 | # Fulling testing (compilation and execution of the parser) on calc. 51 | m4_include([calc.at]) 52 | 53 | # Huge artificial grammars. 54 | # Torturing the stack expansion at runtime. 55 | m4_include([torture.at]) 56 | 57 | # Checking big, real world grammars. 58 | m4_include([existing.at]) 59 | 60 | # Some old bugs. 61 | m4_include([regression.at]) 62 | 63 | # Some C++ specific tests. 64 | m4_include([c++.at]) 65 | 66 | # And some Java specific tests. 67 | m4_include([java.at]) 68 | 69 | # And some PHP specific tests. 70 | m4_include([php.at]) 71 | 72 | # GLR tests: 73 | # C++ types, simplified 74 | m4_include([cxx-type.at]) 75 | # Regression tests 76 | m4_include([glr-regression.at]) 77 | 78 | # Push parsing specific tests. 79 | m4_include([push.at]) 80 | --------------------------------------------------------------------------------