From 4fe4fab1ca93f493849b4453a9e1f13b70305fc0 Mon Sep 17 00:00:00 2001 From: Alex Zhondin Date: Wed, 6 Feb 2019 02:07:12 -0700 Subject: [PATCH 1/5] migrate to bison 3.3.1 --- bison/data/README | 124 +- bison/data/local.mk | 47 +- bison/data/skeletons/README-D.txt | 60 + bison/data/{ => skeletons}/bison.m4 | 209 +-- bison/data/{ => skeletons}/c++-skel.m4 | 10 +- bison/data/{ => skeletons}/c++.m4 | 326 ++-- bison/data/{ => skeletons}/c-like.m4 | 31 +- bison/data/{ => skeletons}/c-skel.m4 | 10 +- bison/data/{ => skeletons}/c.m4 | 130 +- bison/data/skeletons/d-skel.m4 | 26 + bison/data/skeletons/d.m4 | 320 ++++ bison/data/{ => skeletons}/glr.c | 339 ++-- bison/data/{ => skeletons}/glr.cc | 132 +- bison/data/{ => skeletons}/java-skel.m4 | 5 +- bison/data/{ => skeletons}/java.m4 | 93 +- bison/data/{ => skeletons}/lalr1.cc | 380 +++-- bison/data/skeletons/lalr1.d | 897 +++++++++++ bison/data/{ => skeletons}/lalr1.java | 52 +- bison/data/{ => skeletons}/location.cc | 117 +- bison/data/skeletons/stack.hh | 163 ++ bison/data/skeletons/variant.hh | 453 ++++++ bison/data/{ => skeletons}/yacc.c | 240 +-- bison/data/stack.hh | 153 -- bison/data/variant.hh | 363 ----- bison/data/xslt/bison.xsl | 2 +- bison/data/xslt/xml2dot.xsl | 6 +- bison/data/xslt/xml2text.xsl | 2 +- bison/data/xslt/xml2xhtml.xsl | 3 +- bison/src/AnnotationList.c | 151 +- bison/src/AnnotationList.h | 2 +- bison/src/InadequacyList.c | 2 +- bison/src/InadequacyList.h | 2 +- bison/src/LR0.c | 42 +- bison/src/LR0.h | 2 +- bison/src/Sbitset.c | 2 +- bison/src/Sbitset.h | 2 +- bison/src/assoc.c | 2 +- bison/src/assoc.h | 4 +- bison/src/closure.c | 8 +- bison/src/closure.h | 2 +- bison/src/complain.c | 61 +- bison/src/complain.h | 13 +- bison/src/config.h | 8 +- bison/src/conflicts.c | 150 +- bison/src/conflicts.h | 5 +- bison/src/derives.c | 10 +- bison/src/derives.h | 4 +- bison/src/files.c | 67 +- bison/src/files.h | 9 +- bison/src/fixits.c | 212 +++ bison/src/fixits.h | 35 + bison/src/flex-scanner.h | 43 +- bison/src/getargs.c | 48 +- bison/src/getargs.h | 15 +- bison/src/gram.c | 66 +- bison/src/gram.h | 13 +- bison/src/graphviz.c | 71 +- bison/src/graphviz.h | 3 +- bison/src/ielr.c | 60 +- bison/src/ielr.h | 2 +- bison/src/lalr.c | 142 +- bison/src/lalr.h | 2 +- bison/src/location.c | 14 +- bison/src/location.h | 8 +- bison/src/main.c | 130 +- bison/src/muscle-tab.c | 223 +-- bison/src/muscle-tab.h | 6 +- bison/src/named-ref.c | 2 +- bison/src/named-ref.h | 2 +- bison/src/nullable.c | 4 +- bison/src/nullable.h | 4 +- bison/src/output.c | 220 +-- bison/src/output.h | 6 +- bison/src/parse-gram.c | 1872 ++++++++++++++--------- bison/src/parse-gram.h | 135 +- bison/src/parse-gram.y | 524 ++++--- bison/src/print-xml.c | 3 +- bison/src/print-xml.h | 3 +- bison/src/print.c | 105 +- bison/src/print.h | 3 +- bison/src/print_graph.c | 20 +- bison/src/print_graph.h | 4 +- bison/src/reader.c | 183 ++- bison/src/reader.h | 10 +- bison/src/reduce.c | 91 +- bison/src/reduce.h | 2 +- bison/src/relation.c | 2 +- bison/src/relation.h | 4 +- bison/src/scan-code.c | 220 ++- bison/src/scan-code.h | 6 +- bison/src/scan-code.l | 220 ++- bison/src/scan-gram.c | 1461 +++++++++--------- bison/src/scan-gram.h | 4 +- bison/src/scan-gram.l | 223 +-- bison/src/scan-skel.c | 99 +- bison/src/scan-skel.h | 4 +- bison/src/scan-skel.l | 27 +- bison/src/state.c | 6 +- bison/src/state.h | 14 +- bison/src/symlist.c | 16 +- bison/src/symlist.h | 12 +- bison/src/symtab.c | 142 +- bison/src/symtab.h | 19 +- bison/src/system.h | 6 +- bison/src/tables.c | 234 ++- bison/src/tables.h | 4 +- bison/src/uniqstr.c | 67 +- bison/src/uniqstr.h | 52 +- bison/src/yacc.in | 25 + common/m4/lib/gl_array_list.c | 680 ++++++++ common/m4/lib/gl_array_list.h | 34 + common/misc/arg-nonnull.h | 26 + common/misc/bbitset.h | 38 +- common/misc/bitset.c | 24 +- common/misc/bitset.h | 73 +- common/misc/bitset_stats.c | 146 +- common/misc/bitset_stats.h | 3 +- common/misc/concat-filename.c | 73 + common/misc/concat-filename.h | 41 + common/misc/config.h | 22 +- common/misc/ebitset.c | 703 +++++---- common/misc/ebitset.h | 3 +- common/misc/filename.h | 54 + common/misc/gethrxtime.c | 74 + common/misc/gethrxtime.h | 55 + common/misc/libiberty.h | 37 + common/misc/path-join.c | 37 + common/misc/path-join.h | 38 + common/misc/relocatable.c | 588 +++++++ common/misc/relocatable.h | 101 ++ common/misc/timespec.c | 3 + common/misc/timespec.h | 136 ++ common/misc/timevar.c | 418 ++--- common/misc/timevar.def | 49 +- common/misc/timevar.h | 90 +- common/misc/xtime.c | 3 + common/misc/xtime.h | 108 ++ 137 files changed, 10421 insertions(+), 5630 deletions(-) create mode 100644 bison/data/skeletons/README-D.txt rename bison/data/{ => skeletons}/bison.m4 (88%) rename bison/data/{ => skeletons}/c++-skel.m4 (72%) rename bison/data/{ => skeletons}/c++.m4 (68%) rename bison/data/{ => skeletons}/c-like.m4 (66%) rename bison/data/{ => skeletons}/c-skel.m4 (73%) rename bison/data/{ => skeletons}/c.m4 (89%) create mode 100644 bison/data/skeletons/d-skel.m4 create mode 100644 bison/data/skeletons/d.m4 rename bison/data/{ => skeletons}/glr.c (91%) rename bison/data/{ => skeletons}/glr.cc (76%) rename bison/data/{ => skeletons}/java-skel.m4 (87%) rename bison/data/{ => skeletons}/java.m4 (79%) rename bison/data/{ => skeletons}/lalr1.cc (77%) create mode 100644 bison/data/skeletons/lalr1.d rename bison/data/{ => skeletons}/lalr1.java (95%) rename bison/data/{ => skeletons}/location.cc (75%) create mode 100644 bison/data/skeletons/stack.hh create mode 100644 bison/data/skeletons/variant.hh rename bison/data/{ => skeletons}/yacc.c (92%) delete mode 100644 bison/data/stack.hh delete mode 100644 bison/data/variant.hh create mode 100644 bison/src/fixits.c create mode 100644 bison/src/fixits.h create mode 100644 bison/src/yacc.in create mode 100644 common/m4/lib/gl_array_list.c create mode 100644 common/m4/lib/gl_array_list.h create mode 100644 common/misc/arg-nonnull.h create mode 100644 common/misc/concat-filename.c create mode 100644 common/misc/concat-filename.h create mode 100644 common/misc/filename.h create mode 100644 common/misc/gethrxtime.c create mode 100644 common/misc/gethrxtime.h create mode 100644 common/misc/libiberty.h create mode 100644 common/misc/path-join.c create mode 100644 common/misc/path-join.h create mode 100644 common/misc/relocatable.c create mode 100644 common/misc/relocatable.h create mode 100644 common/misc/timespec.c create mode 100644 common/misc/timespec.h create mode 100644 common/misc/xtime.c create mode 100644 common/misc/xtime.h diff --git a/bison/data/README b/bison/data/README index 798750f..1a2e71c 100644 --- a/bison/data/README +++ b/bison/data/README @@ -1,8 +1,9 @@ This directory contains data needed by Bison. -* Skeletons -Bison skeletons: the general shapes of the different parser kinds, -that are specialized for specific grammars by the bison program. +# Directory content +## Skeletons +Bison skeletons: the general shapes of the different parser kinds, that are +specialized for specific grammars by the bison program. Currently, the supported skeletons are: @@ -22,19 +23,18 @@ Currently, the supported skeletons are: - glr.cc A Generalized LR C++ parser. Actually a C++ wrapper around glr.c. -These skeletons are the only ones supported by the Bison team. -Because the interface between skeletons and the bison program is not -finished, *we are not bound to it*. In particular, Bison is not -mature enough for us to consider that "foreign skeletons" are -supported. +These skeletons are the only ones supported by the Bison team. Because the +interface between skeletons and the bison program is not finished, *we are +not bound to it*. In particular, Bison is not mature enough for us to +consider that "foreign skeletons" are supported. -* m4sugar -This directory contains M4sugar, sort of an extended library for M4, -which is used by Bison to instantiate the skeletons. +## m4sugar +This directory contains M4sugar, sort of an extended library for M4, which +is used by Bison to instantiate the skeletons. -* xslt -This directory contains XSLT programs that transform Bison's XML output -into various formats. +## xslt +This directory contains XSLT programs that transform Bison's XML output into +various formats. - bison.xsl A library of routines used by the other XSLT programs. @@ -48,13 +48,105 @@ into various formats. - xml2xhtml.xsl Conversion into XHTML. +# Implementation note about the skeletons + +"Skeleton" in Bison parlance means "backend": a skeleton is fed by the bison +executable with LR tables, facts about the symbols, etc. and they generate +the output (say parser.cc, parser.hh, location.hh, etc.). They are only in +charge of generating the parser and its auxiliary files, they do not +generate the XML output, the parser.output reports, nor the graphical +rendering. + +The bits of information passing from bison to the backend is named +"muscles". Muscles are passed to M4 via its standard input: it's a set of +m4 definitions. To see them, use `--trace=muscles`. + +Except for muscles, whose names are generated by bison, the skeletons have +no constraint at all on the macro names: there is no technical/theoretical +limitation, as long as you generate the output, you can do what you want. +However, of course, that would be a bad idea if, say, the C and C++ +skeletons used different approaches and had completely different +implementations. That would be a maintenance nightmare. + +Below, we document some of the macros that we use in several of the +skeletons. If you are to write a new skeleton, please, implement them for +your language. Overall, be sure to follow the same patterns as the existing +skeletons. + +## Symbols + +In order to unify the handling of the various aspects of symbols (tag, type +name, whether terminal, etc.), bison.exe defines one macro per (token, +field), where field can `has_id`, `id`, etc.: see +src/output.c:prepare_symbols_definitions(). + +The various FIELDS are: + +- has_id: 0 or 1. + Whether the symbol has an id. +- id: string + If has_id, the id. Guaranteed to be usable as a C identifier. + Prefixed by api.token.prefix if defined. +- tag: string. + A representation of the symbol. Can be 'foo', 'foo.id', '"foo"' etc. +- user_number: integer + The external number as used by yylex. Can be ASCII code when a character, + some number chosen by bison, or some user number in the case of + %token FOO . Corresponds to yychar in yacc.c. +- is_token: 0 or 1 + Whether this is a terminal symbol. +- number: integer + The internal number (computed from the external number by yytranslate). + Corresponds to yytoken in yacc.c. This is the same number that serves as + key in b4_symbol(NUM, FIELD). +- has_type: 0, 1 + Whether has a semantic value. +- type_tag: string + When api.value.type=union, the generated name for the union member. + yytype_INT etc. for symbols that has_id, otherwise yytype_1 etc. +- type + If it has a semantic value, its type tag, or, if variant are used, + its type. + In the case of api.value.type=union, type is the real type (e.g. int). +- has_printer: 0, 1 +- printer: string +- printer_file: string +- printer_line: integer + If the symbol has a printer, everything about it. +- has_destructor, destructor, destructor_file, destructor_line + Likewise. + +### b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG]) +Expansion of $$, $1, $3, etc. + +The semantic value from a given VAL. +- `VAL`: some semantic value storage (typically a union). e.g., `yylval` +- `SYMBOL-NUM`: the symbol number from which we extract the type tag. +- `TYPE-TAG`, the user forced the ``. + +The result can be used safely, it is put in parens to avoid nasty precedence +issues. + +### b4_lhs_value(SYMBOL-NUM, [TYPE]) +Expansion of `$$` or `$$`, for symbol `SYMBOL-NUM`. + +### b4_rhs_data(RULE-LENGTH, POS) +The data corresponding to the symbol `#POS`, where the current rule has +`RULE-LENGTH` symbols on RHS. + +### b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) +Expansion of `$POS`, where the current rule has `RULE-LENGTH` symbols +on RHS. + ----- Local Variables: -mode: outline +mode: markdown +fill-column: 76 +ispell-dictionary: "american" End: -Copyright (C) 2002, 2008-2015, 2018 Free Software Foundation, Inc. +Copyright (C) 2002, 2008-2015, 2018-2019 Free Software Foundation, Inc. This file is part of GNU Bison. diff --git a/bison/data/local.mk b/bison/data/local.mk index ea097aa..f38e822 100644 --- a/bison/data/local.mk +++ b/bison/data/local.mk @@ -1,4 +1,5 @@ -## Copyright (C) 2002, 2005-2015, 2018 Free Software Foundation, Inc. +## Copyright (C) 2002, 2005-2015, 2018-2019 Free Software Foundation, +## Inc. ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -14,23 +15,33 @@ ## along with this program. If not, see . dist_pkgdata_DATA = \ - data/README \ - data/bison.m4 \ - data/c++-skel.m4 \ - data/c++.m4 \ - data/c-like.m4 \ - data/c-skel.m4 \ - data/c.m4 \ - data/glr.c \ - data/glr.cc \ - data/java-skel.m4 \ - data/java.m4 \ - data/lalr1.cc \ - data/lalr1.java \ - data/location.cc \ - data/stack.hh \ - data/variant.hh \ - data/yacc.c + data/README + +skeletonsdir = $(pkgdatadir)/skeletons +dist_skeletons_DATA = \ + data/skeletons/bison.m4 \ + data/skeletons/c++-skel.m4 \ + data/skeletons/c++.m4 \ + data/skeletons/c-like.m4 \ + data/skeletons/c-skel.m4 \ + data/skeletons/c.m4 \ + data/skeletons/glr.c \ + data/skeletons/glr.cc \ + data/skeletons/java-skel.m4 \ + data/skeletons/java.m4 \ + data/skeletons/lalr1.cc \ + data/skeletons/lalr1.java \ + data/skeletons/location.cc \ + data/skeletons/stack.hh \ + data/skeletons/variant.hh \ + data/skeletons/yacc.c + +# Experimental support for the D language. +dist_skeletons_DATA += \ + data/skeletons/README-D.txt \ + data/skeletons/d-skel.m4 \ + data/skeletons/d.m4 \ + data/skeletons/lalr1.d m4sugardir = $(pkgdatadir)/m4sugar dist_m4sugar_DATA = \ diff --git a/bison/data/skeletons/README-D.txt b/bison/data/skeletons/README-D.txt new file mode 100644 index 0000000..214e309 --- /dev/null +++ b/bison/data/skeletons/README-D.txt @@ -0,0 +1,60 @@ +Some usage notes for the D Parser: + +- it is a port of the Java parser, so interface is very similar. + +- the lexer class needs to implement the interface 'Lexer' (similar to + java). It typically (depending on options) looks like this: + +public interface Lexer +{ + /** + * Method to retrieve the beginning position of the last scanned token. + * @return the position at which the last scanned token starts. */ + @property YYPosition startPos (); + + /** + * Method to retrieve the ending position of the last scanned token. + * @return the first position beyond the last scanned token. */ + @property YYPosition endPos (); + + /** + * Method to retrieve the semantic value of the last scanned token. + * @return the semantic value of the last scanned token. */ + @property YYSemanticType semanticVal (); + + /** + * Entry point for the scanner. Returns the token identifier corresponding + * to the next token and prepares to return the semantic value + * and beginning/ending positions of the token. + * @return the token identifier corresponding to the next token. */ + YYTokenType yylex (); + + /** + * Entry point for error reporting. Emits an error + * referring to the given location in a user-defined way. + * + * @param loc The location of the element to which the + * error message is related + * @param s The string for the error message. */ + void yyerror (YYLocation loc, string s); +} + +- semantic types are handled by D usions (same as for C/C++ parsers) + +- the following (non-standard) %defines are supported: + + %define package "" + %define api.parser.class "my_class_name>" + %define position_type "my_position_type" + %define location_type "my_location_type" + +- the following declarations basically work like in C/C++: + + %locations + %error-verbose + %parse-param + %initial-action + %code + %union + +- %destructor is not yet supported diff --git a/bison/data/bison.m4 b/bison/data/skeletons/bison.m4 similarity index 88% rename from bison/data/bison.m4 rename to bison/data/skeletons/bison.m4 index 80e025c..8a33a58 100644 --- a/bison/data/bison.m4 +++ b/bison/data/skeletons/bison.m4 @@ -2,7 +2,8 @@ # Language-independent M4 Macros for Bison. -# Copyright (C) 2002, 2004-2015, 2018 Free Software Foundation, Inc. +# Copyright (C) 2002, 2004-2015, 2018-2019 Free Software Foundation, +# Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,12 +23,17 @@ ## Identification. ## ## ---------------- ## +# b4_generated_by +# --------------- +m4_define([b4_generated_by], +[b4_comment([A Bison parser, made by GNU Bison b4_version.]) +]) + # b4_copyright(TITLE, [YEARS]) # ---------------------------- # If YEARS are not defined, use b4_copyright_years. m4_define([b4_copyright], -[b4_comment([A Bison parser, made by GNU Bison b4_version.]) - +[b4_generated_by b4_comment([$1 ]m4_dquote(m4_text_wrap([Copyright (C) @@ -58,26 +64,49 @@ Bison output files to be licensed under the GNU General Public License without this special exception. This special exception was added by the Free Software Foundation in -version 2.2 of Bison.])]) +version 2.2 of Bison.]) +]) + + +# b4_disclaimer +# ------------- +# Issue a warning about private implementation details. +m4_define([b4_disclaimer], +[b4_comment([Undocumented macros, especially those whose name start with YY_, +are private implementation details. Do not rely on them.]) +]) + + + +# b4_required_version_if(VERSION, IF_NEWER, IF_OLDER) +# --------------------------------------------------- +# If the version %require'd by the user is VERSION (or newer) expand +# IF_NEWER, otherwise IF_OLDER. VERSION should be an integer, e.g., +# 302 for 3.2. +m4_define([b4_required_version_if], +[m4_if(m4_eval($1 <= b4_required_version), + [1], [$2], [$3])]) ## -------- ## ## Output. ## ## -------- ## -# b4_output_begin(FILE) -# --------------------- +# b4_output_begin(FILE1, FILE2) +# ----------------------------- # Enable output, i.e., send to diversion 0, expand after "#", and # generate the tag to output into FILE. Must be followed by EOL. +# FILE is FILE1 concatenated to FILE2. FILE2 can be empty, or be +# absolute: do the right thing. m4_define([b4_output_begin], [m4_changecom() m4_divert_push(0)dnl -@output(m4_unquote([$1])@)@dnl +@output(m4_unquote([$1])@,m4_unquote([$2])@)@dnl ]) -# b4_output_end() -# --------------- +# b4_output_end +# ------------- # Output nothing, restore # as comment character (no expansions after #). m4_define([b4_output_end], [m4_divert_pop(0) @@ -235,8 +264,8 @@ m4_define([b4_subtract], # ------------------- # Join with comma, skipping empty arguments. # b4_join calls itself recursively until it sees the first non-empty -# argument, then calls _b4_join which prepends each non-empty argument -# with a comma. +# argument, then calls _b4_join (i.e., `_$0`) which prepends each +# non-empty argument with a comma. m4_define([b4_join], [m4_if([$#$1], [1], [], @@ -346,54 +375,25 @@ b4_define_flag_if([token_table]) # Whether yytoken_table is demanded. b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated. +# b4_glr_cc_if([IF-TRUE], [IF-FALSE]) +# ----------------------------------- +m4_define([b4_glr_cc_if], + [m4_if(b4_skeleton, ["glr.cc"], $@)]) + + ## --------- ## ## Symbols. ## ## --------- ## -# In order to unify the handling of the various aspects of symbols -# (tag, type_name, whether terminal, etc.), bison.exe defines one -# macro per (token, field), where field can has_id, id, etc.: see -# src/output.c:prepare_symbols_definitions(). +# For a description of the Symbol handling, see README. # -# The various FIELDS are: -# -# - has_id: 0 or 1. -# Whether the symbol has an id. -# - id: string -# If has_id, the id. Guaranteed to be usable as a C identifier. -# Prefixed by api.token.prefix if defined. -# - tag: string. -# A representat of the symbol. Can be 'foo', 'foo.id', '"foo"' etc. -# - user_number: integer -# The assigned (external) number as used by yylex. -# - is_token: 0 or 1 -# Whether this is a terminal symbol. -# - number: integer -# The internalized number (used after yytranslate). -# - has_type: 0, 1 -# Whether has a semantic value. -# - type_tag: string -# When api.value.type=union, the generated name for the union member. -# yytype_INT etc. for symbols that has_id, otherwise yytype_1 etc. -# - type -# If it has a semantic value, its type tag, or, if variant are used, -# its type. -# In the case of api.value.type=union, type is the real type (e.g. int). -# - has_printer: 0, 1 -# - printer: string -# - printer_file: string -# - printer_line: integer -# If the symbol has a printer, everything about it. -# - has_destructor, destructor, destructor_file, destructor_line -# Likewise. -# -# The following macros provide access to these values. +# The following macros provide access to symbol related values. -# b4_symbol_(NUM, FIELD) +# _b4_symbol(NUM, FIELD) # ---------------------- # Recover a FIELD about symbol #NUM. Thanks to m4_indir, fails if # undefined. -m4_define([b4_symbol_], +m4_define([_b4_symbol], [m4_indir([b4_symbol($1, $2)])]) @@ -404,8 +404,8 @@ m4_define([b4_symbol_], m4_define([b4_symbol], [m4_case([$2], [id], [m4_do([b4_percent_define_get([api.token.prefix])], - [b4_symbol_([$1], [id])])], - [b4_symbol_($@)])]) + [_b4_symbol([$1], [id])])], + [_b4_symbol($@)])]) # b4_symbol_if(NUM, FIELD, IF-TRUE, IF-FALSE) @@ -440,10 +440,10 @@ m4_define([b4_symbol_action_location], m4_define([b4_symbol_action], [b4_symbol_if([$1], [has_$2], [b4_dollar_pushdef([(*yyvaluep)], - b4_symbol_if([$1], [has_type], - [m4_dquote(b4_symbol([$1], [type]))]), + [$1], + [], [(*yylocationp)])dnl - b4_symbol_case_([$1])[]dnl + _b4_symbol_case([$1])[]dnl b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])]) b4_symbol([$1], [$2]) b4_syncline([@oline@], [@ofile@]) @@ -469,7 +469,7 @@ m4_define([b4_symbol_actions], m4_ifval(m4_defn([b4_actions_]), [switch (m4_default([$2], [yytype])) { - m4_defn([b4_actions_]) +m4_defn([b4_actions_])[]dnl default: break; }dnl @@ -478,10 +478,12 @@ m4_ifval(m4_defn([b4_actions_]), m4_popdef([b4_actions_])dnl ]) -# b4_symbol_case_(SYMBOL-NUM) +# _b4_symbol_case(SYMBOL-NUM) # --------------------------- -# Issue a "case NUM" for SYMBOL-NUM. -m4_define([b4_symbol_case_], +# Issue a "case NUM" for SYMBOL-NUM. Ends with its EOL to make it +# easier to use with m4_map, but then, use []dnl to suppress the last +# one. +m4_define([_b4_symbol_case], [case b4_symbol([$1], [number]): b4_symbol_tag_comment([$1])]) ]) @@ -536,16 +538,16 @@ m4_define([b4_token_format], ## Types. ## ## ------- ## -# b4_type_action_(NUMS) +# _b4_type_action(NUMS) # --------------------- # Run actions for the symbol NUMS that all have the same type-name. # Skip NUMS that have no type-name. # -# To specify the action to run, define b4_dollar_dollar(NUMBER, +# To specify the action to run, define b4_dollar_dollar(SYMBOL-NUM, # TAG, TYPE). -m4_define([b4_type_action_], +m4_define([_b4_type_action], [b4_symbol_if([$1], [has_type], -[m4_map([ b4_symbol_case_], [$@])[]dnl +[m4_map([ _b4_symbol_case], [$@])[]dnl b4_dollar_dollar([b4_symbol([$1], [number])], [b4_symbol([$1], [tag])], [b4_symbol([$1], [type])]); @@ -601,13 +603,15 @@ m4_define([b4_user_code], b4_syncline([@oline@], [@ofile@])]) -# b4_define_user_code(MACRO) -# -------------------------- -# From b4_MACRO, build b4_user_MACRO that includes the synclines. +# b4_define_user_code(MACRO, COMMENT) +# ----------------------------------- +# From b4_MACRO, if defined, build b4_user_MACRO that includes the synclines. m4_define([b4_define_user_code], [m4_define([b4_user_$1], -[b4_user_code([b4_$1])])]) - + [m4_ifdef([b4_$1], + [m4_ifval([$2], + [b4_comment([$2]) +])b4_user_code([b4_$1])])])]) # b4_user_actions # b4_user_initial_action @@ -617,9 +621,9 @@ m4_define([b4_define_user_code], # ---------------------- # Macros that issue user code, ending with synclines. b4_define_user_code([actions]) -b4_define_user_code([initial_action]) -b4_define_user_code([post_prologue]) -b4_define_user_code([pre_prologue]) +b4_define_user_code([initial_action], [User initialization code.]) +b4_define_user_code([post_prologue], [Second part of user prologue.]) +b4_define_user_code([pre_prologue], [First part of user prologue.]) b4_define_user_code([union_members]) @@ -701,7 +705,7 @@ m4_define([b4_percent_define_use], # b4_percent_define_get([[foo]]) m4_define([b4_percent_define_get], [b4_percent_define_use([$1])dnl -b4_percent_define_ifdef_([$1], +_b4_percent_define_ifdef([$1], [m4_indir([b4_percent_define(]$1[)])], [$2])]) @@ -710,7 +714,7 @@ b4_percent_define_ifdef_([$1], # Mimic muscle_percent_define_get_loc in ../src/muscle-tab.h exactly. That is, # if the %define variable VARIABLE is undefined, complain fatally since that's # a Bison or skeleton error. Otherwise, return its definition location in a -# form approriate for the first two arguments of b4_warn_at, b4_complain_at, or +# form appropriate for the first two arguments of b4_warn_at, b4_complain_at, or # b4_fatal_at. Don't record this as a Bison usage of VARIABLE as there's no # reason to suspect that the user-supplied value has yet influenced the output. # @@ -755,15 +759,15 @@ m4_define([b4_percent_define_get_syncline], [m4_indir([b4_percent_define_syncline(]$1[)])], [b4_fatal([[$0: undefined %%define variable '%s']], [$1])])]) -# b4_percent_define_ifdef_(VARIABLE, IF-TRUE, [IF-FALSE]) +# _b4_percent_define_ifdef(VARIABLE, IF-TRUE, [IF-FALSE]) # ------------------------------------------------------ # If the %define variable VARIABLE is defined, expand IF-TRUE, else expand # IF-FALSE. Don't record usage of VARIABLE. # # For example: # -# b4_percent_define_ifdef_([[foo]], [[it's defined]], [[it's undefined]]) -m4_define([b4_percent_define_ifdef_], +# _b4_percent_define_ifdef([[foo]], [[it's defined]], [[it's undefined]]) +m4_define([_b4_percent_define_ifdef], [m4_ifdef([b4_percent_define(]$1[)], [$2], [$3])]) @@ -779,11 +783,44 @@ m4_define([b4_percent_define_ifdef_], # # b4_percent_define_ifdef([[foo]], [[it's defined]], [[it's undefined]]) m4_define([b4_percent_define_ifdef], -[b4_percent_define_ifdef_([$1], +[_b4_percent_define_ifdef([$1], [b4_percent_define_use([$1])$2], [$3])]) +# b4_percent_define_check_file_complain(VARIABLE) +# ----------------------------------------------- +# Warn about %define variable VARIABLE having an incorrect +# value. +m4_define([b4_percent_define_check_file_complain], +[b4_complain_at(b4_percent_define_get_loc([$1]), + [[%%define variable '%s' requires 'none' or '"..."' values]], + [$1])]) + + +# b4_percent_define_check_file(MACRO, VARIABLE, DEFAULT) +# ------------------------------------------------------ +# If the %define variable VARIABLE: +# - is undefined, then if DEFAULT is non-empty, define MACRO to DEFAULT +# - is a string, define MACRO to its value +# - is the keyword 'none', do nothing +# - otherwise, warn about the incorrect value. +m4_define([b4_percent_define_check_file], +[b4_percent_define_ifdef([$2], + [m4_case(b4_percent_define_get_kind([$2]), + [string], + [m4_define([$1], b4_percent_define_get([$2]))], + [keyword], + [m4_if(b4_percent_define_get([$2]), [none], [], + [b4_percent_define_check_file_complain([$2])])], + [b4_percent_define_check_file_complain([$2])]) + ], + [m4_ifval([$3], + [m4_define([$1], [$3])])]) +]) + + + ## --------- ## ## Options. ## ## --------- ## @@ -824,7 +861,7 @@ m4_define([b4_percent_define_flag_if], # # b4_percent_define_default([[foo]], [[default value]]) m4_define([b4_percent_define_default], -[b4_percent_define_ifdef_([$1], [], +[_b4_percent_define_ifdef([$1], [], [m4_define([b4_percent_define(]$1[)], [$2])dnl m4_define([b4_percent_define_kind(]$1[)], [m4_default([$3], [keyword])])dnl @@ -839,26 +876,26 @@ m4_define([b4_percent_define_default], # Define b4_NAME_if that executes its $1 or $2 depending whether # VARIABLE was %defined. The characters '.' and `-' in VARIABLE are mapped # to '_'. -m4_define([b4_percent_define_if_define_], +m4_define([_b4_percent_define_if_define], [m4_define(m4_bpatsubst([b4_$1_if], [[-.]], [_]), [b4_percent_define_flag_if(m4_default([$2], [$1]), [$3], [$4])])]) m4_define([b4_percent_define_if_define], [b4_percent_define_default([m4_default([$2], [$1])], [[false]]) -b4_percent_define_if_define_([$1], [$2], $[1], $[2])]) +_b4_percent_define_if_define([$1], [$2], $[1], $[2])]) # b4_percent_define_check_kind(VARIABLE, KIND, [DIAGNOSTIC = complain]) # --------------------------------------------------------------------- m4_define([b4_percent_define_check_kind], -[b4_percent_define_ifdef_([$1], +[_b4_percent_define_ifdef([$1], [m4_if(b4_percent_define_get_kind([$1]), [$2], [], [b4_error([m4_default([$3], [complain])], b4_percent_define_get_loc([$1]), [m4_case([$2], - [code], [[%%define variable '%s' requires '{...}' values]], + [code], [[%%define variable '%s' requires '{...}' values]], [keyword], [[%%define variable '%s' requires keyword values]], - [string], [[%%define variable '%s' requires '"..."' values]])], + [string], [[%%define variable '%s' requires '"..."' values]])], [$1])])])dnl ]) @@ -884,7 +921,7 @@ m4_define([b4_percent_define_check_values], [_b4_percent_define_check_values(b4_sublist)])]) m4_define([_b4_percent_define_check_values], -[b4_percent_define_ifdef_([$1], +[_b4_percent_define_ifdef([$1], [b4_percent_define_check_kind(]$1[, [keyword], [deprecated])dnl m4_pushdef([b4_good_value], [0])dnl m4_if($#, 1, [], @@ -946,7 +983,7 @@ m4_define([b4_percent_code_ifdef], # b4_parse_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT]) # b4_parse_trace_if([IF-DEBUG-TRACES-ARE-ENABLED], [IF-NOT]) # b4_token_ctor_if([IF-YYLEX-RETURNS-A-TOKEN], [IF-NOT]) -# ---------------------------------------------- +# ---------------------------------------------------------- b4_percent_define_if_define([token_ctor], [api.token.constructor]) b4_percent_define_if_define([locations]) # Whether locations are tracked. b4_percent_define_if_define([parse.assert]) @@ -1011,8 +1048,6 @@ b4_check_user_names_wrap([[code]], [[qualifier]]) ## ---------------- ## # m4_define_default([b4_lex_param], []) dnl breaks other skeletons -m4_define_default([b4_pre_prologue], []) -m4_define_default([b4_post_prologue], []) m4_define_default([b4_epilogue], []) m4_define_default([b4_parse_param], []) diff --git a/bison/data/c++-skel.m4 b/bison/data/skeletons/c++-skel.m4 similarity index 72% rename from bison/data/c++-skel.m4 rename to bison/data/skeletons/c++-skel.m4 index 3cd5678..1c3721c 100644 --- a/bison/data/c++-skel.m4 +++ b/bison/data/skeletons/c++-skel.m4 @@ -2,8 +2,8 @@ # C++ skeleton dispatching for Bison. -# Copyright (C) 2006-2007, 2009-2015, 2018 Free Software Foundation, -# Inc. +# Copyright (C) 2006-2007, 2009-2015, 2018-2019 Free Software +# Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,10 +18,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -b4_glr_if( [m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.cc]])]) -b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.cc]])]) +b4_glr_if( [m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.cc]])]) +b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.cc]])]) -m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[lalr1.cc]]) +m4_define_default([b4_used_skeleton], [b4_skeletonsdir/[lalr1.cc]]) m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) m4_include(b4_used_skeleton) diff --git a/bison/data/c++.m4 b/bison/data/skeletons/c++.m4 similarity index 68% rename from bison/data/c++.m4 rename to bison/data/skeletons/c++.m4 index 396d861..35008f3 100644 --- a/bison/data/c++.m4 +++ b/bison/data/skeletons/c++.m4 @@ -2,7 +2,7 @@ # C++ skeleton for Bison -# Copyright (C) 2002-2018 Free Software Foundation, Inc. +# Copyright (C) 2002-2019 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,13 +22,22 @@ b4_percent_define_ifdef([[api.value.union.name]], [b4_complain_at(b4_percent_define_get_loc([[api.value.union.name]]), [named %union is invalid in C++])]) -m4_include(b4_pkgdatadir/[c.m4]) +m4_include(b4_skeletonsdir/[c.m4]) + +b4_percent_define_check_kind([api.namespace], [code], [deprecated]) +b4_percent_define_check_kind([api.parser.class], [code], [deprecated]) + + +## ----- ## +## C++. ## +## ----- ## # b4_comment(TEXT, [PREFIX]) # -------------------------- # Put TEXT in comment. Prefix all the output lines with PREFIX. m4_define([b4_comment], -[b4_comment_([$1], [$2// ], [$2// ])]) +[_b4_comment([$1], [$2// ], [$2// ])]) + # b4_inline(hh|cc) # ---------------- @@ -40,18 +49,54 @@ m4_define([b4_inline], ]], [m4_fatal([$0: invalid argument: $1])])]) -## -------- ## -## Checks. ## -## -------- ## -b4_percent_define_check_kind([api.namespace], [code], [deprecated]) -b4_percent_define_check_kind([parser_class_name], [code], [deprecated]) +# b4_cxx_portability +# ------------------ +m4_define([b4_cxx_portability], +[#if defined __cplusplus +# define YY_CPLUSPLUS __cplusplus +#else +# define YY_CPLUSPLUS 199711L +#endif + +// Support move semantics when possible. +#if 201103L <= YY_CPLUSPLUS +# define YY_MOVE std::move +# define YY_MOVE_OR_COPY move +# define YY_MOVE_REF(Type) Type&& +# define YY_RVREF(Type) Type&& +# define YY_COPY(Type) Type +#else +# define YY_MOVE +# define YY_MOVE_OR_COPY copy +# define YY_MOVE_REF(Type) Type& +# define YY_RVREF(Type) const Type& +# define YY_COPY(Type) const Type& +#endif + +// Support noexcept when possible. +#if 201103L <= YY_CPLUSPLUS +# define YY_NOEXCEPT noexcept +# define YY_NOTHROW +#else +# define YY_NOEXCEPT +# define YY_NOTHROW throw () +#endif + +// Support constexpr when possible. +#if 201703 <= YY_CPLUSPLUS +# define YY_CONSTEXPR constexpr +#else +# define YY_CONSTEXPR +#endif[]dnl +]) + ## ---------------- ## ## Default values. ## ## ---------------- ## -b4_percent_define_default([[parser_class_name]], [[parser]]) +b4_percent_define_default([[api.parser.class]], [[parser]]) # Don't do that so that we remember whether we're using a user # request, or the default value. @@ -88,7 +133,7 @@ m4_if(m4_bregexp(b4_namespace_ref, [^[ ]*$]), [-1], [], [[namespace reference is empty]])]) # Instead of assuming the C++ compiler will do it, Bison should reject any -# invalid b4_namepsace_ref that would be converted to a valid +# invalid b4_namespace_ref that would be converted to a valid # b4_namespace_open. The problem is that Bison doesn't always output # b4_namespace_ref to uncommented code but should reserve the ability to do so # in future releases without risking breaking any existing user grammars. @@ -171,7 +216,18 @@ m4_define([b4_public_types_declare], /// Syntax errors thrown from user actions. struct syntax_error : std::runtime_error { - syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m);]b4_locations_if([ + syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m) + : std::runtime_error (m)]b4_locations_if([ + , location (l)])[ + {} + + syntax_error (const syntax_error& s) + : std::runtime_error (s.what ())]b4_locations_if([ + , location (s.location)])[ + {} + + ~syntax_error () YY_NOEXCEPT YY_NOTHROW;]b4_locations_if([ + location_type location;])[ }; @@ -192,11 +248,18 @@ m4_define([b4_public_types_declare], /// Internal symbol number for tokens (subsumed by symbol_number_type). typedef ]b4_int_type_for([b4_translate])[ token_number_type; +]]) - /// A complete symbol. + +# b4_symbol_type_define +# --------------------- +# Define symbol_type, the external type for symbols used for symbol +# constructors. +m4_define([b4_symbol_type_define], +[[ /// A complete symbol. /// /// Expects its Base type to provide access to the symbol type - /// via type_get(). + /// via type_get (). /// /// Provide access to semantic value]b4_locations_if([ and location])[. template @@ -206,30 +269,57 @@ m4_define([b4_public_types_declare], typedef Base super_type; /// Default constructor. - basic_symbol (); + basic_symbol () + : value ()]b4_locations_if([ + , location ()])[ + {} + +#if 201103L <= YY_CPLUSPLUS + /// Move constructor. + basic_symbol (basic_symbol&& that); +#endif /// Copy constructor. - basic_symbol (const basic_symbol& other); -]b4_variant_if([[ + basic_symbol (const basic_symbol& that);]b4_variant_if([[ + /// Constructor for valueless symbols, and symbols from each type. -]b4_type_foreach([b4_basic_symbol_constructor_declare])], [[ +]b4_type_foreach([b4_basic_symbol_constructor_define])], [[ /// Constructor for valueless symbols. basic_symbol (typename Base::kind_type t]b4_locations_if([, - const location_type& l])[);]])[ + YY_MOVE_REF (location_type) l])[); /// Constructor for symbols with semantic value. basic_symbol (typename Base::kind_type t, - const semantic_type& v]b4_locations_if([, - const location_type& l])[); - + YY_RVREF (semantic_type) v]b4_locations_if([, + YY_RVREF (location_type) l])[); +]])[ /// Destroy the symbol. - ~basic_symbol (); + ~basic_symbol () + { + clear (); + } /// Destroy contents, and record that is empty. - void clear (); + void clear () + {]b4_variant_if([[ + // User destructor. + symbol_number_type yytype = this->type_get (); + basic_symbol& yysym = *this; + (void) yysym; + switch (yytype) + { +]b4_symbol_foreach([b4_symbol_destructor])dnl +[ default: + break; + } + + // Type destructor. +]b4_symbol_variant([[yytype]], [[value]], [[template destroy]])])[ + Base::clear (); + } /// Whether empty. - bool empty () const; + bool empty () const YY_NOEXCEPT; /// Destructive move, \a s is emptied into this. void move (basic_symbol& s); @@ -241,8 +331,10 @@ m4_define([b4_public_types_declare], location_type location;])[ private: +#if YY_CPLUSPLUS < 201103L /// Assignment operator. - basic_symbol& operator= (const basic_symbol& other); + basic_symbol& operator= (const basic_symbol& that); +#endif }; /// Type access provider for token (enum) based symbols. @@ -251,8 +343,13 @@ m4_define([b4_public_types_declare], /// Default constructor. by_type (); +#if 201103L <= YY_CPLUSPLUS + /// Move constructor. + by_type (by_type&& that); +#endif + /// Copy constructor. - by_type (const by_type& other); + by_type (const by_type& that); /// The symbol type as needed by the constructor. typedef token_type kind_type; @@ -268,10 +365,10 @@ m4_define([b4_public_types_declare], /// The (internal) type number (corresponding to \a type). /// \a empty when empty. - symbol_number_type type_get () const; + symbol_number_type type_get () const YY_NOEXCEPT; /// The token. - token_type token () const; + token_type token () const YY_NOEXCEPT; /// The symbol type. /// \a empty_symbol when empty. @@ -280,140 +377,130 @@ m4_define([b4_public_types_declare], }; /// "External" symbols: returned by the scanner. - typedef basic_symbol symbol_type; + struct symbol_type : basic_symbol + {]b4_variant_if([[ + /// Superclass. + typedef basic_symbol super_type; + + /// Empty symbol. + symbol_type () {} -]b4_symbol_constructor_declare]) + /// Constructor for valueless symbols, and symbols from each type. +]b4_type_foreach([_b4_token_constructor_define])dnl + ])[}; +]]) # b4_public_types_define(hh|cc) # ----------------------------- # Provide the implementation needed by the public types. m4_define([b4_public_types_define], -[ b4_inline([$1])b4_parser_class_name[::syntax_error::syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m) - : std::runtime_error (m)]b4_locations_if([ - , location (l)])[ - {} - - // basic_symbol. +[[ // basic_symbol. +#if 201103L <= YY_CPLUSPLUS template - ]b4_parser_class_name[::basic_symbol::basic_symbol () - : value ()]b4_locations_if([ - , location ()])[ - {} - - template - ]b4_parser_class_name[::basic_symbol::basic_symbol (const basic_symbol& other) - : Base (other) - , value (]b4_variant_if([], [other.value])[)]b4_locations_if([ - , location (other.location)])[ + ]b4_parser_class[::basic_symbol::basic_symbol (basic_symbol&& that) + : Base (std::move (that)) + , value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([ + , location (std::move (that.location))])[ {]b4_variant_if([ - b4_symbol_variant([other.type_get ()], [value], [copy], - [other.value])])[ - } + b4_symbol_variant([this->type_get ()], [value], [move], + [std::move (that.value)]) + ])[} +#endif template - ]b4_parser_class_name[::basic_symbol::basic_symbol (]b4_join( - [typename Base::kind_type t], - [const semantic_type& v], - b4_locations_if([const location_type& l]))[) - : Base (t) - , value (]b4_variant_if([], [v])[)]b4_locations_if([ - , location (l)])[ - {]b4_variant_if([[ - (void) v; - ]b4_symbol_variant([this->type_get ()], [value], [copy], [v])])[} + ]b4_parser_class[::basic_symbol::basic_symbol (const basic_symbol& that) + : Base (that) + , value (]b4_variant_if([], [that.value]))b4_locations_if([ + , location (that.location)])[ + {]b4_variant_if([ + b4_symbol_variant([this->type_get ()], [value], [copy], + [YY_MOVE (that.value)]) + ])[} -]b4_variant_if([[ - // Implementation of basic_symbol constructor for each type. -]b4_type_foreach([b4_basic_symbol_constructor_define])], [[ +]b4_variant_if([], [[ /// Constructor for valueless symbols. template - ]b4_parser_class_name[::basic_symbol::basic_symbol (]b4_join( + ]b4_parser_class[::basic_symbol::basic_symbol (]b4_join( [typename Base::kind_type t], - b4_locations_if([const location_type& l]))[) + b4_locations_if([YY_MOVE_REF (location_type) l]))[) : Base (t) , value ()]b4_locations_if([ , location (l)])[ - {}]])[ - - template - ]b4_parser_class_name[::basic_symbol::~basic_symbol () - { - clear (); - } + {} template - void - ]b4_parser_class_name[::basic_symbol::clear () + ]b4_parser_class[::basic_symbol::basic_symbol (]b4_join( + [typename Base::kind_type t], + [YY_RVREF (semantic_type) v], + b4_locations_if([YY_RVREF (location_type) l]))[) + : Base (t) + , value (]b4_variant_if([], [YY_MOVE (v)])[)]b4_locations_if([ + , location (YY_MOVE (l))])[ {]b4_variant_if([[ - // User destructor. - symbol_number_type yytype = this->type_get (); - basic_symbol& yysym = *this; - (void) yysym; - switch (yytype) - { -]b4_symbol_foreach([b4_symbol_destructor])dnl -[ default: - break; - } - - // Type destructor. - ]b4_symbol_variant([[yytype]], [[value]], [[template destroy]])])[ - Base::clear (); - } + (void) v; + ]b4_symbol_variant([this->type_get ()], [value], [YY_MOVE_OR_COPY], [YY_MOVE (v)])])[}]])[ template bool - ]b4_parser_class_name[::basic_symbol::empty () const + ]b4_parser_class[::basic_symbol::empty () const YY_NOEXCEPT { return Base::type_get () == empty_symbol; } template void - ]b4_parser_class_name[::basic_symbol::move (basic_symbol& s) + ]b4_parser_class[::basic_symbol::move (basic_symbol& s) { super_type::move (s); ]b4_variant_if([b4_symbol_variant([this->type_get ()], [value], [move], - [s.value])], - [value = s.value;])[]b4_locations_if([ - location = s.location;])[ + [YY_MOVE (s.value)])], + [value = YY_MOVE (s.value);])[]b4_locations_if([ + location = YY_MOVE (s.location);])[ } // by_type. - ]b4_inline([$1])b4_parser_class_name[::by_type::by_type () + ]b4_inline([$1])b4_parser_class[::by_type::by_type () : type (empty_symbol) {} - ]b4_inline([$1])b4_parser_class_name[::by_type::by_type (const by_type& other) - : type (other.type) +#if 201103L <= YY_CPLUSPLUS + ]b4_inline([$1])b4_parser_class[::by_type::by_type (by_type&& that) + : type (that.type) + { + that.clear (); + } +#endif + + ]b4_inline([$1])b4_parser_class[::by_type::by_type (const by_type& that) + : type (that.type) {} - ]b4_inline([$1])b4_parser_class_name[::by_type::by_type (token_type t) + ]b4_inline([$1])b4_parser_class[::by_type::by_type (token_type t) : type (yytranslate_ (t)) {} ]b4_inline([$1])[void - ]b4_parser_class_name[::by_type::clear () + ]b4_parser_class[::by_type::clear () { type = empty_symbol; } ]b4_inline([$1])[void - ]b4_parser_class_name[::by_type::move (by_type& that) + ]b4_parser_class[::by_type::move (by_type& that) { type = that.type; that.clear (); } ]b4_inline([$1])[int - ]b4_parser_class_name[::by_type::type_get () const + ]b4_parser_class[::by_type::type_get () const YY_NOEXCEPT { return type; } ]b4_token_ctor_if([[ - ]b4_inline([$1])b4_parser_class_name[::token_type - ]b4_parser_class_name[::by_type::token () const + ]b4_inline([$1])b4_parser_class[::token_type + ]b4_parser_class[::by_type::token () const YY_NOEXCEPT { // YYTOKNUM[NUM] -- (External) token number corresponding to the // (internal) symbol number NUM (which must be that of a token). */ @@ -423,19 +510,17 @@ m4_define([b4_public_types_define], { ]b4_toknum[ }; - return static_cast (yytoken_number_[type]); + return token_type (yytoken_number_[type]); } ]])[]dnl -b4_symbol_constructor_define]) +]) -# b4_symbol_constructor_declare -# b4_symbol_constructor_define -# ----------------------------- -# Declare/define symbol constructors for all the value types. +# b4_token_constructor_define +# ---------------------------- +# Define symbol constructors for all the value types. # Use at class-level. Redefined in variant.hh. -m4_define([b4_symbol_constructor_declare], []) -m4_define([b4_symbol_constructor_define], []) +m4_define([b4_token_constructor_define], []) # b4_yytranslate_define(cc|hh) @@ -443,16 +528,17 @@ m4_define([b4_symbol_constructor_define], []) # Define yytranslate_. Sometimes used in the header file ($1=hh), # sometimes in the cc file. m4_define([b4_yytranslate_define], -[[ // Symbol number corresponding to token number t. - ]b4_inline([$1])b4_parser_class_name[::token_number_type - ]b4_parser_class_name[::yytranslate_ (]b4_token_ctor_if([token_type], +[ b4_inline([$1])b4_parser_class[::token_number_type + ]b4_parser_class[::yytranslate_ (]b4_token_ctor_if([token_type], [int])[ t) { + // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to + // TOKEN-NUM as returned by yylex. static const token_number_type translate_table[] = { -]b4_translate[ + ]b4_translate[ }; const unsigned user_token_number_max_ = ]b4_user_token_number_max[; const token_number_type undef_token_ = ]b4_undef_token_number[; @@ -469,15 +555,13 @@ m4_define([b4_yytranslate_define], # b4_lhs_value([TYPE]) # -------------------- -# Expansion of $$. m4_define([b4_lhs_value], [b4_symbol_value([yyval], [$1])]) -# b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) +# b4_rhs_value(RULE-LENGTH, POS, [TYPE]) # -------------------------------------- -# Expansion of $NUM, where the current rule has RULE-LENGTH -# symbols on RHS. +# FIXME: Dead code. m4_define([b4_rhs_value], [b4_symbol_value([yysemantic_stack_@{($1) - ($2)@}], [$3])]) @@ -489,9 +573,9 @@ m4_define([b4_lhs_location], [(yyloc)]) -# b4_rhs_location(RULE-LENGTH, NUM) +# b4_rhs_location(RULE-LENGTH, POS) # --------------------------------- -# Expansion of @NUM, where the current rule has RULE-LENGTH symbols +# Expansion of @POS, where the current rule has RULE-LENGTH symbols # on RHS. m4_define([b4_rhs_location], [(yylocation_stack_@{($1) - ($2)@})]) @@ -564,7 +648,7 @@ m4_define([b4_yylloc_default_define], { \ (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \ } \ - while (/*CONSTCOND*/ false) + while (false) # endif ]]) diff --git a/bison/data/c-like.m4 b/bison/data/skeletons/c-like.m4 similarity index 66% rename from bison/data/c-like.m4 rename to bison/data/skeletons/c-like.m4 index 26bab42..8d891b6 100644 --- a/bison/data/c-like.m4 +++ b/bison/data/skeletons/c-like.m4 @@ -2,7 +2,7 @@ # Common code for C-like languages (C, C++, Java, etc.) -# Copyright (C) 2012-2015, 2018 Free Software Foundation, Inc. +# Copyright (C) 2012-2015, 2018-2019 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,14 +17,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# b4_comment_(TEXT, OPEN, CONTINUE, END) +# _b4_comment(TEXT, OPEN, CONTINUE, END) # -------------------------------------- # Put TEXT in comment. Avoid trailing spaces: don't indent empty lines. # Avoid adding indentation to the first line, as the indentation comes # from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]). # # Prefix all the output lines with PREFIX. -m4_define([b4_comment_], +m4_define([_b4_comment], [$2[]m4_bpatsubst(m4_expand([[$1]]), [ \(.\)], [ $3\1])$4]) @@ -34,30 +34,31 @@ $3\1])$4]) # -------------------------- # Put TEXT in comment. Prefix all the output lines with PREFIX. m4_define([b4_comment], -[b4_comment_([$1], [$2/* ], [$2 ], [ */])]) +[_b4_comment([$1], [$2/* ], [$2 ], [ */])]) -# b4_dollar_dollar_(VALUE, FIELD, DEFAULT-FIELD) -# ---------------------------------------------- +# _b4_dollar_dollar(VALUE, SYMBOL-NUM, FIELD, DEFAULT-FIELD) +# ---------------------------------------------------------- # If FIELD (or DEFAULT-FIELD) is non-null, return "VALUE.FIELD", -# otherwise just VALUE. Be sure to pass "(VALUE)" is VALUE is a +# otherwise just VALUE. Be sure to pass "(VALUE)" if VALUE is a # pointer. -m4_define([b4_dollar_dollar_], +m4_define([_b4_dollar_dollar], [b4_symbol_value([$1], - m4_if([$2], [[]], - [[$3]], [[$2]]))]) + [$2], + m4_if([$3], [[]], + [[$4]], [[$3]]))]) -# b4_dollar_pushdef(VALUE-POINTER, DEFAULT-FIELD, LOCATION) +# b4_dollar_pushdef(VALUE-POINTER, SYMBOL-NUM, [TYPE_TAG], LOCATION) # b4_dollar_popdef -# --------------------------------------------------------- -# Define b4_dollar_dollar for VALUE and DEFAULT-FIELD, +# ------------------------------------------------------------------ +# Define b4_dollar_dollar for VALUE-POINTER and DEFAULT-FIELD, # and b4_at_dollar for LOCATION. m4_define([b4_dollar_pushdef], [m4_pushdef([b4_dollar_dollar], - [b4_dollar_dollar_([$1], m4_dquote($][1), [$2])])dnl -m4_pushdef([b4_at_dollar], [$3])dnl + [_b4_dollar_dollar([$1], [$2], m4_dquote($][1), [$3])])dnl +m4_pushdef([b4_at_dollar], [$4])dnl ]) m4_define([b4_dollar_popdef], [m4_popdef([b4_at_dollar])dnl diff --git a/bison/data/c-skel.m4 b/bison/data/skeletons/c-skel.m4 similarity index 73% rename from bison/data/c-skel.m4 rename to bison/data/skeletons/c-skel.m4 index cb9a7a2..2a21cfc 100644 --- a/bison/data/c-skel.m4 +++ b/bison/data/skeletons/c-skel.m4 @@ -2,8 +2,8 @@ # C skeleton dispatching for Bison. -# Copyright (C) 2006-2007, 2009-2015, 2018 Free Software Foundation, -# Inc. +# Copyright (C) 2006-2007, 2009-2015, 2018-2019 Free Software +# Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,10 +18,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -b4_glr_if( [m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.c]])]) -b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_pkgdatadir/[glr.c]])]) +b4_glr_if( [m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.c]])]) +b4_nondeterministic_if([m4_define([b4_used_skeleton], [b4_skeletonsdir/[glr.c]])]) -m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[yacc.c]]) +m4_define_default([b4_used_skeleton], [b4_skeletonsdir/[yacc.c]]) m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) m4_include(b4_used_skeleton) diff --git a/bison/data/c.m4 b/bison/data/skeletons/c.m4 similarity index 89% rename from bison/data/c.m4 rename to bison/data/skeletons/c.m4 index 346b8fd..3cde04a 100644 --- a/bison/data/c.m4 +++ b/bison/data/skeletons/c.m4 @@ -2,7 +2,8 @@ # C M4 Macros for Bison. -# Copyright (C) 2002, 2004-2015, 2018 Free Software Foundation, Inc. +# Copyright (C) 2002, 2004-2015, 2018-2019 Free Software Foundation, +# Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,7 +18,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -m4_include(b4_pkgdatadir/[c-like.m4]) +m4_include(b4_skeletonsdir/[c-like.m4]) # b4_tocpp(STRING) # ---------------- @@ -204,11 +205,12 @@ m4_define([b4_table_value_equals], ## Compiler issues. ## ## ----------------- ## -# b4_attribute_define -# ------------------- -# Provide portable compiler "attributes". +# b4_attribute_define([noreturn]) +# ------------------------------- +# Provide portable compiler "attributes". If "noreturn" is passed, define +# _Noreturn. m4_define([b4_attribute_define], -[#ifndef YY_ATTRIBUTE +[[#ifndef YY_ATTRIBUTE # if (defined __GNUC__ \ && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C @@ -226,16 +228,23 @@ m4_define([b4_attribute_define], # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) #endif -#if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) -# else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) +]m4_bmatch([$1], [\bnoreturn\b], [[/* The _Noreturn keyword of C11. */ +#if ! defined _Noreturn +# if defined __cplusplus && 201103L <= __cplusplus +# define _Noreturn [[noreturn]] +# elif !(defined __STDC_VERSION__ && 201112 <= __STDC_VERSION__) +# if (3 <= __GNUC__ || (__GNUC__ == 2 && 8 <= __GNUC_MINOR__) \ + || 0x5110 <= __SUNPRO_C) +# define _Noreturn __attribute__ ((__noreturn__)) +# elif defined _MSC_VER && 1200 <= _MSC_VER +# define _Noreturn __declspec (noreturn) +# else +# define _Noreturn +# endif # endif #endif -/* Suppress unused-variable warnings by "using" E. */ +]])[/* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ # define YYUSE(E) ((void) (E)) #else @@ -260,24 +269,26 @@ m4_define([b4_attribute_define], #ifndef YY_INITIAL_VALUE # define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif -]) - - -## ---------## -## Values. ## -## ---------## +]]) # b4_null_define # -------------- # Portability issues: define a YY_NULLPTR appropriate for the current # language (C, C++98, or C++11). +# +# In C++ pre C++11 it is standard practice to use 0 (not NULL) for the +# null pointer. In C, prefer ((void*)0) to avoid having to include stdlib.h. m4_define([b4_null_define], [# ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr +# if defined __cplusplus +# if 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif # else -# define YY_NULLPTR 0 +# define YY_NULLPTR ((void*)0) # endif # endif[]dnl ]) @@ -288,6 +299,12 @@ m4_define([b4_null_define], # Return a null pointer constant. m4_define([b4_null], [YY_NULLPTR]) + + +## ---------## +## Values. ## +## ---------## + # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT) # ------------------------------------------------------------- # Define "yy" whose contents is CONTENT. @@ -357,15 +374,17 @@ m4_define([b4_token_enums_defines], ## ----------------- ## -# b4_symbol_value(VAL, [TYPE]) -# ---------------------------- -# Given a semantic value VAL ($$, $1 etc.), extract its value of type -# TYPE if TYPE is given, otherwise just return VAL. The result can be -# used safetly, it is put in parens to avoid nasty precedence issues. -# TYPE is *not* put in braces, provide some if needed. +# b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG]) +# ---------------------------------------------- +# See README. m4_define([b4_symbol_value], -[($1[]m4_ifval([$2], [.$2]))]) - +[m4_ifval([$3], + [($1.$3)], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [($1.b4_symbol([$2], [type]))], + [$1])], + [$1])])]) ## ---------------------- ## @@ -498,54 +517,54 @@ m4_ifset([b4_parse_param], [, b4_parse_param]))[ # Define the "yy_symbol_print" function. m4_define_default([b4_yy_symbol_print_define], [[ -/*----------------------------------------. -| Print this symbol's value on YYOUTPUT. | -`----------------------------------------*/ +/*-----------------------------------. +| Print this symbol's value on YYO. | +`-----------------------------------*/ ]b4_function_define([yy_symbol_value_print], [static void], - [[FILE *yyoutput], [yyoutput]], + [[FILE *yyo], [yyo]], [[int yytype], [yytype]], [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl m4_ifset([b4_parse_param], [, b4_parse_param]))[ { - FILE *yyo = yyoutput; -]b4_parse_param_use([yyo], [yylocationp])dnl + FILE *yyoutput = yyo; +]b4_parse_param_use([yyoutput], [yylocationp])dnl [ if (!yyvaluep) return;] dnl glr.c does not feature yytoknum. m4_if(b4_skeleton, ["yacc.c"], [[# ifdef YYPRINT if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); + YYPRINT (yyo, yytoknum[yytype], *yyvaluep); # endif ]])dnl b4_symbol_actions([printer])[ } -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ +/*---------------------------. +| Print this symbol on YYO. | +`---------------------------*/ ]b4_function_define([yy_symbol_print], [static void], - [[FILE *yyoutput], [yyoutput]], + [[FILE *yyo], [yyo]], [[int yytype], [yytype]], [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl m4_ifset([b4_parse_param], [, b4_parse_param]))[ { - YYFPRINTF (yyoutput, "%s %s (", + YYFPRINTF (yyo, "%s %s (", yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); -]b4_locations_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp); - YYFPRINTF (yyoutput, ": "); +]b4_locations_if([ YY_LOCATION_PRINT (yyo, *yylocationp); + YYFPRINTF (yyo, ": "); ])dnl -[ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl +[ yy_symbol_value_print (yyo, yytype, yyvaluep]dnl b4_locations_if([, yylocationp])[]b4_user_args[); - YYFPRINTF (yyoutput, ")"); + YYFPRINTF (yyo, ")"); }]dnl ]) @@ -588,14 +607,17 @@ m4_define([b4_type_define_tag], ]) -# b4_symbol_value_union(VAL, [TYPE]) -# ---------------------------------- +# b4_symbol_value_union(VAL, SYMBOL-NUM, [TYPE]) +# ---------------------------------------------- # Same of b4_symbol_value, but when api.value.type=union. m4_define([b4_symbol_value_union], -[m4_ifval([$2], - [(*($2*)(&$1))], - [$1])]) -]) +[m4_ifval([$3], + [(*($3*)(&$1))], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [($1.b4_symbol([$2], [type_tag]))], + [$1])], + [$1])])]) # b4_value_type_setup_union @@ -807,11 +829,11 @@ m4_define([b4_yy_location_print_define], YY_ATTRIBUTE_UNUSED ]b4_function_define([yy_location_print_], - [static unsigned], + [static int], [[FILE *yyo], [yyo]], [[YYLTYPE const * const yylocp], [yylocp]])[ { - unsigned res = 0; + int res = 0; int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0; if (0 <= yylocp->first_line) { diff --git a/bison/data/skeletons/d-skel.m4 b/bison/data/skeletons/d-skel.m4 new file mode 100644 index 0000000..1705d84 --- /dev/null +++ b/bison/data/skeletons/d-skel.m4 @@ -0,0 +1,26 @@ + -*- Autoconf -*- + +# D skeleton dispatching for Bison. + +# Copyright (C) 2018-2019 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +b4_glr_if( [b4_complain([%%glr-parser not supported for D])]) +b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for D])]) + +m4_define_default([b4_used_skeleton], [b4_skeletonsdir/[lalr1.d]]) +m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) + +m4_include(b4_used_skeleton) diff --git a/bison/data/skeletons/d.m4 b/bison/data/skeletons/d.m4 new file mode 100644 index 0000000..946f013 --- /dev/null +++ b/bison/data/skeletons/d.m4 @@ -0,0 +1,320 @@ + -*- Autoconf -*- + +# D language support for Bison + +# Copyright (C) 2018-2019 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# b4_comment(TEXT) +# ---------------- +m4_define([b4_comment], [/* m4_bpatsubst([$1], [ +], [ + ]) */]) + + +# b4_list2(LIST1, LIST2) +# ---------------------- +# Join two lists with a comma if necessary. +m4_define([b4_list2], + [$1[]m4_ifval(m4_quote($1), [m4_ifval(m4_quote($2), [[, ]])])[]$2]) + + +# b4_percent_define_get3(DEF, PRE, POST, NOT) +# ------------------------------------------- +# Expand to the value of DEF surrounded by PRE and POST if it's %define'ed, +# otherwise NOT. +m4_define([b4_percent_define_get3], + [m4_ifval(m4_quote(b4_percent_define_get([$1])), + [$2[]b4_percent_define_get([$1])[]$3], [$4])]) + + +# b4_flag_value(BOOLEAN-FLAG) +# --------------------------- +m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])]) + + +# b4_parser_class_declaration +# --------------------------- +# The declaration of the parser class ("class YYParser"), with all its +# qualifiers/annotations. +b4_percent_define_default([[api.parser.abstract]], [[false]]) +b4_percent_define_default([[api.parser.final]], [[false]]) +b4_percent_define_default([[api.parser.public]], [[false]]) + +m4_define([b4_parser_class_declaration], +[b4_percent_define_get3([api.parser.annotations], [], [ ])dnl +b4_percent_define_flag_if([api.parser.public], [public ])dnl +b4_percent_define_flag_if([api.parser.abstract], [abstract ])dnl +b4_percent_define_flag_if([api.parser.final], [final ])dnl +[class ]b4_parser_class[]dnl +b4_percent_define_get3([api.parser.extends], [ extends ])dnl +b4_percent_define_get3([api.parser.implements], [ implements ])]) + + +# b4_lexer_if(TRUE, FALSE) +# ------------------------ +m4_define([b4_lexer_if], +[b4_percent_code_ifdef([[lexer]], [$1], [$2])]) + + +# b4_position_type_if(TRUE, FALSE) +# -------------------------------- +m4_define([b4_position_type_if], +[b4_percent_define_ifdef([[position_type]], [$1], [$2])]) + + +# b4_location_type_if(TRUE, FALSE) +# -------------------------------- +m4_define([b4_location_type_if], +[b4_percent_define_ifdef([[location_type]], [$1], [$2])]) + + +# b4_locations_if(TRUE, FALSE) +# ---------------------------- +m4_define([b4_locations_if], +[m4_if(b4_locations_flag, 1, [$1], [$2])]) + + +# b4_identification +# ----------------- +m4_define([b4_identification], +[/** Version number for the Bison executable that generated this parser. */ + public static immutable string yy_bison_version = "b4_version"; + + /** Name of the skeleton that generated this parser. */ + public static immutable string yy_bison_skeleton = b4_skeleton; +]) + + +## ------------ ## +## Data types. ## +## ------------ ## + +# b4_int_type(MIN, MAX) +# --------------------- +# Return the smallest int type able to handle numbers ranging from +# MIN to MAX (included). +m4_define([b4_int_type], +[m4_if(b4_ints_in($@, [-128], [127]), [1], [byte], + b4_ints_in($@, [-32768], [32767]), [1], [short], + [int])]) + +# b4_int_type_for(NAME) +# --------------------- +# Return the smallest int type able to handle numbers ranging from +# `NAME_min' to `NAME_max' (included). +m4_define([b4_int_type_for], +[b4_int_type($1_min, $1_max)]) + +# b4_null +# ------- +m4_define([b4_null], [null]) + + +# b4_integral_parser_table_define(NAME, DATA, COMMENT) +#----------------------------------------------------- +# Define "yy" whose contents is CONTENT. +m4_define([b4_integral_parser_table_define], +[m4_ifvaln([$3], [b4_comment([$3], [ ])])dnl +private static immutable b4_int_type_for([$2])[[]] yy$1_ = +@{ + $2 +@};dnl +]) + + +## ------------------------- ## +## Assigning token numbers. ## +## ------------------------- ## + +# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER) +# --------------------------------------- +# Output the definition of this token as an enum. +m4_define([b4_token_enum], +[b4_token_format([ %s = %s, +], [$1])]) + +# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) +# ----------------------------------------------------- +# Output the definition of the tokens as enums. +m4_define([b4_token_enums], +[/* Tokens. */ +public enum YYTokenType { + + /** Token returned by the scanner to signal the end of its input. */ + EOF = 0, +b4_symbol_foreach([b4_token_enum]) +} +]) + +# b4-case(ID, CODE) +# ----------------- +m4_define([b4_case], [ case $1: +$2 + break;]) + + +## ---------------- ## +## Default values. ## +## ---------------- ## + +m4_define([b4_yystype], [b4_percent_define_get([[stype]])]) +b4_percent_define_default([[stype]], [[YYSemanticType]])]) + +# %name-prefix +m4_define_default([b4_prefix], [[YY]]) + +b4_percent_define_default([[api.parser.class]], [b4_prefix[]YYParser])]) +m4_define([b4_parser_class], [b4_percent_define_get([[api.parser.class]])]) + +#b4_percent_define_default([[location_type]], [Location])]) +m4_define([b4_location_type], b4_percent_define_ifdef([[location_type]],[b4_percent_define_get([[location_type]])],[YYLocation])) + +#b4_percent_define_default([[position_type]], [Position])]) +m4_define([b4_position_type], b4_percent_define_ifdef([[position_type]],[b4_percent_define_get([[position_type]])],[YYPosition])) + + +## ----------------- ## +## Semantic Values. ## +## ----------------- ## + + +# b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG]) +# ---------------------------------------------- +# See README. FIXME: factor in c-like? +m4_define([b4_symbol_value], +[m4_ifval([$3], + [($1.$3)], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [($1.b4_symbol([$2], [type]))], + [$1])], + [$1])])]) + +# b4_lhs_value(SYMBOL-NUM, [TYPE]) +# -------------------------------- +# See README. +m4_define([b4_lhs_value], +[b4_symbol_value([yyval], [$1], [$2])]) + + +# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) +# -------------------------------------------------- +# See README. +# +# In this simple implementation, %token and %type have class names +# between the angle brackets. +m4_define([b4_rhs_value], +[b4_symbol_value([(yystack.valueAt (b4_subtract([$1], [$2])))], [$3], [$4])]) + + +# b4_lhs_location() +# ----------------- +# Expansion of @$. +m4_define([b4_lhs_location], +[(yyloc)]) + + +# b4_rhs_location(RULE-LENGTH, POS) +# --------------------------------- +# Expansion of @POS, where the current rule has RULE-LENGTH symbols +# on RHS. +m4_define([b4_rhs_location], +[yystack.locationAt ([$1], [$2])]) + + +# b4_lex_param +# b4_parse_param +# -------------- +# If defined, b4_lex_param arrives double quoted, but below we prefer +# it to be single quoted. Same for b4_parse_param. + +# TODO: should be in bison.m4 +m4_define_default([b4_lex_param], [[]])) +m4_define([b4_lex_param], b4_lex_param)) +m4_define([b4_parse_param], b4_parse_param)) + +# b4_lex_param_decl +# ------------------- +# Extra formal arguments of the constructor. +m4_define([b4_lex_param_decl], +[m4_ifset([b4_lex_param], + [b4_remove_comma([$1], + b4_param_decls(b4_lex_param))], + [$1])]) + +m4_define([b4_param_decls], + [m4_map([b4_param_decl], [$@])]) +m4_define([b4_param_decl], [, $1]) + +m4_define([b4_remove_comma], [m4_ifval(m4_quote($1), [$1, ], [])m4_shift2($@)]) + + + +# b4_parse_param_decl +# ------------------- +# Extra formal arguments of the constructor. +m4_define([b4_parse_param_decl], +[m4_ifset([b4_parse_param], + [b4_remove_comma([$1], + b4_param_decls(b4_parse_param))], + [$1])]) + + + +# b4_lex_param_call +# ------------------- +# Delegating the lexer parameters to the lexer constructor. +m4_define([b4_lex_param_call], + [m4_ifset([b4_lex_param], + [b4_remove_comma([$1], + b4_param_calls(b4_lex_param))], + [$1])]) +m4_define([b4_param_calls], + [m4_map([b4_param_call], [$@])]) +m4_define([b4_param_call], [, $2]) + + + +# b4_parse_param_cons +# ------------------- +# Extra initialisations of the constructor. +m4_define([b4_parse_param_cons], + [m4_ifset([b4_parse_param], + [b4_constructor_calls(b4_parse_param)])]) + +m4_define([b4_constructor_calls], + [m4_map([b4_constructor_call], [$@])]) +m4_define([b4_constructor_call], + [this.$2 = $2; + ]) + + + +# b4_parse_param_vars +# ------------------- +# Extra instance variables. +m4_define([b4_parse_param_vars], + [m4_ifset([b4_parse_param], + [ + /* User arguments. */ +b4_var_decls(b4_parse_param)])]) + +m4_define([b4_var_decls], + [m4_map_sep([b4_var_decl], [ +], [$@])]) +m4_define([b4_var_decl], + [ protected $1;]) diff --git a/bison/data/glr.c b/bison/data/skeletons/glr.c similarity index 91% rename from bison/data/glr.c rename to bison/data/skeletons/glr.c index cd4dc3e..87f2830 100644 --- a/bison/data/glr.c +++ b/bison/data/skeletons/glr.c @@ -2,7 +2,7 @@ # GLR skeleton for Bison -# Copyright (C) 2002-2015, 2018 Free Software Foundation, Inc. +# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,7 +21,8 @@ # If we are loaded by glr.cc, do not override c++.m4 definitions by # those of c.m4. m4_if(b4_skeleton, ["glr.c"], - [m4_include(b4_pkgdatadir/[c.m4])]) + [m4_include(b4_skeletonsdir/[c.m4])]) + ## ---------------- ## ## Default values. ## @@ -96,6 +97,7 @@ m4_define([b4_pure_formals], # b4_locuser_formals(LOC = yylocp) # -------------------------------- +# User formal arguments, possibly preceded by location argument. m4_define([b4_locuser_formals], [b4_locations_if([, YYLTYPE *m4_default([$1], [yylocp])])[]b4_user_formals]) @@ -112,27 +114,25 @@ m4_define([b4_locuser_args], ## ----------------- ## -# b4_lhs_value([TYPE]) -# -------------------- -# Expansion of $$. +# b4_lhs_value(SYMBOL-NUM, [TYPE]) +# -------------------------------- +# See README. m4_define([b4_lhs_value], -[b4_symbol_value([(*yyvalp)], [$1])]) +[b4_symbol_value([(*yyvalp)], [$1], [$2])]) -# b4_rhs_data(RULE-LENGTH, NUM) +# b4_rhs_data(RULE-LENGTH, POS) # ----------------------------- -# Expand to the semantic stack place that contains value and location -# of symbol number NUM in a rule of length RULE-LENGTH. +# See README. m4_define([b4_rhs_data], [((yyGLRStackItem const *)yyvsp)@{YYFILL (b4_subtract([$2], [$1]))@}.yystate]) -# b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) -# -------------------------------------- -# Expansion of $NUM, where the current rule has RULE-LENGTH -# symbols on RHS. +# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) +# -------------------------------------------------- +# Expansion of $$ or $$, for symbol SYMBOL-NUM. m4_define([b4_rhs_value], -[b4_symbol_value([b4_rhs_data([$1], [$2]).yysemantics.yysval], [$3])]) +[b4_symbol_value([b4_rhs_data([$1], [$2]).yysemantics.yysval], [$3], [$4])]) @@ -194,16 +194,15 @@ m4_if(b4_skeleton, ["glr.c"], # ----------------- # # glr.cc produces its own header. -m4_if(b4_skeleton, ["glr.c"], +b4_glr_cc_if([], [b4_defines_if( [b4_output_begin([b4_spec_defines_file]) b4_copyright([Skeleton interface for Bison GLR parsers in C], - [2002-2015, 2018])[ - + [2002-2015, 2018-2019])[ ]b4_cpp_guard_open([b4_spec_defines_file])[ ]b4_shared_declarations[ ]b4_cpp_guard_close([b4_spec_defines_file])[ -]b4_output_end() +]b4_output_end ])]) @@ -213,13 +212,13 @@ b4_copyright([Skeleton interface for Bison GLR parsers in C], b4_output_begin([b4_parser_file_name]) b4_copyright([Skeleton implementation for Bison GLR parsers in C], - [2002-2015, 2018])[ - + [2002-2015, 2018-2019])[ /* C GLR parser skeleton written by Paul Hilfinger. */ -]b4_identification +]b4_disclaimer[ +]b4_identification[ -b4_percent_code_get([[top]])[ +]b4_percent_code_get([[top]])[ ]m4_if(b4_api_prefix, [yy], [], [[/* Substitute the type names. */ #define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[ @@ -229,14 +228,12 @@ b4_percent_code_get([[top]])[ #define yyparse ]b4_prefix[parse #define yylex ]b4_prefix[lex #define yyerror ]b4_prefix[error -#define yydebug ]b4_prefix[debug -]]b4_pure_if([], [[ +#define yydebug ]b4_prefix[debug]]b4_pure_if([], [[ #define yylval ]b4_prefix[lval #define yychar ]b4_prefix[char #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[ #define yylloc ]b4_prefix[lloc]])]))[ -/* First part of user declarations. */ ]b4_user_pre_prologue[ ]b4_null_define[ @@ -259,9 +256,8 @@ b4_percent_code_get([[top]])[ static YYSTYPE yyval_default;]b4_locations_if([[ static YYLTYPE yyloc_default][]b4_yyloc_default;])[ -/* Copy the second part of user declarations. */ -]b4_user_post_prologue -b4_percent_code_get[]dnl +]b4_user_post_prologue[ +]b4_percent_code_get[]dnl [#include #include @@ -292,22 +288,29 @@ b4_percent_code_get[]dnl #define YYSIZEMAX ((size_t) -1) #ifdef __cplusplus - typedef bool yybool; + typedef bool yybool; +# define yytrue true +# define yyfalse false #else - typedef unsigned char yybool; + /* When we move to stdbool, get rid of the various casts to yybool. */ + typedef unsigned char yybool; +# define yytrue 1 +# define yyfalse 0 #endif -#define yytrue 1 -#define yyfalse 0 #ifndef YYSETJMP # include # define YYJMP_BUF jmp_buf # define YYSETJMP(Env) setjmp (Env) -/* Pacify clang. */ -# define YYLONGJMP(Env, Val) (longjmp (Env, Val), YYASSERT (0)) +/* Pacify Clang and ICC. */ +# define YYLONGJMP(Env, Val) \ + do { \ + longjmp (Env, Val); \ + YYASSERT (0); \ + } while (yyfalse) #endif -]b4_attribute_define[ +]b4_attribute_define([noreturn])[ #ifndef YYASSERT # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0))) @@ -324,7 +327,7 @@ b4_percent_code_get[]dnl #define YYNNTS ]b4_nterms_number[ /* YYNRULES -- Number of rules. */ #define YYNRULES ]b4_rules_number[ -/* YYNRULES -- Number of states. */ +/* YYNSTATES -- Number of states. */ #define YYNSTATES ]b4_states_number[ /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */ #define YYMAXRHS ]b4_r2_max[ @@ -332,14 +335,22 @@ b4_percent_code_get[]dnl accessed by $0, $-1, etc., in any rule. */ #define YYMAXLEFT ]b4_max_left_semantic_context[ -/* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */ +/* YYMAXUTOK -- Last valid token number (for yychar). */ +#define YYMAXUTOK ]b4_user_token_number_max[]b4_glr_cc_if([[ +/* YYFAULTYTOK -- Token number (for yychar) that denotes a + syntax_error thrown from the scanner. */ +#define YYFAULTYTOK (YYMAXUTOK + 1)]])[ +/* YYUNDEFTOK -- Symbol number (for yytoken) that denotes an unknown + token. */ #define YYUNDEFTOK ]b4_undef_token_number[ -#define YYMAXUTOK ]b4_user_token_number_max[ +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ #define YYTRANSLATE(YYX) \ ((unsigned) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) -/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM + as returned by yylex. */ static const ]b4_int_type_for([b4_translate])[ yytranslate[] = { ]b4_translate[ @@ -579,7 +590,10 @@ yytnamerr (char *yyres, const char *yystr) case '\\': if (*++yyp != '\\') goto do_not_strip_quotes; - /* Fall through. */ + else + goto append; + + append: default: if (yyres) yyres[yyn] = *yyp; @@ -597,7 +611,7 @@ yytnamerr (char *yyres, const char *yystr) if (! yyres) return strlen (yystr); - return yystpcpy (yyres, yystr) - yyres; + return (size_t) (yystpcpy (yyres, yystr) - yyres); } # endif @@ -635,7 +649,7 @@ struct yyGLRState { size_t yyposn; union { /** First in a chain of alternative reductions producing the - * non-terminal corresponding to this state, threaded through + * nonterminal corresponding to this state, threaded through * yynext. */ yySemanticOption* yyfirstVal; /** Semantic value for this state. */ @@ -702,7 +716,7 @@ struct yyGLRStack { static void yyexpandGLRStack (yyGLRStack* yystackp); #endif -static _Noreturn void +_Noreturn static void yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg) { if (yymsg != YY_NULLPTR) @@ -710,7 +724,7 @@ yyFail (yyGLRStack* yystackp]b4_pure_formals[, const char* yymsg) YYLONGJMP (yystackp->yyexception_buffer, 1); } -static _Noreturn void +_Noreturn static void yyMemoryExhausted (yyGLRStack* yystackp) { YYLONGJMP (yystackp->yyexception_buffer, 2); @@ -754,6 +768,50 @@ yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1) } } +]m4_define([b4_yygetToken_call], + [[yygetToken (&yychar][]b4_pure_if([, yystackp])[]b4_user_args[)]])[ +/** If yychar is empty, fetch the next token. */ +static inline yySymbol +yygetToken (int *yycharp][]b4_pure_if([, yyGLRStack* yystackp])[]b4_user_formals[) +{ + yySymbol yytoken; +]b4_parse_param_use()dnl +[ if (*yycharp == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: "));]b4_glr_cc_if([[ +#if YY_EXCEPTIONS + try + { +#endif // YY_EXCEPTIONS + *yycharp = ]b4_lex[; +#if YY_EXCEPTIONS + } + catch (const ]b4_namespace_ref[::]b4_parser_class[::syntax_error& yyexc) + { + YYDPRINTF ((stderr, "Caught exception: %s\n", yyexc.what()));]b4_locations_if([ + yylloc = yyexc.location;])[ + yyerror (]b4_lyyerror_args[yyexc.what ()); + // Map errors caught in the scanner to the undefined token + // (YYUNDEFTOK), so that error handling is started. + // However, record this with this special value of yychar. + *yycharp = YYFAULTYTOK; + } +#endif // YY_EXCEPTIONS]], [[ + *yycharp = ]b4_lex[;]])[ + } + if (*yycharp <= YYEOF) + { + *yycharp = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (*yycharp); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + return yytoken; +} + /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. * For convenience, always return YYLOW1. */ @@ -776,11 +834,11 @@ yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal) * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT, * yyerr for YYERROR, yyabort for YYABORT. */ static YYRESULTTAG -yyuserAction (yyRuleNum yyn, size_t yyrhslen, yyGLRStackItem* yyvsp, +yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp, yyGLRStack* yystackp, YYSTYPE* yyvalp]b4_locuser_formals[) { - yybool yynormal YY_ATTRIBUTE_UNUSED = (yystackp->yysplitPoint == YY_NULLPTR); + yybool yynormal YY_ATTRIBUTE_UNUSED = (yybool) (yystackp->yysplitPoint == YY_NULLPTR); int yylow; ]b4_parse_param_use([yyvalp], [yylocp])dnl [ YYUSE (yyrhslen); @@ -797,7 +855,7 @@ yyuserAction (yyRuleNum yyn, size_t yyrhslen, yyGLRStackItem* yyvsp, # undef yyclearin # define yyclearin (yychar = YYEMPTY) # undef YYFILL -# define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal) +# define YYFILL(N) yyfill (yyvsp, &yylow, (N), yynormal) # undef YYBACKUP # define YYBACKUP(Token, Value) \ return yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")), \ @@ -807,15 +865,31 @@ yyuserAction (yyRuleNum yyn, size_t yyrhslen, yyGLRStackItem* yyvsp, if (yyrhslen == 0) *yyvalp = yyval_default; else - *yyvalp = yyvsp[YYFILL (1 - (int)yyrhslen)].yystate.yysemantics.yysval;]b4_locations_if([[ + *yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;]b4_locations_if([[ + /* Default location. */ YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen); yystackp->yyerror_range[1].yystate.yyloc = *yylocp; -]])[ +]])[]b4_glr_cc_if([[ +#if YY_EXCEPTIONS + typedef ]b4_namespace_ref[::]b4_parser_class[::syntax_error syntax_error; + try + { +#endif // YY_EXCEPTIONS]])[ switch (yyn) { - ]b4_user_actions[ +]b4_user_actions[ default: break; + }]b4_glr_cc_if([[ +#if YY_EXCEPTIONS + } + catch (const syntax_error& yyexc) + { + YYDPRINTF ((stderr, "Caught exception: %s\n", yyexc.what()));]b4_locations_if([ + *yylocp = yyexc.location;])[ + yyerror (]b4_yyerror_args[yyexc.what ()); + YYERROR; } +#endif // YY_EXCEPTIONS]])[ return yyok; # undef yyerrok @@ -899,7 +973,7 @@ yylhsNonterm (yyRuleNum yyrule) static inline yybool yyisDefaultedState (yyStateNum yystate) { - return yypact_value_is_default (yypact[yystate]); + return (yybool) yypact_value_is_default (yypact[yystate]); } /** The default reduction for YYSTATE, assuming it has one. */ @@ -912,7 +986,7 @@ yydefaultAction (yyStateNum yystate) #define yytable_value_is_error(Yytable_value) \ ]b4_table_value_equals([[table]], [[Yytable_value]], [b4_table_ninf])[ -/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN. +/** The action to take in YYSTATE on seeing YYTOKEN. * Result R means * R < 0: Reduce on rule -R. * R = 0: Error. @@ -920,26 +994,25 @@ yydefaultAction (yyStateNum yystate) * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list * of conflicting reductions. */ -static inline void -yygetLRActions (yyStateNum yystate, int yytoken, - int* yyaction, const short** yyconflicts) +static inline int +yygetLRActions (yyStateNum yystate, yySymbol yytoken, const short** yyconflicts) { int yyindex = yypact[yystate] + yytoken; - if (yypact_value_is_default (yypact[yystate]) + if (yyisDefaultedState (yystate) || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) { - *yyaction = -yydefact[yystate]; *yyconflicts = yyconfl; + return -yydefact[yystate]; } else if (! yytable_value_is_error (yytable[yyindex])) { - *yyaction = yytable[yyindex]; *yyconflicts = yyconfl + yyconflp[yyindex]; + return yytable[yyindex]; } else { - *yyaction = 0; *yyconflicts = yyconfl + yyconflp[yyindex]; + return 0; } } @@ -960,13 +1033,13 @@ yyLRgotoState (yyStateNum yystate, yySymbol yysym) static inline yybool yyisShiftAction (int yyaction) { - return 0 < yyaction; + return (yybool) (0 < yyaction); } static inline yybool yyisErrorAction (int yyaction) { - return yyaction == 0; + return (yybool) (yyaction == 0); } /* GLRStates */ @@ -1076,7 +1149,7 @@ yyexpandGLRStack (yyGLRStack* yystackp) yyGLRStackItem* yyp0, *yyp1; size_t yynewSize; size_t yyn; - size_t yysize = yystackp->yynextFree - yystackp->yyitems; + size_t yysize = (size_t) (yystackp->yynextFree - yystackp->yyitems); if (YYMAXDEPTH - YYHEADROOM < yysize) yyMemoryExhausted (yystackp); yynewSize = 2*yysize; @@ -1249,17 +1322,17 @@ yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState, # define YY_REDUCE_PRINT(Args) #else # define YY_REDUCE_PRINT(Args) \ -do { \ - if (yydebug) \ - yy_reduce_print Args; \ -} while (0) + do { \ + if (yydebug) \ + yy_reduce_print Args; \ + } while (0) /*----------------------------------------------------------------------. | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. | `----------------------------------------------------------------------*/ static inline void -yy_reduce_print (int yynormal, yyGLRStackItem* yyvsp, size_t yyk, +yy_reduce_print (yybool yynormal, yyGLRStackItem* yyvsp, size_t yyk, yyRuleNum yyrule]b4_user_formals[) { int yynrhs = yyrhsLength (yyrule);]b4_locations_if([ @@ -1276,8 +1349,8 @@ yy_reduce_print (int yynormal, yyGLRStackItem* yyvsp, size_t yyk, YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, yystos[yyvsp[yyi - yynrhs + 1].yystate.yylrState], - &yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yysval - ]b4_locations_if([, &]b4_rhs_location(yynrhs, yyi + 1))[]dnl + &yyvsp[yyi - yynrhs + 1].yystate.yysemantics.yysval]b4_locations_if([, + &]b4_rhs_location(yynrhs, yyi + 1))[]dnl b4_user_args[); if (!yyvsp[yyi - yynrhs + 1].yystate.yyresolved) YYFPRINTF (stderr, " (unresolved)"); @@ -1304,9 +1377,9 @@ yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk]; YYASSERT (yyk == 0); yystackp->yynextFree -= yynrhs; - yystackp->yyspaceLeft += yynrhs; + yystackp->yyspaceLeft += (size_t) yynrhs; yystackp->yytops.yystates[0] = & yystackp->yynextFree[-1].yystate; - YY_REDUCE_PRINT ((1, yyrhs, yyk, yyrule]b4_user_args[)); + YY_REDUCE_PRINT ((yytrue, yyrhs, yyk, yyrule]b4_user_args[)); return yyuserAction (yyrule, yynrhs, yyrhs, yystackp, yyvalp]b4_locuser_args[); } @@ -1327,7 +1400,7 @@ yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule, } yyupdateSplit (yystackp, yys); yystackp->yytops.yystates[yyk] = yys; - YY_REDUCE_PRINT ((0, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule]b4_user_args[)); + YY_REDUCE_PRINT ((yyfalse, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyk, yyrule]b4_user_args[)); return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yystackp, yyvalp]b4_locuser_args[); } @@ -1423,11 +1496,9 @@ yysplitStack (yyGLRStack* yystackp, size_t yyk) } if (yystackp->yytops.yysize >= yystackp->yytops.yycapacity) { - yyGLRState** yynewStates; + yyGLRState** yynewStates = YY_NULLPTR; yybool* yynewLookaheadNeeds; - yynewStates = YY_NULLPTR; - if (yystackp->yytops.yycapacity > (YYSIZEMAX / (2 * sizeof yynewStates[0]))) yyMemoryExhausted (yystackp); @@ -1855,9 +1926,9 @@ yycompressStack (yyGLRStack* yystackp) yyr = yyp, yyp = yyq, yyq = yyp->yypred) yyp->yypred = yyr; - yystackp->yyspaceLeft += yystackp->yynextFree - yystackp->yyitems; + yystackp->yyspaceLeft += (size_t) (yystackp->yynextFree - yystackp->yyitems); yystackp->yynextFree = ((yyGLRStackItem*) yystackp->yysplitPoint) + 1; - yystackp->yyspaceLeft -= yystackp->yynextFree - yystackp->yyitems; + yystackp->yyspaceLeft -= (size_t) (yystackp->yynextFree - yystackp->yyitems); yystackp->yysplitPoint = YY_NULLPTR; yystackp->yylastDeleted = YY_NULLPTR; @@ -1915,24 +1986,8 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk, const short* yyconflicts; yystackp->yytops.yylookaheadNeeds[yyk] = yytrue; - if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = ]b4_lex[; - } - - if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } - else - { - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } - - yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts); + yytoken = ]b4_yygetToken_call[; + yyaction = yygetLRActions (yystate, yytoken, &yyconflicts); while (*yyconflicts != 0) { @@ -2061,7 +2116,8 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) yyarg[yycount++] = yytokenName (yyx); { size_t yysz = yysize + yytnamerr (YY_NULLPTR, yytokenName (yyx)); - yysize_overflow |= yysz < yysize; + if (yysz < yysize) + yysize_overflow = yytrue; yysize = yysz; } } @@ -2086,7 +2142,8 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) { size_t yysz = yysize + strlen (yyformat); - yysize_overflow |= yysz < yysize; + if (yysz < yysize) + yysize_overflow = yytrue; yysize = yysz; } @@ -2129,15 +2186,13 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[) static void yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) { - size_t yyk; - int yyj; - if (yystackp->yyerrState == 3) /* We just shifted the error token and (perhaps) took some reductions. Skip tokens until we can proceed. */ while (yytrue) { yySymbol yytoken; + int yyj; if (yychar == YYEOF) yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR); if (yychar != YYEMPTY) @@ -2152,19 +2207,9 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) yytoken = YYTRANSLATE (yychar); yydestruct ("Error: discarding", yytoken, &yylval]b4_locuser_args([&yylloc])[); + yychar = YYEMPTY; } - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = ]b4_lex[; - if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } - else - { - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } + yytoken = ]b4_yygetToken_call[; yyj = yypact[yystackp->yytops.yystates[0]->yylrState]; if (yypact_value_is_default (yyj)) return; @@ -2179,22 +2224,25 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) } /* Reduce to one stack. */ - for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1) - if (yystackp->yytops.yystates[yyk] != YY_NULLPTR) - break; - if (yyk >= yystackp->yytops.yysize) - yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR); - for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1) - yymarkStackDeleted (yystackp, yyk); - yyremoveDeletes (yystackp); - yycompressStack (yystackp); + { + size_t yyk; + for (yyk = 0; yyk < yystackp->yytops.yysize; yyk += 1) + if (yystackp->yytops.yystates[yyk] != YY_NULLPTR) + break; + if (yyk >= yystackp->yytops.yysize) + yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR); + for (yyk += 1; yyk < yystackp->yytops.yysize; yyk += 1) + yymarkStackDeleted (yystackp, yyk); + yyremoveDeletes (yystackp); + yycompressStack (yystackp); + } /* Now pop stack until we find a state that shifts the error token. */ yystackp->yyerrState = 3; while (yystackp->yytops.yystates[0] != YY_NULLPTR) { yyGLRState *yys = yystackp->yytops.yystates[0]; - yyj = yypact[yys->yylrState]; + int yyj = yypact[yys->yylrState]; if (! yypact_value_is_default (yyj)) { yyj += YYTERROR; @@ -2258,8 +2306,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[) yylval = yyval_default;]b4_locations_if([ yylloc = yyloc_default;])[ ]m4_ifdef([b4_initial_action], [ -b4_dollar_pushdef([yylval], [], [yylloc])dnl - /* User initialization code. */ +b4_dollar_pushdef([yylval], [], [], [yylloc])dnl b4_user_initial_action b4_dollar_popdef])[]dnl [ @@ -2283,17 +2330,13 @@ b4_dollar_popdef])[]dnl /* Standard mode */ while (yytrue) { - yyRuleNum yyrule; - int yyaction; - const short* yyconflicts; - yyStateNum yystate = yystack.yytops.yystates[0]->yylrState; YYDPRINTF ((stderr, "Entering state %d\n", yystate)); if (yystate == YYFINAL) goto yyacceptlab; if (yyisDefaultedState (yystate)) { - yyrule = yydefaultAction (yystate); + yyRuleNum yyrule = yydefaultAction (yystate); if (yyrule == 0) {]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ @@ -2304,25 +2347,9 @@ b4_dollar_popdef])[]dnl } else { - yySymbol yytoken; - if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = ]b4_lex[; - } - - if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } - else - { - yytoken = YYTRANSLATE (yychar); - YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); - } - - yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts); + yySymbol yytoken = ]b4_yygetToken_call;[ + const short* yyconflicts; + int yyaction = yygetLRActions (yystate, yytoken, &yyconflicts); if (*yyconflicts != 0) break; if (yyisShiftAction (yyaction)) @@ -2336,8 +2363,11 @@ b4_dollar_popdef])[]dnl } else if (yyisErrorAction (yyaction)) {]b4_locations_if([[ - yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[ - yyreportSyntaxError (&yystack]b4_user_args[); + yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[]b4_glr_cc_if([[ + /* Don't issue an error message again for exceptions + thrown from the scanner. */ + if (yychar != YYFAULTYTOK) + ]])[ yyreportSyntaxError (&yystack]b4_user_args[); goto yyuser_error; } else @@ -2351,7 +2381,7 @@ b4_dollar_popdef])[]dnl size_t yys; for (yys = 0; yys < yystack.yytops.yysize; yys += 1) - yystackp->yytops.yylookaheadNeeds[yys] = yychar != YYEMPTY; + yystackp->yytops.yylookaheadNeeds[yys] = (yybool) (yychar != YYEMPTY); /* yyprocessOneStack returns one of three things: @@ -2397,10 +2427,9 @@ b4_dollar_popdef])[]dnl yyposn += 1; for (yys = 0; yys < yystack.yytops.yysize; yys += 1) { - int yyaction; - const short* yyconflicts; yyStateNum yystate = yystack.yytops.yystates[yys]->yylrState; - yygetLRActions (yystate, yytoken_to_shift, &yyaction, + const short* yyconflicts; + int yyaction = yygetLRActions (yystate, yytoken_to_shift, &yyconflicts); /* Note that yyconflicts were handled by yyprocessOneStack. */ YYDPRINTF ((stderr, "On stack %lu, ", (unsigned long) yys)); @@ -2572,4 +2601,4 @@ m4_if(b4_prefix, [yy], [], #define yylloc ]b4_prefix[lloc]])])[ ]b4_epilogue[]dnl -b4_output_end() +b4_output_end diff --git a/bison/data/glr.cc b/bison/data/skeletons/glr.cc similarity index 76% rename from bison/data/glr.cc rename to bison/data/skeletons/glr.cc index 2ce14bc..5621734 100644 --- a/bison/data/glr.cc +++ b/bison/data/skeletons/glr.cc @@ -1,6 +1,6 @@ # C++ GLR skeleton for Bison -# Copyright (C) 2002-2015, 2018 Free Software Foundation, Inc. +# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,13 +44,13 @@ # filename member). # We require a pure interface. -m4_define([b4_pure_flag], [1]) +m4_define([b4_pure_flag], [1]) -m4_include(b4_pkgdatadir/[c++.m4]) -b4_bison_locations_if([m4_include(b4_pkgdatadir/[location.cc])]) +m4_include(b4_skeletonsdir/[c++.m4]) +b4_bison_locations_if([m4_include(b4_skeletonsdir/[location.cc])]) -m4_define([b4_parser_class_name], - [b4_percent_define_get([[parser_class_name]])]) +m4_define([b4_parser_class], + [b4_percent_define_get([[api.parser.class]])]) # Save the parse parameters. m4_define([b4_parse_param_orig], m4_defn([b4_parse_param])) @@ -60,10 +60,10 @@ m4_define([b4_parse_param_orig], m4_defn([b4_parse_param])) # New ones. m4_ifset([b4_parse_param], [m4_define([b4_parse_param_wrap], - [[b4_namespace_ref::b4_parser_class_name[& yyparser], [[yyparser]]],] + [[b4_namespace_ref::b4_parser_class[& yyparser], [[yyparser]]],] m4_defn([b4_parse_param]))], [m4_define([b4_parse_param_wrap], - [[b4_namespace_ref::b4_parser_class_name[& yyparser], [[yyparser]]]]) + [[b4_namespace_ref::b4_parser_class[& yyparser], [[yyparser]]]]) ]) @@ -81,10 +81,10 @@ m4_define([b4_yy_symbol_print_define], [static void], [[FILE *], []], [[int yytype], [yytype]], - [[const ]b4_namespace_ref::b4_parser_class_name[::semantic_type *yyvaluep], + [[const ]b4_namespace_ref::b4_parser_class[::semantic_type *yyvaluep], [yyvaluep]][]dnl b4_locations_if([, - [[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp], + [[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp], [yylocationp]]]), b4_parse_param)[ { @@ -98,18 +98,15 @@ b4_locations_if([, [yylloc.initialize ();]m4_ifdef([b4_initial_action], [ m4_defn([b4_initial_action])]))])[ -# Hijack the post prologue to insert early definition of YYLLOC_DEFAULT -# and declaration of yyerror. +# Hijack the post prologue to declare yyerror. ]m4_append([b4_post_prologue], [b4_syncline([@oline@], [@ofile@])[ -]b4_yylloc_default_define[ -#define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc) ]b4_function_declare([yyerror], [static void],b4_locations_if([ - [[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp], + [[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp], [yylocationp]],]) b4_parse_param, - [[const char* msg], [msg]])]) + [[const char* msg], [msg]])])[ #undef yynerrs @@ -122,8 +119,7 @@ m4_if(b4_prefix, [yy], [], #define yyparse ]b4_prefix[parse #define yylex ]b4_prefix[lex #define yyerror ]b4_prefix[error -#define yydebug ]b4_prefix[debug -]]b4_pure_if([], [[ +#define yydebug ]b4_prefix[debug]]b4_pure_if([], [[ #define yylval ]b4_prefix[lval #define yychar ]b4_prefix[char #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[ @@ -140,7 +136,7 @@ m4_append([b4_epilogue], ]b4_function_define([yyerror], [static void],b4_locations_if([ - [[const ]b4_namespace_ref::b4_parser_class_name[::location_type *yylocationp], + [[const ]b4_namespace_ref::b4_parser_class[::location_type *yylocationp], [yylocationp]],]) b4_parse_param, [[const char* msg], [msg]])[ @@ -154,20 +150,27 @@ m4_append([b4_epilogue], ]dnl In this section, the parse params are the original parse_params. m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl [ /// Build a parser object. - ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [ + ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [ :])[ #if ]b4_api_PREFIX[DEBUG ]m4_ifset([b4_parse_param], [ ], [ :])[yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[ #endif]b4_parse_param_cons[ - { - } + {} + + ]b4_parser_class::~b4_parser_class[ () + {} + + ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW + {} - ]b4_parser_class_name::~b4_parser_class_name[ () + int + ]b4_parser_class[::operator() () { + return parse (); } int - ]b4_parser_class_name[::parse () + ]b4_parser_class[::parse () { return ::yyparse (*this]b4_user_args[); } @@ -178,21 +181,21 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl `--------------------*/ void - ]b4_parser_class_name[::yy_symbol_value_print_ (int yytype, + ]b4_parser_class[::yy_symbol_value_print_ (int yytype, const semantic_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[) {]b4_locations_if([[ YYUSE (yylocationp);]])[ YYUSE (yyvaluep); - std::ostream& yyoutput = debug_stream (); - std::ostream& yyo = yyoutput; - YYUSE (yyo); + std::ostream& yyo = debug_stream (); + std::ostream& yyoutput = yyo; + YYUSE (yyoutput); ]b4_symbol_actions([printer])[ } void - ]b4_parser_class_name[::yy_symbol_print_ (int yytype, + ]b4_parser_class[::yy_symbol_print_ (int yytype, const semantic_type* yyvaluep]b4_locations_if([[, const location_type* yylocationp]])[) { @@ -204,26 +207,26 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl } std::ostream& - ]b4_parser_class_name[::debug_stream () const + ]b4_parser_class[::debug_stream () const { return *yycdebug_; } void - ]b4_parser_class_name[::set_debug_stream (std::ostream& o) + ]b4_parser_class[::set_debug_stream (std::ostream& o) { yycdebug_ = &o; } - ]b4_parser_class_name[::debug_level_type - ]b4_parser_class_name[::debug_level () const + ]b4_parser_class[::debug_level_type + ]b4_parser_class[::debug_level () const { return yydebug; } void - ]b4_parser_class_name[::set_debug_level (debug_level_type l) + ]b4_parser_class[::set_debug_level (debug_level_type l) { // Actually, it is yydebug which is really used. yydebug = l; @@ -234,40 +237,61 @@ m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl b4_namespace_close ]) -# b4_shared_declarations -# ---------------------- -# Declaration that might either go into the header (if --defines) -# or open coded in the parser body. + +# b4_shared_declarations(hh|cc) +# ----------------------------- +# Declaration that might either go into the header (if --defines, $1 = hh) +# or in the implementation file. m4_define([b4_shared_declarations], [m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_orig]))dnl b4_percent_code_get([[requires]])[ - +#include #include #include -#include ]b4_defines_if([ -b4_bison_locations_if([[#include "location.hh"]])])[ + +]b4_cxx_portability[ +]m4_ifdef([b4_location_include], + [[# include ]b4_location_include])[ +]b4_variant_if([b4_variant_includes])[ + +]b4_attribute_define[ +]b4_null_define[ + +// Whether we are compiled with exception support. +#ifndef YY_EXCEPTIONS +# if defined __GNUC__ && !defined __EXCEPTIONS +# define YY_EXCEPTIONS 0 +# else +# define YY_EXCEPTIONS 1 +# endif +#endif ]b4_YYDEBUG_define[ ]b4_namespace_open[ -]b4_defines_if([], -[b4_bison_locations_if([b4_position_define -b4_location_define])])[ + +]b4_bison_locations_if([m4_ifndef([b4_location_file], + [b4_location_define])])[ /// A Bison parser. - class ]b4_parser_class_name[ + class ]b4_parser_class[ { public: ]b4_public_types_declare[ /// Build a parser object. - ]b4_parser_class_name[ (]b4_parse_param_decl[); - virtual ~]b4_parser_class_name[ (); + ]b4_parser_class[ (]b4_parse_param_decl[); + virtual ~]b4_parser_class[ (); + + /// Parse. An alias for parse (). + /// \returns 0 iff parsing succeeded. + int operator() (); /// Parse. /// \returns 0 iff parsing succeeded. virtual int parse (); +#if ]b4_api_PREFIX[DEBUG /// The current debugging stream. std::ostream& debug_stream () const; /// Set the current debugging stream. @@ -279,8 +303,8 @@ b4_location_define])])[ debug_level_type debug_level () const; /// Set the current debugging level. void set_debug_level (debug_level_type l); +#endif - public: /// Report a syntax error.]b4_locations_if([[ /// \param loc where the syntax error is found.]])[ /// \param msg a description of the syntax error. @@ -315,10 +339,10 @@ b4_percent_define_flag_if([[global_tokens_and_yystype]], [b4_token_defines]) [ #ifndef ]b4_api_PREFIX[STYPE -# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class_name[::semantic_type +# define ]b4_api_PREFIX[STYPE ]b4_namespace_ref[::]b4_parser_class[::semantic_type #endif #ifndef ]b4_api_PREFIX[LTYPE -# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class_name[::location_type +# define ]b4_api_PREFIX[LTYPE ]b4_namespace_ref[::]b4_parser_class[::location_type #endif ]b4_namespace_close[ @@ -329,17 +353,17 @@ b4_percent_define_flag_if([[global_tokens_and_yystype]], b4_defines_if( [b4_output_begin([b4_spec_defines_file]) b4_copyright([Skeleton interface for Bison GLR parsers in C++], - [2002-2015, 2018])[ - + [2002-2015, 2018-2019])[ // C++ GLR parser skeleton written by Akim Demaille. +]b4_disclaimer[ ]b4_cpp_guard_open([b4_spec_defines_file])[ ]b4_shared_declarations[ ]b4_cpp_guard_close([b4_spec_defines_file])[ -]b4_output_end()]) +]b4_output_end]) # Let glr.c (and b4_shared_declarations) believe that the user # arguments include the parser itself. m4_pushdef([b4_parse_param], m4_defn([b4_parse_param_wrap])) -m4_include(b4_pkgdatadir/[glr.c]) +m4_include(b4_skeletonsdir/[glr.c]) m4_popdef([b4_parse_param]) diff --git a/bison/data/java-skel.m4 b/bison/data/skeletons/java-skel.m4 similarity index 87% rename from bison/data/java-skel.m4 rename to bison/data/skeletons/java-skel.m4 index 79c3f53..922f1a8 100644 --- a/bison/data/java-skel.m4 +++ b/bison/data/skeletons/java-skel.m4 @@ -2,7 +2,8 @@ # Java skeleton dispatching for Bison. -# Copyright (C) 2007, 2009-2015, 2018 Free Software Foundation, Inc. +# Copyright (C) 2007, 2009-2015, 2018-2019 Free Software Foundation, +# Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,7 +21,7 @@ b4_glr_if( [b4_complain([%%glr-parser not supported for Java])]) b4_nondeterministic_if([b4_complain([%%nondeterministic-parser not supported for Java])]) -m4_define_default([b4_used_skeleton], [b4_pkgdatadir/[lalr1.java]]) +m4_define_default([b4_used_skeleton], [b4_skeletonsdir/[lalr1.java]]) m4_define_default([b4_skeleton], ["b4_basename(b4_used_skeleton)"]) m4_include(b4_used_skeleton) diff --git a/bison/data/java.m4 b/bison/data/skeletons/java.m4 similarity index 79% rename from bison/data/java.m4 rename to bison/data/skeletons/java.m4 index 5ac145c..a62a52e 100644 --- a/bison/data/java.m4 +++ b/bison/data/skeletons/java.m4 @@ -2,7 +2,7 @@ # Java language support for Bison -# Copyright (C) 2007-2015, 2018 Free Software Foundation, Inc. +# Copyright (C) 2007-2015, 2018-2019 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -m4_include(b4_pkgdatadir/[c-like.m4]) +m4_include(b4_skeletonsdir/[c-like.m4]) # b4_list2(LIST1, LIST2) @@ -42,32 +42,24 @@ m4_define([b4_percent_define_get3], m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])]) -# b4_public_if(TRUE, FALSE) -# ------------------------- -b4_percent_define_default([[public]], [[false]]) -m4_define([b4_public_if], -[b4_percent_define_flag_if([public], [$1], [$2])]) - - -# b4_abstract_if(TRUE, FALSE) -# --------------------------- -b4_percent_define_default([[abstract]], [[false]]) -m4_define([b4_abstract_if], -[b4_percent_define_flag_if([abstract], [$1], [$2])]) - - -# b4_final_if(TRUE, FALSE) -# --------------------------- -b4_percent_define_default([[final]], [[false]]) -m4_define([b4_final_if], -[b4_percent_define_flag_if([final], [$1], [$2])]) - - -# b4_strictfp_if(TRUE, FALSE) +# b4_parser_class_declaration # --------------------------- -b4_percent_define_default([[strictfp]], [[false]]) -m4_define([b4_strictfp_if], -[b4_percent_define_flag_if([strictfp], [$1], [$2])]) +# The declaration of the parser class ("class YYParser"), with all its +# qualifiers/annotations. +b4_percent_define_default([[api.parser.abstract]], [[false]]) +b4_percent_define_default([[api.parser.final]], [[false]]) +b4_percent_define_default([[api.parser.public]], [[false]]) +b4_percent_define_default([[api.parser.strictfp]], [[false]]) + +m4_define([b4_parser_class_declaration], +[b4_percent_define_get3([api.parser.annotations], [], [ ])dnl +b4_percent_define_flag_if([api.parser.public], [public ])dnl +b4_percent_define_flag_if([api.parser.abstract], [abstract ])dnl +b4_percent_define_flag_if([api.parser.final], [final ])dnl +b4_percent_define_flag_if([api.parser.strictfp], [strictfp ])dnl +[class ]b4_parser_class[]dnl +b4_percent_define_get3([api.parser.extends], [ extends ])dnl +b4_percent_define_get3([api.parser.implements], [ implements ])]) # b4_lexer_if(TRUE, FALSE) @@ -180,7 +172,7 @@ b4_percent_define_check_kind([[extends]], [code], [deprecated]) b4_percent_define_check_kind([[implements]], [code], [deprecated]) b4_percent_define_check_kind([[init_throws]], [code], [deprecated]) b4_percent_define_check_kind([[lex_throws]], [code], [deprecated]) -b4_percent_define_check_kind([[parser_class_name]], [code], [deprecated]) +b4_percent_define_check_kind([[api.parser.class]], [code], [deprecated]) b4_percent_define_check_kind([[throws]], [code], [deprecated]) @@ -195,8 +187,8 @@ b4_percent_define_default([[api.value.type]], [[Object]]) # %name-prefix m4_define_default([b4_prefix], [[YY]]) -b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser]) -m4_define([b4_parser_class_name], [b4_percent_define_get([[parser_class_name]])]) +b4_percent_define_default([[api.parser.class]], [b4_prefix[]Parser]) +m4_define([b4_parser_class], [b4_percent_define_get([[api.parser.class]])]) b4_percent_define_default([[lex_throws]], [[java.io.IOException]]) m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])]) @@ -219,21 +211,40 @@ m4_define([b4_position_type], [b4_percent_define_get([[api.position.type]])]) ## ----------------- ## -# b4_lhs_value([TYPE]) -# -------------------- -# Expansion of $$. +# b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG]) +# ---------------------------------------------- +# See README. +m4_define([b4_symbol_value], +[m4_ifval([$3], + [(($3)($1))], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [((b4_symbol([$2], [type]))($1))], + [$1])], + [$1])])]) + + +# b4_lhs_value([SYMBOL-NUM], [TYPE]) +# ---------------------------------- +# See README. m4_define([b4_lhs_value], [yyval]) -# b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) -# -------------------------------------- -# Expansion of $NUM, where the current rule has RULE-LENGTH -# symbols on RHS. +# b4_rhs_data(RULE-LENGTH, POS) +# ----------------------------- +# See README. +m4_define([b4_rhs_data], +[yystack.valueAt (b4_subtract($@))]) + +# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) +# -------------------------------------------------- +# See README. # # In this simple implementation, %token and %type have class names # between the angle brackets. m4_define([b4_rhs_value], -[(m4_ifval($3, [($3)])[](yystack.valueAt ($1-($2))))]) +[b4_symbol_value([b4_rhs_data([$1], [$2])], [$3], [$4])]) + # b4_lhs_location() # ----------------- @@ -242,12 +253,12 @@ m4_define([b4_lhs_location], [(yyloc)]) -# b4_rhs_location(RULE-LENGTH, NUM) +# b4_rhs_location(RULE-LENGTH, POS) # --------------------------------- -# Expansion of @NUM, where the current rule has RULE-LENGTH symbols +# Expansion of @POS, where the current rule has RULE-LENGTH symbols # on RHS. m4_define([b4_rhs_location], -[yystack.locationAt ($1-($2))]) +[yystack.locationAt (b4_subtract($@))]) # b4_lex_param diff --git a/bison/data/lalr1.cc b/bison/data/skeletons/lalr1.cc similarity index 77% rename from bison/data/lalr1.cc rename to bison/data/skeletons/lalr1.cc index c2f62bd..09f4259 100644 --- a/bison/data/lalr1.cc +++ b/bison/data/skeletons/lalr1.cc @@ -1,6 +1,6 @@ # C++ skeleton for Bison -# Copyright (C) 2002-2015, 2018 Free Software Foundation, Inc. +# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,11 +15,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -m4_include(b4_pkgdatadir/[c++.m4]) +m4_include(b4_skeletonsdir/[c++.m4]) # api.value.type=variant is valid. m4_define([b4_value_type_setup_variant]) + # b4_integral_parser_table_declare(TABLE-NAME, CONTENT, COMMENT) # -------------------------------------------------------------- # Declare "parser::yy_" whose contents is CONTENT. @@ -34,65 +35,68 @@ m4_define([b4_integral_parser_table_declare], # Define "parser::yy_" whose contents is CONTENT. m4_define([b4_integral_parser_table_define], [ const b4_int_type_for([$2]) - b4_parser_class_name::yy$1_[[]] = + b4_parser_class::yy$1_[[]] = { $2 };dnl ]) -# b4_symbol_value_template(VAL, [TYPE]) -# ------------------------------------- +# b4_symbol_value_template(VAL, SYMBOL-NUM, [TYPE]) +# ------------------------------------------------- # Same as b4_symbol_value, but used in a template method. It makes # a difference when using variants. Note that b4_value_type_setup_union # overrides b4_symbol_value, so we must override it again. m4_copy([b4_symbol_value], [b4_symbol_value_template]) m4_append([b4_value_type_setup_union], - [m4_copy_force([b4_symbol_value_union], [b4_symbol_value_template])]) +[m4_copy_force([b4_symbol_value_union], [b4_symbol_value_template])]) -# b4_lhs_value([TYPE]) -# -------------------- -# Expansion of $$. +# b4_lhs_value(SYMBOL-NUM, [TYPE]) +# -------------------------------- +# See README. m4_define([b4_lhs_value], - [b4_symbol_value([yylhs.value], [$1])]) +[b4_symbol_value([yylhs.value], [$1], [$2])]) # b4_lhs_location() # ----------------- # Expansion of @$. m4_define([b4_lhs_location], - [yylhs.location]) +[yylhs.location]) -# b4_rhs_data(RULE-LENGTH, NUM) +# b4_rhs_data(RULE-LENGTH, POS) # ----------------------------- -# Return the data corresponding to the symbol #NUM, where the current -# rule has RULE-LENGTH symbols on RHS. +# See README. m4_define([b4_rhs_data], - [yystack_@{b4_subtract($@)@}]) +[yystack_@{b4_subtract($@)@}]) -# b4_rhs_state(RULE-LENGTH, NUM) +# b4_rhs_state(RULE-LENGTH, POS) # ------------------------------ -# The state corresponding to the symbol #NUM, where the current +# The state corresponding to the symbol #POS, where the current # rule has RULE-LENGTH symbols on RHS. m4_define([b4_rhs_state], - [b4_rhs_data([$1], [$2]).state]) +[b4_rhs_data([$1], [$2]).state]) + +# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) +# -------------------------------------------------- +# See README. +m4_define([_b4_rhs_value], +[b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3], [$4])]) -# b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) -# -------------------------------------- -# Expansion of $NUM, where the current rule has RULE-LENGTH -# symbols on RHS. m4_define([b4_rhs_value], - [b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3])]) +[b4_percent_define_ifdef([api.value.automove], + [YY_MOVE (_b4_rhs_value($@))], + [_b4_rhs_value($@)])]) -# b4_rhs_location(RULE-LENGTH, NUM) +# b4_rhs_location(RULE-LENGTH, POS) # --------------------------------- -# Expansion of @NUM, where the current rule has RULE-LENGTH symbols +# Expansion of @POS, where the current rule has RULE-LENGTH symbols # on RHS. m4_define([b4_rhs_location], - [b4_rhs_data([$1], [$2]).location]) +[b4_rhs_data([$1], [$2]).location]) # b4_symbol_action(SYMBOL-NUM, KIND) @@ -103,10 +107,10 @@ m4_define([b4_symbol_action], [b4_symbol_if([$1], [has_$2], [m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl b4_dollar_pushdef([yysym.value], - b4_symbol_if([$1], [has_type], - [m4_dquote(b4_symbol([$1], [type]))]), - [yysym.location])dnl - b4_symbol_case_([$1]) + [$1], + [], + [yysym.location])dnl + _b4_symbol_case([$1])[]dnl b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])]) b4_symbol([$1], [$2]) b4_syncline([@oline@], [@ofile@]) @@ -131,21 +135,22 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))])]) m4_pushdef([b4_copyright_years], - [2002-2015, 2018]) + [2002-2015, 2018-2019]) -m4_define([b4_parser_class_name], - [b4_percent_define_get([[parser_class_name]])]) +m4_define([b4_parser_class], + [b4_percent_define_get([[api.parser.class]])]) b4_bison_locations_if([# Backward compatibility. m4_define([b4_location_constructors]) - m4_include(b4_pkgdatadir/[location.cc])]) -m4_include(b4_pkgdatadir/[stack.hh]) -b4_variant_if([m4_include(b4_pkgdatadir/[variant.hh])]) + m4_include(b4_skeletonsdir/[location.cc])]) +m4_include(b4_skeletonsdir/[stack.hh]) +b4_variant_if([m4_include(b4_skeletonsdir/[variant.hh])]) + # b4_shared_declarations(hh|cc) # ----------------------------- # Declaration that might either go into the header (if --defines, $1 = hh) -# or open coded in the parser body. +# or in the implementation file. m4_define([b4_shared_declarations], [b4_percent_code_get([[requires]])[ ]b4_parse_assert_if([# include ])[ @@ -153,32 +158,36 @@ m4_define([b4_shared_declarations], # include # include # include -# include ]b4_defines_if([[ -# include "stack.hh" -]b4_bison_locations_if([[# include "location.hh"]])])[ +# include + +]b4_cxx_portability[ +]m4_ifdef([b4_location_include], + [[# include ]b4_location_include])[ ]b4_variant_if([b4_variant_includes])[ ]b4_attribute_define[ ]b4_null_define[ + ]b4_YYDEBUG_define[ ]b4_namespace_open[ -]b4_defines_if([], -[b4_stack_define -b4_bison_locations_if([b4_position_define -b4_location_define])])[ - -]b4_variant_if([b4_variant_define])[ +]b4_bison_locations_if([m4_ifndef([b4_location_file], + [b4_location_define])])[ /// A Bison parser. - class ]b4_parser_class_name[ + class ]b4_parser_class[ { public: ]b4_public_types_declare[ +]b4_symbol_type_define[ /// Build a parser object. - ]b4_parser_class_name[ (]b4_parse_param_decl[); - virtual ~]b4_parser_class_name[ (); + ]b4_parser_class[ (]b4_parse_param_decl[); + virtual ~]b4_parser_class[ (); + + /// Parse. An alias for parse (). + /// \returns 0 iff parsing succeeded. + int operator() (); /// Parse. /// \returns 0 iff parsing succeeded. @@ -206,10 +215,12 @@ b4_location_define])])[ /// Report a syntax error. void error (const syntax_error& err); +]b4_token_constructor_define[ + private: /// This class is not copyable. - ]b4_parser_class_name[ (const ]b4_parser_class_name[&); - ]b4_parser_class_name[& operator= (const ]b4_parser_class_name[&); + ]b4_parser_class[ (const ]b4_parser_class[&); + ]b4_parser_class[& operator= (const ]b4_parser_class[&); /// State numbers. typedef int state_type; @@ -256,8 +267,9 @@ b4_location_define])])[ /// Print the state stack on the debug stream. virtual void yystack_print_ (); - // Debugging. + /// Debugging level. int yydebug_; + /// Debug stream. std::ostream* yycdebug_; /// \brief Display a symbol type, value and location. @@ -279,26 +291,26 @@ b4_location_define])])[ struct by_state { /// Default constructor. - by_state (); + by_state () YY_NOEXCEPT; /// The symbol type as needed by the constructor. typedef state_type kind_type; /// Constructor. - by_state (kind_type s); + by_state (kind_type s) YY_NOEXCEPT; /// Copy constructor. - by_state (const by_state& other); + by_state (const by_state& that) YY_NOEXCEPT; /// Record that this symbol is empty. - void clear (); + void clear () YY_NOEXCEPT; /// Steal the symbol type from \a that. void move (by_state& that); /// The (internal) type number (corresponding to \a state). /// \a empty_symbol when empty. - symbol_number_type type_get () const; + symbol_number_type type_get () const YY_NOEXCEPT; /// The state number used to denote an empty symbol. enum { empty_state = -1 }; @@ -315,14 +327,19 @@ b4_location_define])])[ typedef basic_symbol super_type; /// Construct an empty symbol. stack_symbol_type (); - /// Copy construct (for efficiency). - stack_symbol_type (const stack_symbol_type& that); + /// Move or copy construction. + stack_symbol_type (YY_RVREF (stack_symbol_type) that); /// Steal the contents from \a sym to build this. - stack_symbol_type (state_type s, symbol_type& sym); - /// Assignment, needed by push_back. - stack_symbol_type& operator= (const stack_symbol_type& that); + stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) sym); +#if YY_CPLUSPLUS < 201103L + /// Assignment, needed by push_back by some old implementations. + /// Moves the contents of that. + stack_symbol_type& operator= (stack_symbol_type& that); +#endif }; +]b4_stack_define[ + /// Stack type. typedef stack stack_type; @@ -332,20 +349,20 @@ b4_location_define])])[ /// Push a new state on the stack. /// \param m a debug message to display /// if null, no trace is output. - /// \param s the symbol + /// \param sym the symbol /// \warning the contents of \a s.value is stolen. - void yypush_ (const char* m, stack_symbol_type& s); + void yypush_ (const char* m, YY_MOVE_REF (stack_symbol_type) sym); /// Push a new look ahead token on the state on the stack. /// \param m a debug message to display /// if null, no trace is output. /// \param s the state /// \param sym the symbol (for its value and location). - /// \warning the contents of \a s.value is stolen. - void yypush_ (const char* m, state_type s, symbol_type& sym); + /// \warning the contents of \a sym.value is stolen. + void yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym); - /// Pop \a n symbols the three stacks. - void yypop_ (unsigned n = 1); + /// Pop \a n symbols from the stack. + void yypop_ (int n = 1); /// Constants. enum @@ -371,12 +388,16 @@ b4_location_define])])[ #ifndef ]b4_api_PREFIX[STYPE // Redirection for backward compatibility. -# define ]b4_api_PREFIX[STYPE b4_namespace_ref::b4_parser_class_name::semantic_type +# define ]b4_api_PREFIX[STYPE b4_namespace_ref::b4_parser_class::semantic_type #endif ])[ ]b4_percent_code_get([[provides]])[ ]]) +## -------------- ## +## Output files. ## +## -------------- ## + b4_defines_if( [b4_output_begin([b4_spec_defines_file]) b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++]) @@ -388,30 +409,28 @@ b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++]) // C++ LALR(1) parser skeleton written by Akim Demaille. +]b4_disclaimer[ ]b4_cpp_guard_open([b4_spec_defines_file])[ ]b4_shared_declarations(hh)[ ]b4_cpp_guard_close([b4_spec_defines_file]) -b4_output_end() +b4_output_end ]) -b4_output_begin([b4_parser_file_name]) -b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++]) -b4_percent_code_get([[top]])[]dnl +b4_output_begin([b4_parser_file_name])[ +]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])[ +]b4_disclaimer[ +]b4_percent_code_get([[top]])[]dnl m4_if(b4_prefix, [yy], [], [ // Take the name prefix into account. -#define yylex b4_prefix[]lex])[ +[#]define yylex b4_prefix[]lex])[ -// First part of user declarations. ]b4_user_pre_prologue[ -]b4_null_define[ - ]b4_defines_if([[#include "@basename(]b4_spec_defines_file[@)"]], [b4_shared_declarations([cc])])[ -// User implementation prologue. ]b4_user_post_prologue[ ]b4_percent_code_get[ @@ -455,7 +474,7 @@ m4_if(b4_prefix, [yy], [], { \ *yycdebug_ << Title << ' '; \ yy_print_ (*yycdebug_, Symbol); \ - *yycdebug_ << std::endl; \ + *yycdebug_ << '\n'; \ } \ } while (false) @@ -496,11 +515,11 @@ m4_if(b4_prefix, [yy], [], apostrophe, a comma, or backslash (other than backslash-backslash). YYSTR is taken from yytname. */ std::string - ]b4_parser_class_name[::yytnamerr_ (const char *yystr) + ]b4_parser_class[::yytnamerr_ (const char *yystr) { if (*yystr == '"') { - std::string yyr = ""; + std::string yyr; char const *yyp = yystr; for (;;) @@ -513,7 +532,10 @@ m4_if(b4_prefix, [yy], [], case '\\': if (*++yyp != '\\') goto do_not_strip_quotes; - // Fall through. + else + goto append; + + append: default: yyr += *yyp; break; @@ -529,7 +551,7 @@ m4_if(b4_prefix, [yy], [], ]])[ /// Build a parser object. - ]b4_parser_class_name::b4_parser_class_name[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [ + ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [ :])[ #if ]b4_api_PREFIX[DEBUG ]m4_ifset([b4_parse_param], [ ], [ :])[yydebug_ (false), @@ -537,9 +559,11 @@ m4_if(b4_prefix, [yy], [], #endif]b4_parse_param_cons[ {} - ]b4_parser_class_name::~b4_parser_class_name[ () + ]b4_parser_class::~b4_parser_class[ () {} + ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW + {} /*---------------. | Symbol types. | @@ -548,33 +572,33 @@ m4_if(b4_prefix, [yy], [], ]b4_token_ctor_if([], [b4_public_types_define([cc])])[ // by_state. - ]b4_parser_class_name[::by_state::by_state () + ]b4_parser_class[::by_state::by_state () YY_NOEXCEPT : state (empty_state) {} - ]b4_parser_class_name[::by_state::by_state (const by_state& other) - : state (other.state) + ]b4_parser_class[::by_state::by_state (const by_state& that) YY_NOEXCEPT + : state (that.state) {} void - ]b4_parser_class_name[::by_state::clear () + ]b4_parser_class[::by_state::clear () YY_NOEXCEPT { state = empty_state; } void - ]b4_parser_class_name[::by_state::move (by_state& that) + ]b4_parser_class[::by_state::move (by_state& that) { state = that.state; that.clear (); } - ]b4_parser_class_name[::by_state::by_state (state_type s) + ]b4_parser_class[::by_state::by_state (state_type s) YY_NOEXCEPT : state (s) {} - ]b4_parser_class_name[::symbol_number_type - ]b4_parser_class_name[::by_state::type_get () const + ]b4_parser_class[::symbol_number_type + ]b4_parser_class[::by_state::type_get () const YY_NOEXCEPT { if (state == empty_state) return empty_symbol; @@ -582,41 +606,47 @@ m4_if(b4_prefix, [yy], [], return yystos_[state]; } - ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type () + ]b4_parser_class[::stack_symbol_type::stack_symbol_type () {} - ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (const stack_symbol_type& that) - : super_type (that.state]b4_locations_if([, that.location])[) - { - ]b4_variant_if([b4_symbol_variant([that.type_get ()], - [value], [copy], [that.value])], - [[value = that.value;]])[ + ]b4_parser_class[::stack_symbol_type::stack_symbol_type (YY_RVREF (stack_symbol_type) that) + : super_type (YY_MOVE (that.state)]b4_variant_if([], [, YY_MOVE (that.value)])b4_locations_if([, YY_MOVE (that.location)])[) + {]b4_variant_if([ + b4_symbol_variant([that.type_get ()], + [value], [YY_MOVE_OR_COPY], [YY_MOVE (that.value)])])[ +#if 201103L <= YY_CPLUSPLUS + // that is emptied. + that.state = empty_state; +#endif } - ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type (state_type s, symbol_type& that) - : super_type (s]b4_variant_if([], [, that.value])[]b4_locations_if([, that.location])[) + ]b4_parser_class[::stack_symbol_type::stack_symbol_type (state_type s, YY_MOVE_REF (symbol_type) that) + : super_type (s]b4_variant_if([], [, YY_MOVE (that.value)])[]b4_locations_if([, YY_MOVE (that.location)])[) {]b4_variant_if([ b4_symbol_variant([that.type_get ()], - [value], [move], [that.value])])[ + [value], [move], [YY_MOVE (that.value)])])[ // that is emptied. that.type = empty_symbol; } - ]b4_parser_class_name[::stack_symbol_type& - ]b4_parser_class_name[::stack_symbol_type::operator= (const stack_symbol_type& that) +#if YY_CPLUSPLUS < 201103L + ]b4_parser_class[::stack_symbol_type& + ]b4_parser_class[::stack_symbol_type::operator= (stack_symbol_type& that) { state = that.state; ]b4_variant_if([b4_symbol_variant([that.type_get ()], - [value], [copy], [that.value])], + [value], [move], [that.value])], [[value = that.value;]])[]b4_locations_if([ location = that.location;])[ + // that is emptied. + that.state = empty_state; return *this; } - +#endif template void - ]b4_parser_class_name[::yy_destroy_ (const char* yymsg, basic_symbol& yysym) const + ]b4_parser_class[::yy_destroy_ (const char* yymsg, basic_symbol& yysym) const { if (yymsg) YY_SYMBOL_PRINT (yymsg, yysym);]b4_variant_if([], [ @@ -628,16 +658,18 @@ m4_if(b4_prefix, [yy], [], #if ]b4_api_PREFIX[DEBUG template void - ]b4_parser_class_name[::yy_print_ (std::ostream& yyo, + ]b4_parser_class[::yy_print_ (std::ostream& yyo, const basic_symbol& yysym) const { std::ostream& yyoutput = yyo; YYUSE (yyoutput); symbol_number_type yytype = yysym.type_get (); +#if defined __GNUC__ && ! defined __clang__ && ! defined __ICC && __GNUC__ * 100 + __GNUC_MINOR__ <= 408 // Avoid a (spurious) G++ 4.8 warning about "array subscript is // below array bounds". if (yysym.empty ()) std::abort (); +#endif yyo << (yytype < yyntokens_ ? "token" : "nterm") << ' ' << yytname_[yytype] << " ("]b4_locations_if([ << yysym.location << ": "])[; @@ -647,55 +679,59 @@ m4_if(b4_prefix, [yy], [], #endif void - ]b4_parser_class_name[::yypush_ (const char* m, state_type s, symbol_type& sym) + ]b4_parser_class[::yypush_ (const char* m, YY_MOVE_REF (stack_symbol_type) sym) { - stack_symbol_type t (s, sym); - yypush_ (m, t); + if (m) + YY_SYMBOL_PRINT (m, sym); + yystack_.push (YY_MOVE (sym)); } void - ]b4_parser_class_name[::yypush_ (const char* m, stack_symbol_type& s) + ]b4_parser_class[::yypush_ (const char* m, state_type s, YY_MOVE_REF (symbol_type) sym) { - if (m) - YY_SYMBOL_PRINT (m, s); - yystack_.push (s); +#if 201103L <= YY_CPLUSPLUS + yypush_ (m, stack_symbol_type (s, std::move (sym))); +#else + stack_symbol_type ss (s, sym); + yypush_ (m, ss); +#endif } void - ]b4_parser_class_name[::yypop_ (unsigned n) + ]b4_parser_class[::yypop_ (int n) { yystack_.pop (n); } #if ]b4_api_PREFIX[DEBUG std::ostream& - ]b4_parser_class_name[::debug_stream () const + ]b4_parser_class[::debug_stream () const { return *yycdebug_; } void - ]b4_parser_class_name[::set_debug_stream (std::ostream& o) + ]b4_parser_class[::set_debug_stream (std::ostream& o) { yycdebug_ = &o; } - ]b4_parser_class_name[::debug_level_type - ]b4_parser_class_name[::debug_level () const + ]b4_parser_class[::debug_level_type + ]b4_parser_class[::debug_level () const { return yydebug_; } void - ]b4_parser_class_name[::set_debug_level (debug_level_type l) + ]b4_parser_class[::set_debug_level (debug_level_type l) { yydebug_ = l; } #endif // ]b4_api_PREFIX[DEBUG - ]b4_parser_class_name[::state_type - ]b4_parser_class_name[::yy_lr_goto_state_ (state_type yystate, int yysym) + ]b4_parser_class[::state_type + ]b4_parser_class[::yy_lr_goto_state_ (state_type yystate, int yysym) { int yyr = yypgoto_[yysym - yyntokens_] + yystate; if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate) @@ -705,19 +741,25 @@ m4_if(b4_prefix, [yy], [], } bool - ]b4_parser_class_name[::yy_pact_value_is_default_ (int yyvalue) + ]b4_parser_class[::yy_pact_value_is_default_ (int yyvalue) { return yyvalue == yypact_ninf_; } bool - ]b4_parser_class_name[::yy_table_value_is_error_ (int yyvalue) + ]b4_parser_class[::yy_table_value_is_error_ (int yyvalue) { return yyvalue == yytable_ninf_; } int - ]b4_parser_class_name[::parse () + ]b4_parser_class[::operator() () + { + return parse (); + } + + int + ]b4_parser_class[::parse () { // State. int yyn; @@ -741,11 +783,10 @@ m4_if(b4_prefix, [yy], [], try #endif // YY_EXCEPTIONS { - YYCDEBUG << "Starting parse" << std::endl; + YYCDEBUG << "Starting parse\n"; ]m4_ifdef([b4_initial_action], [ -b4_dollar_pushdef([yyla.value], [], [yyla.location])dnl - // User initialization code. +b4_dollar_pushdef([yyla.value], [], [], [yyla.location])dnl b4_user_initial_action b4_dollar_popdef])[]dnl @@ -754,19 +795,24 @@ b4_dollar_popdef])[]dnl location values to have been already stored, initialize these stacks with a primary value. */ yystack_.clear (); - yypush_ (YY_NULLPTR, 0, yyla); + yypush_ (YY_NULLPTR, 0, YY_MOVE (yyla)); - // A new symbol was pushed on the stack. + /*-----------------------------------------------. + | yynewstate -- push a new symbol on the stack. | + `-----------------------------------------------*/ yynewstate: - YYCDEBUG << "Entering state " << yystack_[0].state << std::endl; + YYCDEBUG << "Entering state " << yystack_[0].state << '\n'; // Accept? if (yystack_[0].state == yyfinal_) - goto yyacceptlab; + YYACCEPT; goto yybackup; - // Backup. + + /*-----------. + | yybackup. | + `-----------*/ yybackup: // Try to take a decision without lookahead. yyn = yypact_[yystack_[0].state]; @@ -788,6 +834,7 @@ b4_dollar_popdef])[]dnl #if YY_EXCEPTIONS catch (const syntax_error& yyexc) { + YYCDEBUG << "Caught exception: " << yyexc.what() << '\n'; error (yyexc); goto yyerrlab1; } @@ -816,9 +863,10 @@ b4_dollar_popdef])[]dnl --yyerrstatus_; // Shift the lookahead token. - yypush_ ("Shifting", yyn, yyla); + yypush_ ("Shifting", yyn, YY_MOVE (yyla)); goto yynewstate; + /*-----------------------------------------------------------. | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ @@ -828,8 +876,9 @@ b4_dollar_popdef])[]dnl goto yyerrlab; goto yyreduce; + /*-----------------------------. - | yyreduce -- Do a reduction. | + | yyreduce -- do a reduction. | `-----------------------------*/ yyreduce: yylen = yyr2_[yyn]; @@ -839,7 +888,7 @@ b4_dollar_popdef])[]dnl /* Variants are always initialized to an empty instance of the correct type. The default '$$ = $1' action is NOT applied when using variants. */ - b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build])], [ + b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [emplace])], [ /* If YYLEN is nonzero, implement the default value of the action: '$$ = $1'. Otherwise, use the top of the stack. @@ -854,8 +903,8 @@ b4_dollar_popdef])[]dnl [ // Default location. { - slice slice (yystack_, yylen); - YYLLOC_DEFAULT (yylhs.location, slice, yylen); + stack_type::slice range (yystack_, yylen); + YYLLOC_DEFAULT (yylhs.location, range, yylen); yyerror_range[1].location = yylhs.location; }]])[ @@ -875,6 +924,7 @@ b4_dollar_popdef])[]dnl #if YY_EXCEPTIONS catch (const syntax_error& yyexc) { + YYCDEBUG << "Caught exception: " << yyexc.what() << '\n'; error (yyexc); YYERROR; } @@ -885,10 +935,11 @@ b4_dollar_popdef])[]dnl YY_STACK_PRINT (); // Shift the result of the reduction. - yypush_ (YY_NULLPTR, yylhs); + yypush_ (YY_NULLPTR, YY_MOVE (yylhs)); } goto yynewstate; + /*--------------------------------------. | yyerrlab -- here on detecting error. | `--------------------------------------*/ @@ -926,18 +977,18 @@ b4_dollar_popdef])[]dnl | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: - - /* Pacify compilers like GCC when the user code never invokes - YYERROR and the label yyerrorlab therefore never appears in user - code. */ + /* Pacify compilers when the user code never invokes YYERROR and + the label yyerrorlab therefore never appears in user code. */ if (false) - goto yyerrorlab; + YYERROR; + /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ yypop_ (yylen); yylen = 0; goto yyerrlab1; + /*-------------------------------------------------------------. | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ @@ -974,20 +1025,30 @@ b4_dollar_popdef])[]dnl // Shift the error token. error_token.state = yyn; - yypush_ ("Shifting", error_token); + yypush_ ("Shifting", YY_MOVE (error_token)); } goto yynewstate; - // Accept. + + /*-------------------------------------. + | yyacceptlab -- YYACCEPT comes here. | + `-------------------------------------*/ yyacceptlab: yyresult = 0; goto yyreturn; - // Abort. + + /*-----------------------------------. + | yyabortlab -- YYABORT comes here. | + `-----------------------------------*/ yyabortlab: yyresult = 1; goto yyreturn; + + /*-----------------------------------------------------. + | yyreturn -- parsing is finished, return the result. | + `-----------------------------------------------------*/ yyreturn: if (!yyla.empty ()) yy_destroy_ ("Cleanup: discarding lookahead", yyla); @@ -1006,8 +1067,7 @@ b4_dollar_popdef])[]dnl #if YY_EXCEPTIONS catch (...) { - YYCDEBUG << "Exception caught: cleaning lookahead and stack" - << std::endl; + YYCDEBUG << "Exception caught: cleaning lookahead and stack\n"; // Do not try to display the values of the reclaimed symbols, // as their printers might throw an exception. if (!yyla.empty ()) @@ -1024,7 +1084,7 @@ b4_dollar_popdef])[]dnl } void - ]b4_parser_class_name[::error (const syntax_error& yyexc) + ]b4_parser_class[::error (const syntax_error& yyexc) { error (]b4_join(b4_locations_if([yyexc.location]), [[yyexc.what ()]])[); @@ -1032,7 +1092,7 @@ b4_dollar_popdef])[]dnl // Generate an error message. std::string - ]b4_parser_class_name[::yysyntax_error_ (]dnl + ]b4_parser_class[::yysyntax_error_ (]dnl b4_error_verbose_if([state_type yystate, const symbol_type& yyla], [state_type, const symbol_type&])[) const {]b4_error_verbose_if([[ @@ -1131,9 +1191,9 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], } - const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class_name::yypact_ninf_ = b4_pact_ninf[; + const ]b4_int_type(b4_pact_ninf, b4_pact_ninf) b4_parser_class::yypact_ninf_ = b4_pact_ninf[; - const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class_name::yytable_ninf_ = b4_table_ninf[; + const ]b4_int_type(b4_table_ninf, b4_table_ninf) b4_parser_class::yytable_ninf_ = b4_table_ninf[; ]b4_parser_tables_define[ @@ -1141,7 +1201,7 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. // First, the terminals, then, starting at \a yyntokens_, nonterminals. const char* - const ]b4_parser_class_name[::yytname_[] = + const ]b4_parser_class[::yytname_[] = { ]b4_tname[ }; @@ -1151,7 +1211,7 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], // Print the state stack on the debug stream. void - ]b4_parser_class_name[::yystack_print_ () + ]b4_parser_class[::yystack_print_ () { *yycdebug_ << "Stack now"; for (stack_type::const_iterator @@ -1159,18 +1219,18 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], i_end = yystack_.end (); i != i_end; ++i) *yycdebug_ << ' ' << i->state; - *yycdebug_ << std::endl; + *yycdebug_ << '\n'; } // Report on the debug stream that the rule \a yyrule is going to be reduced. void - ]b4_parser_class_name[::yy_reduce_print_ (int yyrule) + ]b4_parser_class[::yy_reduce_print_ (int yyrule) { unsigned yylno = yyrline_[yyrule]; int yynrhs = yyr2_[yyrule]; // Print the symbols being reduced, and their result. *yycdebug_ << "Reducing stack by rule " << yyrule - 1 - << " (line " << yylno << "):" << std::endl; + << " (line " << yylno << "):\n"; // The symbols being reduced. for (int yyi = 0; yyi < yynrhs; yyi++) YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", @@ -1181,7 +1241,7 @@ b4_error_verbose_if([state_type yystate, const symbol_type& yyla], ]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[ ]b4_namespace_close[ ]b4_epilogue[]dnl -b4_output_end() +b4_output_end m4_popdef([b4_copyright_years])dnl diff --git a/bison/data/skeletons/lalr1.d b/bison/data/skeletons/lalr1.d new file mode 100644 index 0000000..770e537 --- /dev/null +++ b/bison/data/skeletons/lalr1.d @@ -0,0 +1,897 @@ +# Java skeleton for Bison -*- autoconf -*- + +# Copyright (C) 2007-2011, 2019 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +m4_include(b4_skeletonsdir/[d.m4]) + + +m4_divert_push(0)dnl +@output(b4_parser_file_name@)@ +b4_copyright([Skeleton implementation for Bison LALR(1) parsers in D], + [2007-2012, 2019]) + +b4_percent_define_ifdef([package], [module b4_percent_define_get([package]); +])[ +version(D_Version2) { +} else { + static assert(false, "need compiler for D Version 2"); +} + +]b4_user_pre_prologue[ +]b4_user_post_prologue[ +]b4_percent_code_get([[imports]])[ +import std.format; + +/** + * A Bison parser, automatically generated from ]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[. + * + * @@author LALR (1) parser skeleton written by Paolo Bonzini. + * Port to D language was done by Oliver Mangold. + */ + +/** + * Communication interface between the scanner and the Bison-generated + * parser ]b4_parser_class[. + */ +public interface Lexer +{ + ]b4_locations_if([[/** + * Method to retrieve the beginning position of the last scanned token. + * @@return the position at which the last scanned token starts. */ + @@property ]b4_position_type[ startPos (); + + /** + * Method to retrieve the ending position of the last scanned token. + * @@return the first position beyond the last scanned token. */ + @@property ]b4_position_type[ endPos ();]])[ + + /** + * Method to retrieve the semantic value of the last scanned token. + * @@return the semantic value of the last scanned token. */ + @@property ]b4_yystype[ semanticVal (); + + /** + * Entry point for the scanner. Returns the token identifier corresponding + * to the next token and prepares to return the semantic value + * ]b4_locations_if([and beginning/ending positions ])[of the token. + * @@return the token identifier corresponding to the next token. */ + YYTokenType yylex (); + + /** + * Entry point for error reporting. Emits an error + * ]b4_locations_if([referring to the given location ])[in a user-defined way. + * + * ]b4_locations_if([[@@param loc The location of the element to which the + * error message is related]])[ + * @@param s The string for the error message. */ + void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[string s); +} + +private final struct YYStackElement{ + int state; + ]b4_yystype[ value; + ]b4_locations_if(b4_location_type[[] location;])[ +} + +private final struct YYStack { + private YYStackElement[] stack = []; + + public final @@property ulong height() + { + return stack.length; + } + + public final void push (int state, ]b4_yystype[ value]dnl +b4_locations_if([, ref ]b4_location_type[ loc])[) + { + stack ~= YYStackElement(state, value]b4_locations_if([, loc])[); + } + + public final void pop () + { + pop (1); + } + + public final void pop (int num) + { + stack.length -= num; + } + + public final int stateAt (int i) + { + return stack[$-i-1].state; + } + + ]b4_locations_if([[public final ref ]b4_location_type[ locationAt (int i) + { + return stack[$-i-1].location; + } + + ]])[public final ref ]b4_yystype[ valueAt (int i) + { + return stack[$-i-1].value; + } + + // Print the state stack on the debug stream. + public final void print (File stream) + { + stream.write ("Stack now"); + for (int i = 0; i < stack.length; i++) + stream.write (" %d", stack[i].state); + stream.writeln (); + } +} +]b4_locations_if(b4_position_type_if([[[ +static assert(__traits(compiles, + (new ]b4_position_type[[1])[0]=(new ]b4_position_type[[1])[0]), + "struct/class ]b4_position_type[ must be default-constructible " + "and assignable"); +static assert(__traits(compiles, (new string[1])[0]=(new ]b4_position_type[).toString()), + "error: struct/class ]b4_position_type[ must have toString method"); +]]], [[ + /** + * A struct denoting a point in the input.*/ +public struct ]b4_position_type[ { + + /** The column index within the line of input. */ + public int column = 1; + /** The line number within an input file. */ + public int line = 1; + /** The name of the input file. */ + public string filename = "(unspecified file)"; + + /** + * Return a string representation of the position. */ + public string toString() const { + return format("%s:%d.%d", filename, line, column); + } +} +]])b4_location_type_if([[[ +static assert(__traits(compiles, (new ]b4_location_type[((new ]b4_position_type[[1])[0]))) && + __traits(compiles, (new ]b4_location_type[((new ]b4_position_type[[1])[0], (new ]b4_position_type[[1])[0]))), + "error: struct/class ]b4_location_type[ must have " + "default constructor and constructors this(]b4_position_type[) and this(]b4_position_type[, ]b4_position_type[)."); +static assert(__traits(compiles, (new ]b4_location_type[[1])[0].begin=(new ]b4_location_type[[1])[0].begin) && + __traits(compiles, (new ]b4_location_type[[1])[0].begin=(new ]b4_location_type[[1])[0].end) && + __traits(compiles, (new ]b4_location_type[[1])[0].end=(new ]b4_location_type[[1])[0].begin) && + __traits(compiles, (new ]b4_location_type[[1])[0].end=(new ]b4_location_type[[1])[0].end), + "error: struct/class ]b4_location_type[ must have assignment-compatible " + "members/properties 'begin' and 'end'."); +static assert(__traits(compiles, (new string[1])[0]=(new ]b4_location_type[[1])[0].toString()), + "error: struct/class ]b4_location_type[ must have toString method."); + +private immutable bool yy_location_is_class = !__traits(compiles, *(new ]b4_location_type[((new ]b4_position_type[[1])[0])));]]], [[ +/** + * A class defining a pair of positions. Positions, defined by the + * ]b4_position_type[ class, denote a point in the input. + * Locations represent a part of the input through the beginning + * and ending positions. */ +public class ]b4_location_type[ +{ + /** The first, inclusive, position in the range. */ + public ]b4_position_type[ begin; + + /** The first position beyond the range. */ + public ]b4_position_type[ end; + + /** + * Create a ]b4_location_type[ denoting an empty range located at + * a given point. + * @@param loc The position at which the range is anchored. */ + public this (]b4_position_type[ loc) { + this.begin = this.end = loc; + } + + /** + * Create a ]b4_location_type[ from the endpoints of the range. + * @@param begin The first position included in the range. + * @@param end The first position beyond the range. */ + public this (]b4_position_type[ begin, ]b4_position_type[ end) + { + this.begin = begin; + this.end = end; + } + + /** + * Return a representation of the location. For this to be correct, + * ]b4_position_type[ should override the toString + * method. */ + public const string toString () const { + if (begin==end) + return begin.toString (); + else + return begin.toString () ~ "-" ~ end.toString (); + } +} + +private immutable bool yy_location_is_class = true; + +]]))m4_ifdef([b4_user_union_members], [private union YYSemanticType +{ +b4_user_union_members +};], +[m4_if(b4_tag_seen_flag, 0, +[[private alias int YYSemanticType;]])])[ +]b4_token_enums(b4_tokens)[ +]b4_parser_class_declaration[ +{ + ]b4_identification[ + + /** True if verbose error messages are enabled. */ + public bool errorVerbose = ]b4_flag_value([error_verbose]); + + b4_locations_if([[ + private final ]b4_location_type[ yylloc_from_stack (ref YYStack rhs, int n) + { + static if (yy_location_is_class) { + if (n > 0) + return new ]b4_location_type[ (rhs.locationAt (n-1).begin, rhs.locationAt (0).end); + else + return new ]b4_location_type[ (rhs.locationAt (0).end); + } else { + if (n > 0) + return ]b4_location_type[ (rhs.locationAt (n-1).begin, rhs.locationAt (0).end); + else + return ]b4_location_type[ (rhs.locationAt (0).end); + } + }]])[ + + ]b4_lexer_if([[private class YYLexer implements Lexer { +]b4_percent_code_get([[lexer]])[ + } + + ]])[/** The object doing lexical analysis for us. */ + private Lexer yylexer; + ] + b4_parse_param_vars + +b4_lexer_if([[ + /** + * Instantiates the Bison-generated parser. + */ + public this] (b4_parse_param_decl([b4_lex_param_decl])[) { + this.yylexer = new YYLexer(]b4_lex_param_call[); + this.yyDebugStream = stderr; + ]b4_parse_param_cons[ + } +]]) + + /** + * Instantiates the Bison-generated parser. + * @@param yylexer The scanner that will supply tokens to the parser. + */ + b4_lexer_if([[protected]], [[public]]) [this (]b4_parse_param_decl([[Lexer yylexer]])[) { + this.yylexer = yylexer; + this.yyDebugStream = stderr; + ]b4_parse_param_cons[ + } + + private File yyDebugStream; + + /** + * Return the File on which the debugging output is + * printed. + */ + public File getDebugStream () { return yyDebugStream; } + + /** + * Set the std.File on which the debug output is printed. + * @@param s The stream that is used for debugging output. + */ + public final void setDebugStream(File s) { yyDebugStream = s; } + + private int yydebug = 0; + + /** + * Answer the verbosity of the debugging output; 0 means that all kinds of + * output from the parser are suppressed. + */ + public final int getDebugLevel() { return yydebug; } + + /** + * Set the verbosity of the debugging output; 0 means that all kinds of + * output from the parser are suppressed. + * @@param level The verbosity level for debugging output. + */ + public final void setDebugLevel(int level) { yydebug = level; } + + private final int yylex () { + return yylexer.yylex (); + } + protected final void yyerror (]b4_locations_if(ref [b4_location_type[ loc, ]])[string s) { + yylexer.yyerror (]b4_locations_if([loc, ])[s); + }] + + [protected final void yycdebug (string s) { + if (yydebug > 0) + yyDebugStream.writeln (s); + } + + /** + * Returned by a Bison action in order to stop the parsing process and + * return success (true). */ + public static immutable int YYACCEPT = 0; + + /** + * Returned by a Bison action in order to stop the parsing process and + * return failure (false). */ + public static immutable int YYABORT = 1; + + /** + * Returned by a Bison action in order to start error recovery without + * printing an error message. */ + public static immutable int YYERROR = 2; + + // Internal return codes that are not supported for user semantic + // actions. + private static immutable int YYERRLAB = 3; + private static immutable int YYNEWSTATE = 4; + private static immutable int YYDEFAULT = 5; + private static immutable int YYREDUCE = 6; + private static immutable int YYERRLAB1 = 7; + private static immutable int YYRETURN = 8; +]b4_locations_if([ + private static immutable YYSemanticType yy_semantic_null = cast(YYSemanticType)null;])[ + private int yyerrstatus_ = 0; + + /** + * Return whether error recovery is being done. In this state, the parser + * reads token until it reaches a known state, and then restarts normal + * operation. */ + public final bool recovering () + { + return yyerrstatus_ == 0; + } + + private int yyaction (int yyn, ref YYStack yystack, int yylen) + { + ]b4_yystype[ yyval; + ]b4_locations_if([b4_location_type[ yyloc = yylloc_from_stack (yystack, yylen);]])[ + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. Otherwise, use the top of the stack. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. */ + if (yylen > 0) + yyval = yystack.valueAt (yylen - 1); + else + yyval = yystack.valueAt (0); + + yy_reduce_print (yyn, yystack); + + switch (yyn) + { +]b4_user_actions[ + default: break; + } + + yy_symbol_print ("-> $$ =", yyr1_[yyn], yyval]b4_locations_if([, yyloc])[); + + yystack.pop (yylen); + yylen = 0; + + /* Shift the result of the reduction. */ + yyn = yyr1_[yyn]; + int yystate = yypgoto_[yyn - yyntokens_] + yystack.stateAt (0); + if (0 <= yystate && yystate <= yylast_ + && yycheck_[yystate] == yystack.stateAt (0)) + yystate = yytable_[yystate]; + else + yystate = yydefgoto_[yyn - yyntokens_]; + + yystack.push (yystate, yyval]b4_locations_if([, yyloc])[); + return YYNEWSTATE; + } + + /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + private final string yytnamerr_ (string yystr) + { + if (yystr[0] == '"') + { + string yyr; + strip_quotes: for (int i = 1; i < yystr.length; i++) + switch (yystr[i]) + { + case '\'': + case ',': + break strip_quotes; + + case '\\': + if (yystr[++i] != '\\') + break strip_quotes; + goto default; + default: + yyr ~= yystr[i]; + break; + + case '"': + return yyr; + } + } + else if (yystr=="$end") + return "end of input"; + + return yystr; + } + + /*--------------------------------. + | Print this symbol on YYOUTPUT. | + `--------------------------------*/ + + private final void yy_symbol_print (string s, int yytype, + ref ]b4_yystype[ yyvaluep]dnl +b4_locations_if([, ref ]b4_location_type[ yylocationp])[) + { + if (yydebug > 0) { + string message = s ~ (yytype < yyntokens_ ? " token " : " nterm ") + ~ yytname_[yytype] ~ " ("]b4_locations_if([ + ~ yylocationp.toString() ~ ": "])[; + static if (__traits(compiles, message~=yyvaluep.toString ())) + message ~= yyvaluep.toString (); + else + message ~= format ("%s", &yyvaluep); + message ~= ")"; + yycdebug (message); + } + } + + /** + * Parse input from the scanner that was specified at object construction + * time. Return whether the end of the input was reached successfully. + * + * @@return true if the parsing succeeds. Note that this does not + * imply that there were no syntax errors. + */ + public bool parse () + { + /// Lookahead and lookahead in internal form. + int yychar = yyempty_; + int yytoken = 0; + + /* State. */ + int yyn = 0; + int yylen = 0; + int yystate = 0; + + YYStack yystack; + + /* Error handling. */ + int yynerrs_ = 0; + ]b4_locations_if([/// The location where the error started. + ]b4_location_type[ yyerrloc = null; + + /// ]b4_location_type[ of the lookahead. + ]b4_location_type[ yylloc; + + /// @@$. + ]b4_location_type[ yyloc;])[ + + /// Semantic value of the lookahead. + ]b4_yystype[ yylval; + + int yyresult; + + yycdebug ("Starting parse\n"); + yyerrstatus_ = 0; + +]m4_ifdef([b4_initial_action], [ +m4_pushdef([b4_at_dollar], [yylloc])dnl +m4_pushdef([b4_dollar_dollar], [yylval])dnl + /* User initialization code. */ + b4_user_initial_action +m4_popdef([b4_dollar_dollar])dnl +m4_popdef([b4_at_dollar])])dnl + + [ /* Initialize the stack. */ + yystack.push (yystate, yylval]b4_locations_if([, yylloc])[); + + int label = YYNEWSTATE; + for (;;) + final switch (label) + { + /* New state. Unlike in the C/C++ skeletons, the state is already + pushed when we come here. */ + case YYNEWSTATE: + yycdebug (format("Entering state %d\n", yystate)); + if (yydebug > 0) + yystack.print (yyDebugStream); + + /* Accept? */ + if (yystate == yyfinal_) + return true; + + /* Take a decision. First try without lookahead. */ + yyn = yypact_[yystate]; + if (yy_pact_value_is_default_ (yyn)) + { + label = YYDEFAULT; + break; + } + + /* Read a lookahead token. */ + if (yychar == yyempty_) + { + yycdebug ("Reading a token: "); + yychar = yylex ();] + b4_locations_if([[ + static if (yy_location_is_class) { + yylloc = new ]b4_location_type[(yylexer.startPos, yylexer.endPos); + } else { + yylloc = ]b4_location_type[(yylexer.startPos, yylexer.endPos); + }]]) + yylval = yylexer.semanticVal;[ + } + + /* Convert token to internal form. */ + if (yychar <= YYTokenType.EOF) + { + yychar = yytoken = YYTokenType.EOF; + yycdebug ("Now at end of input.\n"); + } + else + { + yytoken = yytranslate_ (yychar); + yy_symbol_print ("Next token is", + yytoken, yylval]b4_locations_if([, yylloc])[); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yytoken) + label = YYDEFAULT; + + /* <= 0 means reduce or error. */ + else if ((yyn = yytable_[yyn]) <= 0) + { + if (yy_table_value_is_error_ (yyn)) + label = YYERRLAB; + else + { + yyn = -yyn; + label = YYREDUCE; + } + } + else + { + /* Shift the lookahead token. */ + yy_symbol_print ("Shifting", yytoken, + yylval]b4_locations_if([, yylloc])[); + + /* Discard the token being shifted. */ + yychar = yyempty_; + + /* Count tokens shifted since error; after three, turn off error + * status. */ + if (yyerrstatus_ > 0) + --yyerrstatus_; + + yystate = yyn; + yystack.push (yystate, yylval]b4_locations_if([, yylloc])[); + label = YYNEWSTATE; + } + break; + + /*-----------------------------------------------------------. + | yydefault -- do the default action for the current state. | + `-----------------------------------------------------------*/ + case YYDEFAULT: + yyn = yydefact_[yystate]; + if (yyn == 0) + label = YYERRLAB; + else + label = YYREDUCE; + break; + + /*-----------------------------. + | yyreduce -- Do a reduction. | + `-----------------------------*/ + case YYREDUCE: + yylen = yyr2_[yyn]; + label = yyaction (yyn, yystack, yylen); + yystate = yystack.stateAt (0); + break; + + /*------------------------------------. + | yyerrlab -- here on detecting error | + `------------------------------------*/ + case YYERRLAB: + /* If not already recovering from an error, report this error. */ + if (yyerrstatus_ == 0) + { + ++yynerrs_; + if (yychar == yyempty_) + yytoken = yyempty_; + yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken)); + } + + ]b4_locations_if([yyerrloc = yylloc;])[ + if (yyerrstatus_ == 3) + { + /* If just tried and failed to reuse lookahead token after an + * error, discard it. */ + + if (yychar <= YYTokenType.EOF) + { + /* Return failure if at end of input. */ + if (yychar == YYTokenType.EOF) + return false; + } + else + yychar = yyempty_; + } + + /* Else will try to reuse lookahead token after shifting the error + * token. */ + label = YYERRLAB1; + break; + + /*-------------------------------------------------. + | errorlab -- error raised explicitly by YYERROR. | + `-------------------------------------------------*/ + case YYERROR: + + ]b4_locations_if([yyerrloc = yystack.locationAt (yylen - 1);])[ + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + yystack.pop (yylen); + yylen = 0; + yystate = yystack.stateAt (0); + label = YYERRLAB1; + break; + + /*-------------------------------------------------------------. + | yyerrlab1 -- common code for both syntax error and YYERROR. | + `-------------------------------------------------------------*/ + case YYERRLAB1: + yyerrstatus_ = 3; /* Each real token shifted decrements this.xb */ + + for (;;) + { + yyn = yypact_[yystate]; + if (!yy_pact_value_is_default_ (yyn)) + { + yyn += yyterror_; + if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) + { + yyn = yytable_[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yystack.height == 1) + return false; + + ]b4_locations_if([yyerrloc = yystack.locationAt (0);])[ + yystack.pop (); + yystate = yystack.stateAt (0); + if (yydebug > 0) + yystack.print (yyDebugStream); + } + + ]b4_locations_if([ + /* Muck with the stack to setup for yylloc. */ + yystack.push (0, yy_semantic_null, yylloc); + yystack.push (0, yy_semantic_null, yyerrloc); + yyloc = yylloc_from_stack (yystack, 2); + yystack.pop (2);])[ + + /* Shift the error token. */ + yy_symbol_print ("Shifting", yystos_[yyn], + yylval]b4_locations_if([, yyloc])[); + + yystate = yyn; + yystack.push (yyn, yylval]b4_locations_if([, yyloc])[); + label = YYNEWSTATE; + break; + + /* Accept. */ + case YYACCEPT: + return true; + + /* Abort. */ + case YYABORT: + return false; + } + } + + // Generate an error message. + private final string yysyntax_error (int yystate, int tok) + { + if (errorVerbose) + { + /* There are many possibilities here to consider: + - Assume YYFAIL is not used. It's too flawed to consider. + See + + for details. YYERROR is fine as it does not invoke this + function. + - If this state is a consistent state with a default action, + then the only way this function was invoked is if the + default action is an error action. In that case, don't + check for expected tokens because there are none. + - The only way there can be no lookahead present (in tok) is + if this state is a consistent state with a default action. + Thus, detecting the absence of a lookahead is sufficient to + determine that there is no unexpected or expected token to + report. In that case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this + state is a consistent state with a default action. There + might have been a previous inconsistent state, consistent + state with a non-default action, or user semantic action + that manipulated yychar. (However, yychar is currently out + of scope during semantic actions.) + - Of course, the expected token list depends on states to + have correct lookahead information, and it depends on the + parser not to perform extra reductions after fetching a + lookahead from the scanner and before detecting a syntax + error. Thus, state merging (from LALR or IELR) and default + reductions corrupt the expected token list. However, the + list is correct for canonical LR with one exception: it + will still contain any token that will not be accepted due + to an error action in a later state. + */ + if (tok != yyempty_) + { + // FIXME: This method of building the message is not compatible + // with internationalization. + string res = "syntax error, unexpected "; + res ~= yytnamerr_ (yytname_[tok]); + int yyn = yypact_[yystate]; + if (!yy_pact_value_is_default_ (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative + indexes in YYCHECK. In other words, skip the first + -YYN actions for this state because they are default + actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = yylast_ - yyn + 1; + int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; + int count = 0; + for (int x = yyxbegin; x < yyxend; ++x) + if (yycheck_[x + yyn] == x && x != yyterror_ + && !yy_table_value_is_error_ (yytable_[x + yyn])) + ++count; + if (count < 5) + { + count = 0; + for (int x = yyxbegin; x < yyxend; ++x) + if (yycheck_[x + yyn] == x && x != yyterror_ + && !yy_table_value_is_error_ (yytable_[x + yyn])) + { + res ~= count++ == 0 ? ", expecting " : " or "; + res ~= yytnamerr_ (yytname_[x]); + } + } + } + return res; + } + } + + return "syntax error"; + } + + /** + * Whether the given yypact_ value indicates a defaulted state. + * @@param yyvalue the value to check + */ + private static bool yy_pact_value_is_default_ (int yyvalue) + { + return yyvalue == yypact_ninf_; + } + + /** + * Whether the given yytable_ value indicates a syntax error. + * @@param yyvalue the value to check + */ + private static bool yy_table_value_is_error_ (int yyvalue) + { + return yyvalue == yytable_ninf_; + } + + /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ + private static immutable ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[; + + /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If YYTABLE_NINF_, syntax error. */ + private static immutable ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[; + + ]b4_parser_tables_define[ + + /* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding + to YYLEX-NUM. */ + private static immutable ]b4_int_type_for([b4_toknum])[[] + yytoken_number_ = + @{ + ]b4_toknum[ + @}; + + /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at \a yyntokens_, nonterminals. */ + private static immutable string[] yytname_ = + @{ + ]b4_tname[ + @}; + + /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ + private static immutable ]b4_int_type_for([b4_rline])[[] yyrline_ = + @{ + ]b4_rline[ + @}; + + // Report on the debug stream that the rule yyrule is going to be reduced. + private final void yy_reduce_print (int yyrule, ref YYStack yystack) + { + if (yydebug == 0) + return; + + int yylno = yyrline_[yyrule]; + int yynrhs = yyr2_[yyrule]; + /* Print the symbols being reduced, and their result. */ + yycdebug (format("Reducing stack by rule %d (line %d), ", + yyrule - 1, yylno)); + + /* The symbols being reduced. */ + for (int yyi = 0; yyi < yynrhs; yyi++) + yy_symbol_print (format(" $%d =", yyi + 1), + yystos_[yystack.stateAt(yynrhs - (yyi + 1))], + ]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([, + b4_rhs_location(yynrhs, yyi + 1)])[); + } + + /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ + private static immutable ]b4_int_type_for([b4_translate])[[] yytranslate_table_ = + @{ + ]b4_translate[ + @}; + + private static ]b4_int_type_for([b4_translate])[ yytranslate_ (int t) + { + if (t >= 0 && t <= yyuser_token_number_max_) + return yytranslate_table_[t]; + else + return yyundef_token_; + } + + private static immutable int yylast_ = ]b4_last[; + private static immutable int yynnts_ = ]b4_nterms_number[; + private static immutable int yyempty_ = -2; + private static immutable int yyfinal_ = ]b4_final_state_number[; + private static immutable int yyterror_ = 1; + private static immutable int yyerrcode_ = 256; + private static immutable int yyntokens_ = ]b4_tokens_number[; + + private static immutable int yyuser_token_number_max_ = ]b4_user_token_number_max[; + private static immutable int yyundef_token_ = ]b4_undef_token_number[; + +]/* User implementation code. */ +b4_percent_code_get[]dnl + +} + +b4_epilogue +m4_divert_pop(0)dnl diff --git a/bison/data/lalr1.java b/bison/data/skeletons/lalr1.java similarity index 95% rename from bison/data/lalr1.java rename to bison/data/skeletons/lalr1.java index 7bf8e7f..1b9e11d 100644 --- a/bison/data/lalr1.java +++ b/bison/data/skeletons/lalr1.java @@ -1,6 +1,6 @@ # Java skeleton for Bison -*- autoconf -*- -# Copyright (C) 2007-2015, 2018 Free Software Foundation, Inc. +# Copyright (C) 2007-2015, 2018-2019 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -m4_include(b4_pkgdatadir/[java.m4]) +m4_include(b4_skeletonsdir/[java.m4]) b4_defines_if([b4_fatal([%s: %%defines does not make sense in Java], [b4_skeleton])]) @@ -82,28 +82,20 @@ ]b4_yystype[ yylval = null; ]]) -b4_output_begin([b4_parser_file_name]) -b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java], - [2007-2015, 2018]) - -b4_percent_define_ifdef([package], [package b4_percent_define_get([package]); -])[/* First part of user declarations. */ -]b4_user_pre_prologue -b4_user_post_prologue -b4_percent_code_get([[imports]]) +b4_output_begin([b4_parser_file_name])[ +]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java], + [2007-2015, 2018])[ +]b4_percent_define_ifdef([package], [package b4_percent_define_get([package]);[ +]])[ +]b4_user_pre_prologue[ +]b4_user_post_prologue[ +]b4_percent_code_get([[imports]]) [/** * A Bison parser, automatically generated from ]m4_bpatsubst(b4_file_name, [^"\(.*\)"$], [\1])[. * * @@author LALR (1) parser skeleton written by Paolo Bonzini. */ -]b4_percent_define_get3([annotations], [], [ ])dnl -b4_public_if([public ])dnl -b4_abstract_if([abstract ])dnl -b4_final_if([final ])dnl -b4_strictfp_if([strictfp ])dnl -[class ]b4_parser_class_name[]dnl -b4_percent_define_get3([extends], [ extends ])dnl -b4_percent_define_get3([implements], [ implements ])[ +]b4_parser_class_declaration[ { ]b4_identification[ ]b4_error_verbose_if([[ @@ -188,7 +180,7 @@ public String toString () { /** * Communication interface between the scanner and the Bison-generated - * parser ]b4_parser_class_name[. + * parser ]b4_parser_class[. */ public interface Lexer { /** Token returned by the scanner to signal the end of its input. */ @@ -248,7 +240,7 @@ public interface Lexer { /** * Instantiates the Bison-generated parser. */ - public ]b4_parser_class_name (b4_parse_param_decl([b4_lex_param_decl])[) ]b4_maybe_throws([b4_init_throws])[ + public ]b4_parser_class (b4_parse_param_decl([b4_lex_param_decl])[) ]b4_maybe_throws([b4_init_throws])[ { ]b4_percent_code_get([[init]])[ this.yylexer = new YYLexer(]b4_lex_param_call[); @@ -260,7 +252,7 @@ public interface Lexer { * Instantiates the Bison-generated parser. * @@param yylexer The scanner that will supply tokens to the parser. */ - b4_lexer_if([[protected]], [[public]]) b4_parser_class_name[ (]b4_parse_param_decl([[Lexer yylexer]])[) ]b4_maybe_throws([b4_init_throws])[ + b4_lexer_if([[protected]], [[public]]) b4_parser_class[ (]b4_parse_param_decl([[Lexer yylexer]])[) ]b4_maybe_throws([b4_init_throws])[ { ]b4_percent_code_get([[init]])[ this.yylexer = yylexer; @@ -390,8 +382,7 @@ public final int stateAt (int i) { } // Print the state stack on the debug stream. - public void print (java.io.PrintStream out) - { + public void print (java.io.PrintStream out) { out.print ("Stack now"); for (int i = 0; i <= height; i++) @@ -585,8 +576,7 @@ public int push_parse (int yylextoken, b4_yystype yylexval[]b4_locations_if([, b /* Initialize the stack. */ yystack.push (yystate, yylval ]b4_locations_if([, yylloc])[); ]m4_ifdef([b4_initial_action], [ -b4_dollar_pushdef([yylval], [], [yylloc])dnl - /* User initialization code. */ +b4_dollar_pushdef([yylval], [], [], [yylloc])dnl b4_user_initial_action b4_dollar_popdef[]dnl ])[ @@ -596,8 +586,7 @@ public int push_parse (int yylextoken, b4_yystype yylexval[]b4_locations_if([, b { push_parse_initialize (); ]m4_ifdef([b4_initial_action], [ -b4_dollar_pushdef([yylval], [], [yylloc])dnl - /* User initialization code. */ +b4_dollar_pushdef([yylval], [], [], [yylloc])dnl b4_user_initial_action b4_dollar_popdef[]dnl ])[ @@ -1036,11 +1025,12 @@ private void yy_reduce_print (int yyrule, YYStack yystack) for (int yyi = 0; yyi < yynrhs; yyi++) yy_symbol_print (" $" + (yyi + 1) + " =", yystos_[yystack.stateAt(yynrhs - (yyi + 1))], - ]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([, + ]b4_rhs_data(yynrhs, yyi + 1)b4_locations_if([, b4_rhs_location(yynrhs, yyi + 1)])[); } - /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ + /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ ]b4_integral_parser_table_define([translate_table], [b4_translate])[ private static final ]b4_int_type_for([b4_translate])[ yytranslate_ (int t) @@ -1068,4 +1058,4 @@ private void yy_reduce_print (int yyrule, YYStack yystack) } b4_epilogue[]dnl -b4_output_end() +b4_output_end diff --git a/bison/data/location.cc b/bison/data/skeletons/location.cc similarity index 75% rename from bison/data/location.cc rename to bison/data/skeletons/location.cc index 184f810..a57c0fb 100644 --- a/bison/data/location.cc +++ b/bison/data/skeletons/location.cc @@ -1,6 +1,6 @@ # C++ skeleton for Bison -# Copyright (C) 2002-2015, 2018 Free Software Foundation, Inc. +# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,13 +16,50 @@ # along with this program. If not, see . m4_pushdef([b4_copyright_years], - [2002-2015, 2018]) + [2002-2015, 2018-2019]) -# b4_position_define + +# b4_position_file +# ---------------- +# Name of the file containing the position class, if we want this file. +b4_defines_if([b4_required_version_if([302], [], + [m4_define([b4_position_file], [position.hh])])])]) + + +# b4_location_file +# ---------------- +# Name of the file containing the position/location class, +# if we want this file. +b4_percent_define_check_file([b4_location_file], + [[api.location.file]], + b4_defines_if([[location.hh]])) + +# b4_location_include +# ------------------- +# If location.hh is to be generated, the name under which should it be +# included. +# +# b4_location_path +# ---------------- +# The path to use for the CPP guard. +m4_ifdef([b4_location_file], +[m4_define([b4_location_include], + [b4_percent_define_get([[api.location.include]], + ["b4_location_file"])]) + m4_define([b4_location_path], + b4_percent_define_get([[api.location.include]], + ["b4_dir_prefix[]b4_location_file"])) + m4_define([b4_location_path], + m4_substr(m4_defn([b4_location_path]), 1, m4_eval(m4_len(m4_defn([b4_location_path])) - 2))) + ]) + + + +# b4_location_define # ------------------ -# Define class position. -m4_define([b4_position_define], -[[ /// Abstract a position. +# Define the position and location classes. +m4_define([b4_location_define], +[[ /// A point in a source file. class position { public:]m4_ifdef([b4_location_constructors], [[ @@ -73,10 +110,11 @@ m4_define([b4_position_define], unsigned column; private: - /// Compute max(min, lhs+rhs). + /// Compute max (min, lhs+rhs). static unsigned add_ (unsigned lhs, int rhs, int min) { - return static_cast(std::max(min, static_cast(lhs) + rhs)); + return static_cast (std::max (min, + static_cast (lhs) + rhs)); } }; @@ -132,20 +170,15 @@ m4_define([b4_position_define], ** \param pos a reference to the position to redirect */ template - inline std::basic_ostream& + std::basic_ostream& operator<< (std::basic_ostream& ostr, const position& pos) { if (pos.filename) ostr << *pos.filename << ':'; return ostr << pos.line << '.' << pos.column; } -]]) - -# b4_location_define -# ------------------ -m4_define([b4_location_define], -[[ /// Abstract a location. + /// Two points in a source file. class location { public: @@ -269,7 +302,7 @@ m4_define([b4_location_define], ** Avoid duplicate information. */ template - inline std::basic_ostream& + std::basic_ostream& operator<< (std::basic_ostream& ostr, const location& loc) { unsigned end_col = 0 < loc.end.column ? loc.end.column - 1 : 0; @@ -287,16 +320,31 @@ m4_define([b4_location_define], ]]) -b4_defines_if([ -b4_output_begin([b4_dir_prefix[]position.hh]) -b4_copyright([Positions for Bison parsers in C++])[ +m4_ifdef([b4_position_file], [[ +]b4_output_begin([b4_dir_prefix], [b4_position_file])[ +]b4_generated_by[ +// Starting with Bison 3.2, this file is useless: the structure it +// used to define is now defined in "]b4_location_file[". +// +// To get rid of this file: +// 1. add 'require "3.2"' (or newer) to your grammar file +// 2. remove references to this file from your build system +// 3. if you used to include it, include "]b4_location_file[" instead. +#include ]b4_location_include[ +]b4_output_end[ +]]) + + +m4_ifdef([b4_location_file], [[ +]b4_output_begin([b4_dir_prefix], [b4_location_file])[ +]b4_copyright([Locations for Bison parsers in C++])[ /** - ** \file ]b4_dir_prefix[position.hh - ** Define the ]b4_namespace_ref[::position class. + ** \file ]b4_location_path[ + ** Define the ]b4_namespace_ref[::location class. */ -]b4_cpp_guard_open([b4_dir_prefix[]position.hh])[ +]b4_cpp_guard_open([b4_location_path])[ # include // std::max # include @@ -304,31 +352,12 @@ b4_copyright([Positions for Bison parsers in C++])[ ]b4_null_define[ -]b4_namespace_open[ -]b4_position_define[ -]b4_namespace_close[ -]b4_cpp_guard_close([b4_dir_prefix[]position.hh]) -b4_output_end() - - -b4_output_begin([b4_dir_prefix[]location.hh]) -b4_copyright([Locations for Bison parsers in C++])[ - -/** - ** \file ]b4_dir_prefix[location.hh - ** Define the ]b4_namespace_ref[::location class. - */ - -]b4_cpp_guard_open([b4_dir_prefix[]location.hh])[ - -# include "position.hh" - ]b4_namespace_open[ ]b4_location_define[ ]b4_namespace_close[ -]b4_cpp_guard_close([b4_dir_prefix[]location.hh]) -b4_output_end() -]) +]b4_cpp_guard_close([b4_location_path])[ +]b4_output_end[ +]]) m4_popdef([b4_copyright_years]) diff --git a/bison/data/skeletons/stack.hh b/bison/data/skeletons/stack.hh new file mode 100644 index 0000000..926a6f8 --- /dev/null +++ b/bison/data/skeletons/stack.hh @@ -0,0 +1,163 @@ +# C++ skeleton for Bison + +# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# b4_stack_file +# ------------- +# Name of the file containing the stack class, if we want this file. +b4_defines_if([b4_required_version_if([302], [], + [m4_define([b4_stack_file], [stack.hh])])]) + + +# b4_stack_define +# --------------- +m4_define([b4_stack_define], +[[ /// A stack with random access from its top. + template > + class stack + { + public: + // Hide our reversed order. + typedef typename S::reverse_iterator iterator; + typedef typename S::const_reverse_iterator const_iterator; + typedef typename S::size_type size_type; + + stack (size_type n = 200) + : seq_ (n) + {} + + /// Random access. + /// + /// Index 0 returns the topmost element. + T& + operator[] (size_type i) + { + return seq_[size () - 1 - i]; + } + + /// Random access. + /// + /// Index 0 returns the topmost element. + T& + operator[] (int i) + { + return operator[] (size_type (i)); + } + + /// Random access. + /// + /// Index 0 returns the topmost element. + const T& + operator[] (size_type i) const + { + return seq_[size () - 1 - i]; + } + + /// Random access. + /// + /// Index 0 returns the topmost element. + const T& + operator[] (int i) const + { + return operator[] (size_type (i)); + } + + /// Steal the contents of \a t. + /// + /// Close to move-semantics. + void + push (YY_MOVE_REF (T) t) + { + seq_.push_back (T ()); + operator[] (0).move (t); + } + + /// Pop elements from the stack. + void + pop (int n = 1) YY_NOEXCEPT + { + for (; 0 < n; --n) + seq_.pop_back (); + } + + /// Pop all elements from the stack. + void + clear () YY_NOEXCEPT + { + seq_.clear (); + } + + /// Number of elements on the stack. + size_type + size () const YY_NOEXCEPT + { + return seq_.size (); + } + + /// Iterator on top of the stack (going downwards). + const_iterator + begin () const YY_NOEXCEPT + { + return seq_.rbegin (); + } + + /// Bottom of the stack. + const_iterator + end () const YY_NOEXCEPT + { + return seq_.rend (); + } + + /// Present a slice of the top of a stack. + class slice + { + public: + slice (const stack& stack, int range) + : stack_ (stack) + , range_ (range) + {} + + const T& + operator[] (int i) const + { + return stack_[range_ - i]; + } + + private: + const stack& stack_; + int range_; + }; + + private: + stack (const stack&); + stack& operator= (const stack&); + /// The wrapped container. + S seq_; + }; +]]) + +m4_ifdef([b4_stack_file], +[b4_output_begin([b4_dir_prefix], [b4_stack_file])[ +]b4_generated_by[ +// Starting with Bison 3.2, this file is useless: the structure it +// used to define is now defined with the parser itself. +// +// To get rid of this file: +// 1. add 'require "3.2"' (or newer) to your grammar file +// 2. remove references to this file from your build system. +]b4_output_end[ +]]) diff --git a/bison/data/skeletons/variant.hh b/bison/data/skeletons/variant.hh new file mode 100644 index 0000000..8b9d480 --- /dev/null +++ b/bison/data/skeletons/variant.hh @@ -0,0 +1,453 @@ +# C++ skeleton for Bison + +# Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +## --------- ## +## variant. ## +## --------- ## + +# b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS]) +# ------------------------------------------------ +# Run some ACTION ("build", or "destroy") on YYVAL of symbol type +# YYTYPE. +m4_define([b4_symbol_variant], +[m4_pushdef([b4_dollar_dollar], + [$2.$3< $][3 > (m4_shift3($@))])dnl +switch ($1) + { +b4_type_foreach([_b4_type_action])[]dnl + default: + break; + } +m4_popdef([b4_dollar_dollar])dnl +]) + + +# _b4_char_sizeof_counter +# ----------------------- +# A counter used by _b4_char_sizeof_dummy to create fresh symbols. +m4_define([_b4_char_sizeof_counter], +[0]) + +# _b4_char_sizeof_dummy +# --------------------- +# At each call return a new C++ identifier. +m4_define([_b4_char_sizeof_dummy], +[m4_define([_b4_char_sizeof_counter], m4_incr(_b4_char_sizeof_counter))dnl +dummy[]_b4_char_sizeof_counter]) + + +# b4_char_sizeof(SYMBOL-NUMS) +# --------------------------- +# To be mapped on the list of type names to produce: +# +# char dummy1[sizeof (type_name_1)]; +# char dummy2[sizeof (type_name_2)]; +# +# for defined type names. +m4_define([b4_char_sizeof], +[b4_symbol_if([$1], [has_type], +[ +m4_map([ b4_symbol_tag_comment], [$@])dnl + char _b4_char_sizeof_dummy@{sizeof (b4_symbol([$1], [type]))@}; +])]) + + +# b4_variant_includes +# ------------------- +# The needed includes for variants support. +m4_define([b4_variant_includes], +[b4_parse_assert_if([[#include ]])[ +#ifndef YYASSERT +# include +# define YYASSERT assert +#endif +]]) + + + +## -------------------------- ## +## Adjustments for variants. ## +## -------------------------- ## + + +# b4_value_type_declare +# --------------------- +# Define semantic_type. +m4_define([b4_value_type_declare], +[[ /// A buffer to store and retrieve objects. + /// + /// Sort of a variant, but does not keep track of the nature + /// of the stored data, since that knowledge is available + /// via the current parser state. + class semantic_type + { + public: + /// Type of *this. + typedef semantic_type self_type; + + /// Empty construction. + semantic_type () YY_NOEXCEPT + : yybuffer_ ()]b4_parse_assert_if([ + , yytypeid_ (YY_NULLPTR)])[ + {} + + /// Construct and fill. + template + semantic_type (YY_RVREF (T) t)]b4_parse_assert_if([ + : yytypeid_ (&typeid (T))])[ + { + YYASSERT (sizeof (T) <= size); + new (yyas_ ()) T (YY_MOVE (t)); + } + + /// Destruction, allowed only if empty. + ~semantic_type () YY_NOEXCEPT + {]b4_parse_assert_if([ + YYASSERT (!yytypeid_); + ])[} + +# if 201103L <= YY_CPLUSPLUS + /// Instantiate a \a T in here from \a t. + template + T& + emplace (U&&... u) + {]b4_parse_assert_if([ + YYASSERT (!yytypeid_); + YYASSERT (sizeof (T) <= size); + yytypeid_ = & typeid (T);])[ + return *new (yyas_ ()) T (std::forward (u)...); + } +# else + /// Instantiate an empty \a T in here. + template + T& + emplace () + {]b4_parse_assert_if([ + YYASSERT (!yytypeid_); + YYASSERT (sizeof (T) <= size); + yytypeid_ = & typeid (T);])[ + return *new (yyas_ ()) T (); + } + + /// Instantiate a \a T in here from \a t. + template + T& + emplace (const T& t) + {]b4_parse_assert_if([ + YYASSERT (!yytypeid_); + YYASSERT (sizeof (T) <= size); + yytypeid_ = & typeid (T);])[ + return *new (yyas_ ()) T (t); + } +# endif + + /// Instantiate an empty \a T in here. + /// Obsolete, use emplace. + template + T& + build () + { + return emplace (); + } + + /// Instantiate a \a T in here from \a t. + /// Obsolete, use emplace. + template + T& + build (const T& t) + { + return emplace (t); + } + + /// Accessor to a built \a T. + template + T& + as () YY_NOEXCEPT + {]b4_parse_assert_if([ + YYASSERT (yytypeid_); + YYASSERT (*yytypeid_ == typeid (T)); + YYASSERT (sizeof (T) <= size);])[ + return *yyas_ (); + } + + /// Const accessor to a built \a T (for %printer). + template + const T& + as () const YY_NOEXCEPT + {]b4_parse_assert_if([ + YYASSERT (yytypeid_); + YYASSERT (*yytypeid_ == typeid (T)); + YYASSERT (sizeof (T) <= size);])[ + return *yyas_ (); + } + + /// Swap the content with \a that, of same type. + /// + /// Both variants must be built beforehand, because swapping the actual + /// data requires reading it (with as()), and this is not possible on + /// unconstructed variants: it would require some dynamic testing, which + /// should not be the variant's responsibility. + /// Swapping between built and (possibly) non-built is done with + /// self_type::move (). + template + void + swap (self_type& that) YY_NOEXCEPT + {]b4_parse_assert_if([ + YYASSERT (yytypeid_); + YYASSERT (*yytypeid_ == *that.yytypeid_);])[ + std::swap (as (), that.as ()); + } + + /// Move the content of \a that to this. + /// + /// Destroys \a that. + template + void + move (self_type& that) + { +# if 201103L <= YY_CPLUSPLUS + emplace (std::move (that.as ())); +# else + emplace (); + swap (that); +# endif + that.destroy (); + } + +# if 201103L <= YY_CPLUSPLUS + /// Move the content of \a that to this. + template + void + move (self_type&& that) + { + emplace (std::move (that.as ())); + that.destroy (); + } +#endif + + /// Copy the content of \a that to this. + template + void + copy (const self_type& that) + { + emplace (that.as ()); + } + + /// Destroy the stored \a T. + template + void + destroy () + { + as ().~T ();]b4_parse_assert_if([ + yytypeid_ = YY_NULLPTR;])[ + } + + private: + /// Prohibit blind copies. + self_type& operator= (const self_type&); + semantic_type (const self_type&); + + /// Accessor to raw memory as \a T. + template + T* + yyas_ () YY_NOEXCEPT + { + void *yyp = yybuffer_.yyraw; + return static_cast (yyp); + } + + /// Const accessor to raw memory as \a T. + template + const T* + yyas_ () const YY_NOEXCEPT + { + const void *yyp = yybuffer_.yyraw; + return static_cast (yyp); + } + + /// An auxiliary type to compute the largest semantic type. + union union_type + {]b4_type_foreach([b4_char_sizeof])[ }; + + /// The size of the largest semantic type. + enum { size = sizeof (union_type) }; + + /// A buffer to store semantic values. + union + { + /// Strongest alignment constraints. + long double yyalign_me; + /// A buffer large enough to store any of the semantic values. + char yyraw[size]; + } yybuffer_;]b4_parse_assert_if([ + + /// Whether the content is built: if defined, the name of the stored type. + const std::type_info *yytypeid_;])[ + }; +]]) + + +# How the semantic value is extracted when using variants. + +# b4_symbol_value(VAL, SYMBOL-NUM, [TYPE]) +# ---------------------------------------- +# See README. +m4_define([b4_symbol_value], +[m4_ifval([$3], + [$1.as< $3 > ()], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [$1.as < b4_symbol([$2], [type]) > ()], + [$1])], + [$1])])]) + +# b4_symbol_value_template(VAL, SYMBOL-NUM, [TYPE]) +# ------------------------------------------------- +# Same as b4_symbol_value, but used in a template method. +m4_define([b4_symbol_value_template], +[m4_ifval([$3], + [$1.template as< $3 > ()], + [m4_ifval([$2], + [b4_symbol_if([$2], [has_type], + [$1.template as < b4_symbol([$2], [type]) > ()], + [$1])], + [$1])])]) + + + +## ------------- ## +## make_SYMBOL. ## +## ------------- ## + + +# _b4_includes_tokens(SYMBOL-NUM...) +# ---------------------------------- +# Expands to non-empty iff one of the SYMBOL-NUM denotes +# a token. +m4_define([_b4_is_token], + [b4_symbol_if([$1], [is_token], [1])]) +m4_define([_b4_includes_tokens], + [m4_map([_b4_is_token], [$@])]) + + +# _b4_token_maker_define(SYMBOL-NUM) +# ---------------------------------- +# Declare make_SYMBOL for SYMBOL-NUM. Use at class-level. +m4_define([_b4_token_maker_define], +[b4_token_visible_if([$1], +[#if 201103L <= YY_CPLUSPLUS + static + symbol_type + make_[]_b4_symbol([$1], [id]) (b4_join( + b4_symbol_if([$1], [has_type], + [b4_symbol([$1], [type]) v]), + b4_locations_if([location_type l]))) + { + return symbol_type (b4_join([token::b4_symbol([$1], [id])], + b4_symbol_if([$1], [has_type], [std::move (v)]), + b4_locations_if([std::move (l)]))); + } +#else + static + symbol_type + make_[]_b4_symbol([$1], [id]) (b4_join( + b4_symbol_if([$1], [has_type], + [const b4_symbol([$1], [type])& v]), + b4_locations_if([const location_type& l]))) + { + return symbol_type (b4_join([token::b4_symbol([$1], [id])], + b4_symbol_if([$1], [has_type], [v]), + b4_locations_if([l]))); + } +#endif +])]) + + +m4_define([_b4_type_clause], +[b4_symbol_if([$1], [is_token], + [b4_symbol_if([$1], [has_id], + [tok == token::b4_symbol([$1], [id])], + [tok == b4_symbol([$1], [user_number])])])]) + + +# _b4_token_constructor_define(SYMBOL-NUM...) +# ------------------------------------------- +# Define a unique make_symbol for all the SYMBOL-NUM (they +# have the same type). Use at class-level. +m4_define([_b4_token_constructor_define], +[m4_ifval(_b4_includes_tokens($@), +[[#if 201103L <= YY_CPLUSPLUS + symbol_type (]b4_join( + [int tok], + b4_symbol_if([$1], [has_type], + [b4_symbol([$1], [type]) v]), + b4_locations_if([location_type l]))[) + : super_type(]b4_join([token_type (tok)], + b4_symbol_if([$1], [has_type], [std::move (v)]), + b4_locations_if([std::move (l)]))[) + { + YYASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[); + } +#else + symbol_type (]b4_join( + [int tok], + b4_symbol_if([$1], [has_type], + [const b4_symbol([$1], [type])& v]), + b4_locations_if([const location_type& l]))[) + : super_type(]b4_join([token_type (tok)], + b4_symbol_if([$1], [has_type], [v]), + b4_locations_if([l]))[) + { + YYASSERT (]m4_join([ || ], m4_map_sep([_b4_type_clause], [, ], [$@]))[); + } +#endif +]])]) + + +# b4_basic_symbol_constructor_define(SYMBOL-NUM) +# ---------------------------------------------- +# Generate a constructor for basic_symbol from given type. +m4_define([b4_basic_symbol_constructor_define], +[[#if 201103L <= YY_CPLUSPLUS + basic_symbol (]b4_join( + [typename Base::kind_type t], + b4_symbol_if([$1], [has_type], [b4_symbol([$1], [type])&& v]), + b4_locations_if([location_type&& l]))[) + : Base (t)]b4_symbol_if([$1], [has_type], [ + , value (std::move (v))])[]b4_locations_if([ + , location (std::move (l))])[ + {} +#else + basic_symbol (]b4_join( + [typename Base::kind_type t], + b4_symbol_if([$1], [has_type], [const b4_symbol([$1], [type])& v]), + b4_locations_if([const location_type& l]))[) + : Base (t)]b4_symbol_if([$1], [has_type], [ + , value (v)])[]b4_locations_if([ + , location (l)])[ + {} +#endif +]]) + + +# b4_token_constructor_define +# --------------------------- +# Define the overloaded versions of make_symbol for all the value types. +m4_define([b4_token_constructor_define], +[ // Implementation of make_symbol for each symbol type. +b4_symbol_foreach([_b4_token_maker_define])]) diff --git a/bison/data/yacc.c b/bison/data/skeletons/yacc.c similarity index 92% rename from bison/data/yacc.c rename to bison/data/skeletons/yacc.c index e72b098..54e40e6 100644 --- a/bison/data/yacc.c +++ b/bison/data/skeletons/yacc.c @@ -1,11 +1,11 @@ -*- C -*- # Yacc compatible skeleton for Bison -# Copyright (C) 1984, 1989-1990, 2000-2015, 2018 Free Software +# Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software # Foundation, Inc. m4_pushdef([b4_copyright_years], - [1984, 1989-1990, 2000-2015, 2018]) + [1984, 1989-1990, 2000-2015, 2018-2019]) # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -51,7 +51,7 @@ m4_define([b4_lac_flag], [m4_if(b4_percent_define_get([[parse.lac]]), [none], [[0]], [[1]])]) -m4_include(b4_pkgdatadir/[c.m4]) +m4_include(b4_skeletonsdir/[c.m4]) ## ---------------- ## ## Default values. ## @@ -128,19 +128,18 @@ m4_define([b4_int_type], ## ----------------- ## -# b4_lhs_value([TYPE]) -# -------------------- -# Expansion of $$. +# b4_lhs_value(SYMBOL-NUM, [TYPE]) +# -------------------------------- +# See README. m4_define([b4_lhs_value], -[b4_symbol_value(yyval, [$1])]) +[b4_symbol_value(yyval, [$1], [$2])]) -# b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) -# -------------------------------------- -# Expansion of $NUM, where the current rule has RULE-LENGTH -# symbols on RHS. +# b4_rhs_value(RULE-LENGTH, POS, [SYMBOL-NUM], [TYPE]) +# ---------------------------------------------------- +# See README. m4_define([b4_rhs_value], - [b4_symbol_value([yyvsp@{b4_subtract([$2], [$1])@}], [$3])]) +[b4_symbol_value([yyvsp@{b4_subtract([$2], [$1])@}], [$3], [$4])]) ## ----------- ## @@ -154,12 +153,12 @@ m4_define([b4_lhs_location], [(yyloc)]) -# b4_rhs_location(RULE-LENGTH, NUM) +# b4_rhs_location(RULE-LENGTH, POS) # --------------------------------- -# Expansion of @NUM, where the current rule has RULE-LENGTH symbols +# Expansion of @POS, where the current rule has RULE-LENGTH symbols # on RHS. m4_define([b4_rhs_location], - [(yylsp@{b4_subtract([$2], [$1])@})]) +[(yylsp@{b4_subtract([$2], [$1])@})]) ## -------------- ## @@ -237,11 +236,11 @@ m4_define([b4_declare_parser_state_variables], [b4_pure_if([[ YYSIZE_T yyes_capacity;]])]) -# b4_declare_yyparse_push_ +# _b4_declare_yyparse_push # ------------------------ # Declaration of yyparse (and dependencies) when using the push parser # (including in pull mode). -m4_define([b4_declare_yyparse_push_], +m4_define([_b4_declare_yyparse_push], [[#ifndef YYPUSH_MORE_DEFINED # define YYPUSH_MORE_DEFINED enum { YYPUSH_MORE = 4 }; @@ -265,18 +264,18 @@ b4_function_declare([b4_prefix[pstate_delete]], [[void]], [[b4_prefix[pstate *ps]], [[ps]]])dnl ]) -# b4_declare_yyparse_ +# _b4_declare_yyparse # ------------------- # When not the push parser. -m4_define([b4_declare_yyparse_], +m4_define([_b4_declare_yyparse], [b4_function_declare(b4_prefix[parse], [int], b4_parse_param)]) # b4_declare_yyparse # ------------------ m4_define([b4_declare_yyparse], -[b4_push_if([b4_declare_yyparse_push_], - [b4_declare_yyparse_])[]dnl +[b4_push_if([_b4_declare_yyparse_push], + [_b4_declare_yyparse])[]dnl ]) @@ -299,9 +298,8 @@ m4_define([b4_shared_declarations], ## Output files. ## ## -------------- ## -b4_output_begin([b4_parser_file_name]) -b4_copyright([Bison implementation for Yacc-like parsers in C])[ - +b4_output_begin([b4_parser_file_name])[ +]b4_copyright([Bison implementation for Yacc-like parsers in C])[ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ @@ -312,8 +310,9 @@ b4_copyright([Bison implementation for Yacc-like parsers in C])[ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -]b4_identification -b4_percent_code_get([[top]])[]dnl +]b4_disclaimer[ +]b4_identification[ +]b4_percent_code_get([[top]])[]dnl m4_if(b4_api_prefix, [yy], [], [[/* Substitute the type names. */ #define YYSTYPE ]b4_api_PREFIX[STYPE]b4_locations_if([[ @@ -335,9 +334,7 @@ m4_if(b4_api_prefix, [yy], [], #define yychar ]b4_prefix[char]b4_locations_if([[ #define yylloc ]b4_prefix[lloc]])]))[ -/* Copy the first part of user declarations. */ ]b4_user_pre_prologue[ - ]b4_null_define[ /* Enabling verbose error messages. */ @@ -354,9 +351,8 @@ m4_if(b4_api_prefix, [yy], [], ]])dnl b4_shared_declarations[ -/* Copy the second part of user declarations. */ -]b4_user_post_prologue -b4_percent_code_get[]dnl +]b4_user_post_prologue[ +]b4_percent_code_get[]dnl [#ifdef short # undef short @@ -565,16 +561,16 @@ union yyalloc /* YYNSTATES -- Number of states. */ #define YYNSTATES ]b4_states_number[ -/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned - by yylex, with out-of-bounds checking. */ #define YYUNDEFTOK ]b4_undef_token_number[ #define YYMAXUTOK ]b4_user_token_number_max[ +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ #define YYTRANSLATE(YYX) \ ((unsigned) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM - as returned by yylex, without out-of-bounds checking. */ + as returned by yylex. */ static const ]b4_int_type_for([b4_translate])[ yytranslate[] = { ]b4_translate[ @@ -627,23 +623,23 @@ static const ]b4_int_type_for([b4_toknum])[ yytoknum[] = #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \]b4_lac_if([[ - YY_LAC_DISCARD ("YYBACKUP"); \]])[ - goto yybackup; \ - } \ - else \ - { \ - yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (0) +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \]b4_lac_if([[ + YY_LAC_DISCARD ("YYBACKUP"); \]])[ + goto yybackup; \ + } \ + else \ + { \ + yyerror (]b4_yyerror_args[YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) /* Error token number */ #define YYTERROR 1 @@ -791,7 +787,7 @@ yy_lac_stack_realloc (YYSIZE_T *yycapacity, YYSIZE_T yyadd, yytype_int16 **yytop, yytype_int16 *yytop_empty) { YYSIZE_T yysize_old = - *yytop == yytop_empty ? 0 : *yytop - *yybottom + 1; + (YYSIZE_T) (*yytop == yytop_empty ? 0 : *yytop - *yybottom + 1); YYSIZE_T yysize_new = yysize_old + yyadd; if (*yycapacity < yysize_new) { @@ -957,7 +953,7 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, YYDPRINTF ((stderr, " R%d", yyrule - 1)); if (yyesp != yyes_prev) { - YYSIZE_T yysize = yyesp - *yyes + 1; + YYSIZE_T yysize = (YYSIZE_T) (yyesp - *yyes + 1); if (yylen < yysize) { yyesp -= yylen; @@ -973,15 +969,14 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, yyesp = yyes_prev -= yylen; } { - int yystate; + yytype_int16 yystate; { - int yylhs = yyr1[yyrule] - YYNTOKENS; - yystate = yypgoto[yylhs] + *yyesp; - if (yystate < 0 || YYLAST < yystate - || yycheck[yystate] != *yyesp) - yystate = yydefgoto[yylhs]; - else - yystate = yytable[yystate]; + const int yylhs = yyr1[yyrule] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyesp; + yystate = ((yytype_int16) + (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyesp + ? yytable[yyi] + : yydefgoto[yylhs])); } if (yyesp == yyes_prev) { @@ -1001,7 +996,7 @@ yy_lac (yytype_int16 *yyesa, yytype_int16 **yyes, } *++yyesp = yystate; } - YYDPRINTF ((stderr, " G%d", yystate)); + YYDPRINTF ((stderr, " G%d", (int) yystate)); } } }]])[ @@ -1071,7 +1066,10 @@ yytnamerr (char *yyres, const char *yystr) case '\\': if (*++yyp != '\\') goto do_not_strip_quotes; - /* Fall through. */ + else + goto append; + + append: default: if (yyres) yyres[yyn] = *yyp; @@ -1089,7 +1087,7 @@ yytnamerr (char *yyres, const char *yystr) if (! yyres) return yystrlen (yystr); - return yystpcpy (yyres, yystr) - yyres; + return (YYSIZE_T) (yystpcpy (yyres, yystr) - yyres); } # endif @@ -1188,10 +1186,10 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, yyarg[yycount++] = yytname[yyx]; { YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) + yysize = yysize1; + else return 2; - yysize = yysize1; } } }]b4_lac_if([[ @@ -1219,9 +1217,10 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, { YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM) + yysize = yysize1; + else return 2; - yysize = yysize1; } if (*yymsg_alloc < yysize) @@ -1279,13 +1278,10 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[ ]b4_function_define([[yypull_parse]], [[int]], [[[yypstate *yyps]], [[yyps]]]m4_ifset([b4_parse_param], [, b4_parse_param]))[ -{ - int yystatus; - yypstate *yyps_local;]b4_pure_if([[ - int yychar; - YYSTYPE yylval;]b4_locations_if([[ +{]b4_pure_if([b4_locations_if([[ static YYLTYPE yyloc_default][]b4_yyloc_default[; YYLTYPE yylloc = yyloc_default;]])])[ + yypstate *yyps_local; if (yyps) yyps_local = yyps; else @@ -1299,8 +1295,10 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[ return 2; } } - do { - yychar = ]b4_lex[; + int yystatus; + do {]b4_pure_if([[ + YYSTYPE yylval; + int ]])[yychar = ]b4_lex[; yystatus = yypush_parse (yyps_local]b4_pure_if([[, yychar, &yylval]b4_locations_if([[, &yylloc]])])m4_ifset([b4_parse_param], [, b4_args(b4_parse_param)])[); } while (yystatus == YYPUSH_MORE); @@ -1431,9 +1429,8 @@ b4_function_define([[yyparse]], [[int]], b4_parse_param)[ yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ ]m4_ifdef([b4_initial_action], [ -b4_dollar_pushdef([m4_define([b4_dollar_dollar_used])yylval], [], +b4_dollar_pushdef([m4_define([b4_dollar_dollar_used])yylval], [], [], [b4_push_if([b4_pure_if([*])yypushed_loc], [yylloc])])dnl -/* User initialization code. */ b4_user_initial_action b4_dollar_popdef[]dnl m4_ifdef([b4_dollar_dollar_used],[[ yyvsp[0] = yylval; @@ -1442,23 +1439,31 @@ b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yyllo ]])dnl [ goto yysetstate; + /*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | +| yynewstate -- push a new state, which is found in yystate. | `------------------------------------------------------------*/ - yynewstate: +yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; - yysetstate: - *yyssp = yystate; + +/*--------------------------------------------------------------------. +| yynewstate -- set current state (the top of the stack) to yystate. | +`--------------------------------------------------------------------*/ +yysetstate: + *yyssp = (yytype_int16) yystate; if (yyss + yystacksize - 1 <= yyssp) +#if !defined yyoverflow && !defined YYSTACK_RELOCATE + goto yyexhaustedlab; +#else { /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; + YYSIZE_T yysize = (YYSIZE_T) (yyssp - yyss + 1); -#ifdef yyoverflow +# if defined yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into @@ -1476,15 +1481,11 @@ b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yyllo &yyvs1, yysize * sizeof (*yyvsp),]b4_locations_if([ &yyls1, yysize * sizeof (*yylsp),])[ &yystacksize); -]b4_locations_if([ - yyls = yyls1;])[ yyss = yyss1; - yyvs = yyvs1; + yyvs = yyvs1;]b4_locations_if([ + yyls = yyls1;])[ } -#else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE - goto yyexhaustedlab; -# else +# else /* defined YYSTACK_RELOCATE */ /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; @@ -1501,12 +1502,11 @@ b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yyllo YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyvs_alloc, yyvs);]b4_locations_if([ YYSTACK_RELOCATE (yyls_alloc, yyls);])[ -# undef YYSTACK_RELOCATE +# undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } # endif -#endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1;]b4_locations_if([ @@ -1518,6 +1518,7 @@ b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yyllo if (yyss + yystacksize - 1 <= yyssp) YYABORT; } +#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ YYDPRINTF ((stderr, "Entering state %d\n", yystate)); @@ -1526,11 +1527,11 @@ b4_locations_if([[ yylsp[0] = ]b4_push_if([b4_pure_if([*])yypushed_loc], [yyllo goto yybackup; + /*-----------. | yybackup. | `-----------*/ yybackup: - /* Do appropriate processing given the current state. Read a lookahead token if we need one and don't already have one. */ @@ -1628,7 +1629,7 @@ yyread_pushed_token:]])[ /*-----------------------------. -| yyreduce -- Do a reduction. | +| yyreduce -- do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ @@ -1653,7 +1654,7 @@ yyread_pushed_token:]])[ int yychar_backup = yychar; switch (yyn) { - ]b4_user_actions[ +]b4_user_actions[ default: break; } if (yychar_backup != yychar) @@ -1687,14 +1688,13 @@ yyread_pushed_token:]])[ /* Now 'shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ - - yyn = yyr1[yyn]; - - yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; - if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTOKENS]; + { + const int yylhs = yyr1[yyn] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyssp; + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp + ? yytable[yyi] + : yydefgoto[yylhs]); + } goto yynewstate; @@ -1780,12 +1780,10 @@ yyread_pushed_token:]])[ | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: - - /* Pacify compilers like GCC when the user code never invokes - YYERROR and the label yyerrorlab therefore never appears in user - code. */ - if (/*CONSTCOND*/ 0) - goto yyerrorlab; + /* Pacify compilers when the user code never invokes YYERROR and the + label yyerrorlab therefore never appears in user code. */ + if (0) + YYERROR; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ @@ -1856,6 +1854,7 @@ yyread_pushed_token:]])[ yyresult = 0; goto yyreturn; + /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ @@ -1863,6 +1862,7 @@ yyread_pushed_token:]])[ yyresult = 1; goto yyreturn; + #if ]b4_lac_if([[1]], [[!defined yyoverflow || YYERROR_VERBOSE]])[ /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | @@ -1873,6 +1873,10 @@ yyread_pushed_token:]])[ /* Fall through. */ #endif + +/*-----------------------------------------------------. +| yyreturn -- parsing is finished, return the result. | +`-----------------------------------------------------*/ yyreturn: if (yychar != YYEMPTY) { @@ -1900,6 +1904,10 @@ yyread_pushed_token:]])[ YYSTACK_FREE (yyes);]])b4_push_if([[ yyps->yynew = 1; + +/*-----------------------------------------. +| yypushreturn -- ask for the next token. | +`-----------------------------------------*/ yypushreturn:]])[ #if YYERROR_VERBOSE if (yymsg != yymsgbuf) @@ -1908,12 +1916,12 @@ yypushreturn:]])[ return yyresult; } ]b4_epilogue[]dnl -b4_output_end() +b4_output_end -b4_defines_if( -[b4_output_begin([b4_spec_defines_file])[ +b4_defines_if([[ +]b4_output_begin([b4_spec_defines_file])[ ]b4_copyright([Bison interface for Yacc-like parsers in C])[ - +]b4_disclaimer[ ]b4_shared_declarations[ -]b4_output_end() -])# b4_defines_if +]b4_output_end[ +]])# b4_defines_if diff --git a/bison/data/stack.hh b/bison/data/stack.hh deleted file mode 100644 index f3ac21f..0000000 --- a/bison/data/stack.hh +++ /dev/null @@ -1,153 +0,0 @@ -# C++ skeleton for Bison - -# Copyright (C) 2002-2015, 2018 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -m4_pushdef([b4_copyright_years], - [2002-2015, 2018]) - -# b4_stack_define -# --------------- -m4_define([b4_stack_define], -[[ /// A stack with random access from its top. - template > - class stack - { - public: - // Hide our reversed order. - typedef typename S::reverse_iterator iterator; - typedef typename S::const_reverse_iterator const_iterator; - typedef typename S::size_type size_type; - - stack () - { - seq_.reserve (200); - } - - stack (size_type n) - : seq_ (n) - {} - - /// Random access. - /// - /// Index 0 returns the topmost element. - T& - operator[] (size_type i) - { - return seq_[seq_.size () - 1 - i]; - } - - /// Random access. - /// - /// Index 0 returns the topmost element. - const T& - operator[] (size_type i) const - { - return seq_[seq_.size () - 1 - i]; - } - - /// Steal the contents of \a t. - /// - /// Close to move-semantics. - void - push (T& t) - { - seq_.push_back (T()); - operator[](0).move (t); - } - - void - pop (size_type n = 1) - { - for (; n; --n) - seq_.pop_back (); - } - - void - clear () - { - seq_.clear (); - } - - size_type - size () const - { - return seq_.size (); - } - - const_iterator - begin () const - { - return seq_.rbegin (); - } - - const_iterator - end () const - { - return seq_.rend (); - } - - private: - stack (const stack&); - stack& operator= (const stack&); - /// The wrapped container. - S seq_; - }; - - /// Present a slice of the top of a stack. - template > - class slice - { - public: - typedef typename S::size_type size_type; - slice (const S& stack, size_type range) - : stack_ (stack) - , range_ (range) - {} - - const T& - operator[] (size_type i) const - { - return stack_[range_ - i]; - } - - private: - const S& stack_; - size_type range_; - }; -]]) - -b4_defines_if( -[b4_output_begin([b4_dir_prefix[]stack.hh]) -b4_copyright([Stack handling for Bison parsers in C++])[ - -/** - ** \file ]b4_dir_prefix[stack.hh - ** Define the ]b4_namespace_ref[::stack class. - */ - -]b4_cpp_guard_open([b4_dir_prefix[]stack.hh])[ - -# include - -]b4_namespace_open[ -]b4_stack_define[ -]b4_namespace_close[ - -]b4_cpp_guard_close([b4_dir_prefix[]stack.hh]) -b4_output_end() -]) - -m4_popdef([b4_copyright_years]) diff --git a/bison/data/variant.hh b/bison/data/variant.hh deleted file mode 100644 index 8d0f06f..0000000 --- a/bison/data/variant.hh +++ /dev/null @@ -1,363 +0,0 @@ -# C++ skeleton for Bison - -# Copyright (C) 2002-2015, 2018 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - -## --------- ## -## variant. ## -## --------- ## - -# b4_symbol_variant(YYTYPE, YYVAL, ACTION, [ARGS]) -# ------------------------------------------------ -# Run some ACTION ("build", or "destroy") on YYVAL of symbol type -# YYTYPE. -m4_define([b4_symbol_variant], -[m4_pushdef([b4_dollar_dollar], - [$2.$3< $][3 > (m4_shift3($@))])dnl -switch ($1) - { -b4_type_foreach([b4_type_action_])[]dnl - default: - break; - } -m4_popdef([b4_dollar_dollar])dnl -]) - - -# _b4_char_sizeof_counter -# ----------------------- -# A counter used by _b4_char_sizeof_dummy to create fresh symbols. -m4_define([_b4_char_sizeof_counter], -[0]) - -# _b4_char_sizeof_dummy -# --------------------- -# At each call return a new C++ identifier. -m4_define([_b4_char_sizeof_dummy], -[m4_define([_b4_char_sizeof_counter], m4_incr(_b4_char_sizeof_counter))dnl -dummy[]_b4_char_sizeof_counter]) - - -# b4_char_sizeof(SYMBOL-NUMS) -# --------------------------- -# To be mapped on the list of type names to produce: -# -# char dummy1[sizeof(type_name_1)]; -# char dummy2[sizeof(type_name_2)]; -# -# for defined type names. -m4_define([b4_char_sizeof], -[b4_symbol_if([$1], [has_type], -[ -m4_map([ b4_symbol_tag_comment], [$@])dnl - char _b4_char_sizeof_dummy@{sizeof(b4_symbol([$1], [type]))@}; -])]) - - -# b4_variant_includes -# ------------------- -# The needed includes for variants support. -m4_define([b4_variant_includes], -[b4_parse_assert_if([[#include ]])[ -#ifndef YYASSERT -# include -# define YYASSERT assert -#endif -]]) - -# b4_variant_define -# ----------------- -# Define "variant". -m4_define([b4_variant_define], -[[ /// A char[S] buffer to store and retrieve objects. - /// - /// Sort of a variant, but does not keep track of the nature - /// of the stored data, since that knowledge is available - /// via the current state. - template - struct variant - { - /// Type of *this. - typedef variant self_type; - - /// Empty construction. - variant () - : yybuffer_ ()]b4_parse_assert_if([ - , yytypeid_ (YY_NULLPTR)])[ - {} - - /// Construct and fill. - template - variant (const T& t)]b4_parse_assert_if([ - : yytypeid_ (&typeid (T))])[ - { - YYASSERT (sizeof (T) <= S); - new (yyas_ ()) T (t); - } - - /// Destruction, allowed only if empty. - ~variant () - {]b4_parse_assert_if([ - YYASSERT (!yytypeid_); - ])[} - - /// Instantiate an empty \a T in here. - template - T& - build () - {]b4_parse_assert_if([ - YYASSERT (!yytypeid_); - YYASSERT (sizeof (T) <= S); - yytypeid_ = & typeid (T);])[ - return *new (yyas_ ()) T (); - } - - /// Instantiate a \a T in here from \a t. - template - T& - build (const T& t) - {]b4_parse_assert_if([ - YYASSERT (!yytypeid_); - YYASSERT (sizeof (T) <= S); - yytypeid_ = & typeid (T);])[ - return *new (yyas_ ()) T (t); - } - - /// Accessor to a built \a T. - template - T& - as () - {]b4_parse_assert_if([ - YYASSERT (yytypeid_); - YYASSERT (*yytypeid_ == typeid (T)); - YYASSERT (sizeof (T) <= S);])[ - return *yyas_ (); - } - - /// Const accessor to a built \a T (for %printer). - template - const T& - as () const - {]b4_parse_assert_if([ - YYASSERT (yytypeid_); - YYASSERT (*yytypeid_ == typeid (T)); - YYASSERT (sizeof (T) <= S);])[ - return *yyas_ (); - } - - /// Swap the content with \a other, of same type. - /// - /// Both variants must be built beforehand, because swapping the actual - /// data requires reading it (with as()), and this is not possible on - /// unconstructed variants: it would require some dynamic testing, which - /// should not be the variant's responsability. - /// Swapping between built and (possibly) non-built is done with - /// variant::move (). - template - void - swap (self_type& other) - {]b4_parse_assert_if([ - YYASSERT (yytypeid_); - YYASSERT (*yytypeid_ == *other.yytypeid_);])[ - std::swap (as (), other.as ()); - } - - /// Move the content of \a other to this. - /// - /// Destroys \a other. - template - void - move (self_type& other) - { - build (); - swap (other); - other.destroy (); - } - - /// Copy the content of \a other to this. - template - void - copy (const self_type& other) - { - build (other.as ()); - } - - /// Destroy the stored \a T. - template - void - destroy () - { - as ().~T ();]b4_parse_assert_if([ - yytypeid_ = YY_NULLPTR;])[ - } - - private: - /// Prohibit blind copies. - self_type& operator=(const self_type&); - variant (const self_type&); - - /// Accessor to raw memory as \a T. - template - T* - yyas_ () - { - void *yyp = yybuffer_.yyraw; - return static_cast (yyp); - } - - /// Const accessor to raw memory as \a T. - template - const T* - yyas_ () const - { - const void *yyp = yybuffer_.yyraw; - return static_cast (yyp); - } - - union - { - /// Strongest alignment constraints. - long double yyalign_me; - /// A buffer large enough to store any of the semantic values. - char yyraw[S]; - } yybuffer_;]b4_parse_assert_if([ - - /// Whether the content is built: if defined, the name of the stored type. - const std::type_info *yytypeid_;])[ - }; -]]) - - -## -------------------------- ## -## Adjustments for variants. ## -## -------------------------- ## - - -# b4_value_type_declare -# --------------------- -# Declare semantic_type. -m4_define([b4_value_type_declare], -[[ /// An auxiliary type to compute the largest semantic type. - union union_type - {]b4_type_foreach([b4_char_sizeof])[}; - - /// Symbol semantic values. - typedef variant semantic_type;][]dnl -]) - - -# How the semantic value is extracted when using variants. - -# b4_symbol_value(VAL, [TYPE]) -# ---------------------------- -m4_define([b4_symbol_value], -[m4_ifval([$2], - [$1.as< $2 > ()], - [$1])]) - -# b4_symbol_value_template(VAL, [TYPE]) -# ------------------------------------- -# Same as b4_symbol_value, but used in a template method. -m4_define([b4_symbol_value_template], -[m4_ifval([$2], - [$1.template as< $2 > ()], - [$1])]) - - - -## ------------- ## -## make_SYMBOL. ## -## ------------- ## - - -# b4_symbol_constructor_declare_(SYMBOL-NUMBER) -# --------------------------------------------- -# Declare the overloaded version of make_symbol for the (common) type of -# these SYMBOL-NUMBERS. Use at class-level. -m4_define([b4_symbol_constructor_declare_], -[b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id], -[ static inline - symbol_type - make_[]b4_symbol_([$1], [id]) (dnl -b4_join(b4_symbol_if([$1], [has_type], - [const b4_symbol([$1], [type])& v]), - b4_locations_if([const location_type& l]))); - -])])]) - - -# b4_symbol_constructor_declare -# ----------------------------- -# Declare symbol constructors for all the value types. -# Use at class-level. -m4_define([b4_symbol_constructor_declare], -[ // Symbol constructors declarations. -b4_symbol_foreach([b4_symbol_constructor_declare_])]) - - - -# b4_symbol_constructor_define_(SYMBOL-NUMBER) -# -------------------------------------------- -# Define symbol constructor for this SYMBOL-NUMBER. -m4_define([b4_symbol_constructor_define_], -[b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id], -[ b4_parser_class_name::symbol_type - b4_parser_class_name::make_[]b4_symbol_([$1], [id]) (dnl -b4_join(b4_symbol_if([$1], [has_type], - [const b4_symbol([$1], [type])& v]), - b4_locations_if([const location_type& l]))) - { - return symbol_type (b4_join([token::b4_symbol([$1], [id])], - b4_symbol_if([$1], [has_type], [v]), - b4_locations_if([l]))); - } - -])])]) - - -# b4_basic_symbol_constructor_declare -# ----------------------------------- -# Generate a constructor declaration for basic_symbol from given type. -m4_define([b4_basic_symbol_constructor_declare], -[[ - basic_symbol (]b4_join( - [typename Base::kind_type t], - b4_symbol_if([$1], [has_type], const b4_symbol([$1], [type])[& v]), - b4_locations_if([const location_type& l]))[); -]]) - -# b4_basic_symbol_constructor_define -# ---------------------------------- -# Generate a constructor implementation for basic_symbol from given type. -m4_define([b4_basic_symbol_constructor_define], -[[ - template - ]b4_parser_class_name[::basic_symbol::basic_symbol (]b4_join( - [typename Base::kind_type t], - b4_symbol_if([$1], [has_type], const b4_symbol([$1], [type])[& v]), - b4_locations_if([const location_type& l]))[) - : Base (t)]b4_symbol_if([$1], [has_type], [ - , value (v)])[]b4_locations_if([ - , location (l)])[ - {} -]]) - -# b4_symbol_constructor_define -# ---------------------------- -# Define the overloaded versions of make_symbol for all the value types. -m4_define([b4_symbol_constructor_define], -[ // Implementation of make_symbol for each symbol type. -b4_symbol_foreach([b4_symbol_constructor_define_])]) diff --git a/bison/data/xslt/bison.xsl b/bison/data/xslt/bison.xsl index 9f9132b..5c1a358 100644 --- a/bison/data/xslt/bison.xsl +++ b/bison/data/xslt/bison.xsl @@ -3,7 +3,7 @@ + referred to directly in XPath expressions. --> @@ -95,7 +95,7 @@ - 0 diff --git a/bison/data/xslt/xml2text.xsl b/bison/data/xslt/xml2text.xsl index 747c32b..72b56e7 100644 --- a/bison/data/xslt/xml2text.xsl +++ b/bison/data/xslt/xml2text.xsl @@ -3,7 +3,7 @@