Commit Graph

1040 Commits

Author SHA1 Message Date
Akim Demaille
bc19eadd65 glr.c: style changes
* data/glr.c (yyuserAction): Use a size_t for sizes.
2013-01-11 18:57:09 +01:00
Akim Demaille
1092d69c34 c.m4: style fix
* data/c.m4 (b4_parse_param_use): Add missing space before paren.
2013-01-11 18:57:09 +01:00
Theophile Ranquet
99d795e8f2 skel: better aliasing of identifiers
* data/glr.c, data/yacc.c: Avoid emitting useless defines.
* data/glr.cc: Restore prefixes for epilogue.
2013-01-11 18:57:09 +01:00
Theophile Ranquet
0707d0c7fa glr.cc: fatal if using api.token.ctor without variants
* data/glr.cc: Here.
2013-01-11 18:57:09 +01:00
Theophile Ranquet
462b243e1d skel: correctly indent switch cases
* data/bison.m4 (b4_type_action_): Here.
2013-01-11 18:57:08 +01:00
Theophile Ranquet
bb1f0f5226 variants: assert changes
* data/variant.hh (swap): More asserts can't hurt. Don't perform useless swaps.
(build): Deactivate problematic asserts, pending further investigation.
(variant): Prohibit copy construction.
2013-01-11 18:57:08 +01:00
Theophile Ranquet
e7b26e942d lalr1.cc: use a vector for the symbol stack
* data/lalr1.cc: Adjust includes.
* data/stack.hh (push, pop): Use push_back and pop_back.
(operator []): Access vector from the end.
2013-01-11 18:57:08 +01:00
Theophile Ranquet
1dbaf37f5c lalr1.cc: change symbols implementation
A "symbol" groups together the symbol type (INT, PLUS, etc.), its
possible semantic value, and its optional location.  The type is
needed to access the value, as it is stored as a variant/union.

There are two kinds of symbols. "symbol_type" are "external symbols":
they have type, value and location, and are returned by yylex.
"stack_symbol_type" are "internal symbols", they group state number,
value and location, and are stored in the parser stack.  The type of
the symbol is computed from the state number.

The class template symbol_base_type<Exact> factors the code common to
stack_symbol_type and symbol_type.  It uses the Curiously Recurring
Template pattern so that we can always (static_) downcast to the exact
type.  symbol_base_type features value and location, and delegates the
handling of the type to its parameter.

When trying to generalize the support for variant, a significant issue
was revealed: because stack_symbol_type and symbol_type _derive_ from
symbol_base_type, the type/state member is defined _after_ the value
and location.  In C++ the order of the definition of the members
defines the order in which they are initialized, things go backward:
the value is initialized _before_ the type.  This is wrong, since the
type is needed to access the value.

Therefore, we need another means to factor the common code, one that
ensures the order of the members.

The idea is simple: define two (base) classes that code the symbol
type ("by_type" codes it by its type, and "by_state" by the state
number).  Define basic_symbol<Base> as the class template that
provides value and location support.  Make it _derive_ from its
parameter, by_type or by_state.  Then define stack_symbol_type and
symbol_type as basic_symbol<by_state>, basic_symbol<by_type>.  The
name basic_symbol was chosen by similarity with basic_string and
basic_ostream.

* data/c++.m4 (symbol_base_type<Exact>): Remove, replace by...
(basic_symbol<Base>): which derives from its parameter, one of...
(by_state, by_type): which provide means to retrieve the actual type of
symbol.
(symbol_type): Is now basic_symbol<by_type>.
(stack_symbol_type): Is now basic_symbol<by_state>.
* data/lalr1.cc: Many adjustments.
2013-01-11 18:57:08 +01:00
Akim Demaille
4119d1ea60 java: stype is obsoleted by api.value.type
This is consistent with the other %define variable names.

* data/java.m4: Use api.value.type instead of stype.
* doc/bison.texi, NEWS: Document that change.
* src/muscle-tab.c (muscle_percent_variable_update): Provide backward
compatibility.
* tests/java.at: Adjust.
2012-12-31 16:32:12 +01:00
Akim Demaille
d2e3c807dc syncline: one line is enough
So far we were issuing two lines for each syncline change:

  /* Line 356 of yacc.c  */
  #line 1 "src/parse-gram.y"

This is a lot of clutter, especially when reading diffs, as these
lines change often.  Fuse them into a single, shorter, line:

  #line 1 "src/parse-gram.y" /* yacc.c:356  */

* data/bison.m4 (b4_syncline): Issue a single line.
Comment improvements.
(b4_sync_start, b4_sync_end): Issue a shorter comment.
* data/c++.m4 (b4_semantic_type_declare): b4_user_code must be
on its own line as it might start with a "#line" directive.
2012-12-28 11:37:22 +01:00
Akim Demaille
c5ae8e85aa maint: restore ANSI 89 compliance
* data/bison.m4, src/conflicts.c, src/files.c, src/output.c,
* src/symtab.c: Use /* ... */ comments only.
Declare variables before statements.
2012-12-28 11:37:21 +01:00
Akim Demaille
6f0a6f274c skeletons: fix comments
The commit 38de4e570f underquoted the
content of the comments, which resulted in losing square brackets in
the comments.  Besides, some other invocations were underquoting the
effective arguments.

* data/c.m4 (b4_comment_): Properly quote the comment.
(b4_comment_, b4_comment): Move to...
* data/c-like.m4: here, so that...
* data/java.m4: can use it instead of its own copy.
* data/bison.m4 (b4_integral_parser_tables_map): Fix some comments.

* data/lalr1.cc, data/lalr1.java, data/yacc.c: Comment fixes.

* data/lalr1.cc: Reorder a bit to factor some CPP directives.
2012-12-27 10:30:14 +01:00
Akim Demaille
e672a4ba5e maint: which -> whose
Apparently, I was confusing both.

* data/bison.m4, data/c.m4, data/glr.c, data/lalr1.cc, data/yacc.c:
Use "whose" where appropriate.
2012-12-27 09:45:17 +01:00
Akim Demaille
64b3612ab1 skeletons: no longer call yylex via a CPP macro
The YYLEX existed only to support YYLEX_PARAM, which is now removed.
This macro was a nuisance, since incorrect yylex calls where pointed
the macro _use_, instead of its definition.

* data/c.m4 (b4_lex_formals, b4_lex): New.
* data/glr.c, data/yacc.c: Use it.
* data/lalr1.cc (b4_lex): New.
Use it.

squash! skeletons: no longer call yylex via a CPP macro
2012-12-26 10:38:59 +01:00
Akim Demaille
40bb6f78f8 YYLEX_PARAM: drop support
* data/yacc.c, doc/bison.texi: Remove YYLEX_PARAM support.
* NEWS: Document it.
2012-12-26 10:38:59 +01:00
Akim Demaille
3fd1d6b2f3 skeletons: factor comments about symbols
* data/variant.hh (b4_char_sizeof_): Rename as...
* data/bison.m4 (b4_symbol_tag_comment): this.
Provide more documentation about b4_symbol_*.
2012-12-26 10:38:58 +01:00
Akim Demaille
4d9bdbe384 c: improve the definition of public types
* data/c.m4 (b4_token_enum): Improve comments.
(b4_value_type_define, b4_location_type_define): New, extracted
from...
(b4_declare_yylstype): here.
Separate the typedefs from the union/struct definitions.
2012-12-26 10:38:58 +01:00
Akim Demaille
bc6038978f %define variables: support value changes in deprecation
* src/muscle-tab.c (define_directive): Be robust to "assignment"
containing '='.
(muscle_percent_variable_update): Upgrade "variant" to "api.value.type".
Support such upgrade patterns.
Adjust callers.

* data/bison.m4: Use api.value.type for variants.
* tests/c++.at: Adjust tests.
2012-12-23 11:14:11 +01:00
Akim Demaille
acb741cd8c skeletons: fix an error message
* data/bison.m4 (b4_flag_if): Display the invalid value.
2012-12-23 10:23:32 +01:00
Akim Demaille
ac826bc4b1 c++: comment changes
* data/c++.m4, data/glr.cc, data/lalr1.cc: Convert some /* ... */
comments to //.
2012-12-23 10:23:14 +01:00
Akim Demaille
38de4e570f c++: use // comments in the output
This is mostly used for the license header, the synclines, and the
generated tables:

-  /* STOS_[STATE-NUM] -- The (internal number of the) accessing
-     symbol of state STATE-NUM.    */
+  // STOS_[STATE-NUM] -- The (internal number of the) accessing
+  // symbol of state STATE-NUM.
   static const unsigned char yystos_[];

* data/c.m4: Comment changes.
(b4_comment_): Expand the text argument.
Before this change, we were actually formatting M4 code as a
C comment, and then expand it.
(b4_comment): Fix the closing of comments: there is no reason to
add the (line) prefix before the closing "*/".
* data/c++.m4 (b4_comment): New.
2012-12-23 09:53:45 +01:00
Akim Demaille
975bdced50 style changes: untabify
* data/xslt/xml2dot.xsl, data/xslt/xml2text.xsl, m4/flex.m4,
* tests/glr-regression.at, tests/torture.at: here.
2012-12-21 16:53:57 +01:00
Akim Demaille
7be08dfbe7 variants: prohibit simple copies
The "variant" structure provides a means to store, in a typeless way,
C++ objects.  Manipulating it without provide the type of the stored
content is doomed to failure.  So provide a means to copy in a type
safe way, and prohibit typeless assignments.

* data/c++.m4 (symbol_type::move): New.
* data/lalr1.cc: Use it.
* data/variant.hh (b4_variant_define): Provide variant::copy.
Let variant::operator= abort.
We cannot undefine it, yet, as it is still uses by the implicit
assigment in symbols, which must also be disabled.
2012-12-19 11:30:22 +01:00
Akim Demaille
35f70d169f variant: more assertions
Equip variants with more checking code.  Provide a means to request
includes.

* data/variant.hh (b4_variant_includes): New.
* data/lalr1.cc: Use it.
* data/variant.hh (variant::built): Define at the end, as a private member.
(variant::tname): New.
Somewhat makes "built" useless, but let's keep both for a start, in
case using "typeinfo" is considered unacceptable in some environments.
Fix some formatting issues.
2012-12-19 11:30:22 +01:00
Akim Demaille
eaf690a700 skeletons: fix output directives
* data/lalr1.cc, data/location.cc, data/glr.cc: Use b4_output_begin.
Broken during a merge.
2012-12-19 11:29:51 +01:00
Akim Demaille
56441943d0 yacc.c: style changes
* data/yacc.c (b4_lex_param): Provide arguments with a name.
2012-12-19 11:26:01 +01:00
Akim Demaille
65e0291619 glr.cc: simplifying the handling of parse/lex params
The fact that glr.cc uses glr.c makes the handling of parse params
more complex, as the parser object of glr.cc must be passed to the
parse function of glr.c.  Yet not all the functions need access to
the parser object.

* data/glr.cc (b4_parse_param_wrap): New.
Use them.
2012-12-19 11:26:00 +01:00
Akim Demaille
ca90437a61 glr: rename lex params
* data/glr.c (b4_lex_param): Rename as...
(b4_lex_formals): this, for consistency.
Provide arguments a name.
(LEX): Adjust.
2012-12-19 11:26:00 +01:00
Akim Demaille
ea45ade792 glr.c: move function declaration earlier
* data/glr.c (yypstack, yypdumpstack): Declare earlier, to make
it easier to call them from other functions.
2012-12-19 11:26:00 +01:00
Akim Demaille
bcd80897f3 skeletons: simplify the handling of default api.location.type
* data/bison.m4 (b4_bison_locations_if): New.
* data/glr.cc, data/lalr1.cc: Use it.
2012-12-16 10:33:42 +01:00
Akim Demaille
b9278c7d17 Merge branch 'origin/maint'
* origin/maint:
  maint: credit Wojciech Polak
  maint: post-release administrivia
  version 2.7
  yacc.c: scope reduction
  tests: C90 compliance
  fix C90 compliance
  glr.c: scope reduction
  gnulib: update

Conflicts:
	NEWS
	gnulib
	src/scan-gram.l
	src/system.h
2012-12-14 13:58:04 +01:00
Akim Demaille
4b6d641913 yacc.c: scope reduction
* data/yacc.c (yysyntax_error): here.
2012-12-12 12:41:37 +01:00
Akim Demaille
1127a75a72 fix C90 compliance
* data/glr.c, src/graphviz.h, src/ielr.c, src/scan-gram.l,
* src/system.h, tests/actions.at, tests/glr-regression.at: Do not
use // comments.
Do not introduce variables after statements.
Provide "main" with a return value.
2012-12-12 11:44:39 +01:00
Akim Demaille
fc28638e1c glr.c: scope reduction
* data/glr.c (yyreportSyntaxError): Reduce the scope of yysize1 (now
yysz).
2012-12-12 11:28:24 +01:00
Theophile Ranquet
f3ead217b8 Merge remote-tracking branch 'origin/maint'
* origin/maint:
  misc: pacify the Tiny C Compiler
  cpp: make the check of Flex version portable
  misc: require getline
  c++: support wide strings for file names
  doc: document carets
  tests: enhance existing tests with carets
  errors: show carets
  getargs: add support for --flags/-f

Conflicts:
	doc/bison.texi
	m4/.gitignore
	src/complain.c
	src/flex-scanner.h
	src/getargs.c
	src/getargs.h
	src/gram.c
	src/main.c
	tests/headers.at
2012-12-06 13:38:43 +01:00
Akim Demaille
7ae57e2a35 c++: support wide strings for file names
Reported by Mark Boyall.
http://lists.gnu.org/archive/html/help-bison/2011-08/msg00002.html

* data/location.cc (operator<<): Be templated on the type of
output stream.
* tests/headers.at (Several parsers): Adjust.
2012-12-05 13:22:21 +01:00
Akim Demaille
064e42b0ac Merge remote-tracking branch 'origin/maint'
* origin/maint:
  parser: accept #line NUM
  m4: use a safer pattern to enable/disable output
  tests: beware of gnulib's need for config.h
  gnulib: update
  yacc.c, glr.c: check and fix the display of locations
  formatting changes
  glr.c: remove stray macro

Conflicts:
	data/c.m4
	data/glr.cc
	data/lalr1.cc
	data/lalr1.java
	data/location.cc
	data/stack.hh
	data/yacc.c
	src/scan-gram.l
2012-12-03 16:27:23 +01:00
Akim Demaille
1c7ec959b1 m4: use a safer pattern to enable/disable output
Work on some other areas of Bison revealed that some macros expanded
to be expanded only once were actually expanded several times.  This
was due to the fact that changecom was not properly restored each
time, and macro names appearing in comments were then expanded.

Introduce begin/end macros which are easier to match that
changecom()/changecom(#).

* data/bison.m4 (b4_output_begin, b4_output_end): New.
* data/glr.c, data/glr.cc, data/lalr1.cc, data/lalr1.java,
* data/location.cc, data/stack.hh, data/yacc.c:
Use them.
2012-12-03 15:44:40 +01:00
Akim Demaille
3804aa260b yacc.c, glr.c: check and fix the display of locations
In some case, negative column number could be displayed.
Make YY_LOCATION_PRINT similar to bison's own implementation of
locations.  Since the macro is getting fat, make it a static
function.
Reported by Jonathan Fabrizio.

* data/c.m4 (yy_location_print_define): Improve the implementation,
and generate the yy_location_print_ function.
Adjust YY_LOCATION_PRINT.
* tests/actions.at (Location Print): New tests.
2012-11-30 11:19:43 +01:00
Akim Demaille
4c36bc2b8d formatting changes
* data/c.m4: Fix comments, put macros in a more natural order.
Space changes (from M-x whitespace-cleanup).
* src/location.c: Fix spaces.
* tests/actions.at: Space changes.
2012-11-30 11:19:33 +01:00
Akim Demaille
5215919366 glr.c: remove stray macro
* data/glr.c (YYOPTIONAL_LOC): Remove, unused since commit
769a8ef9bc.
2012-11-30 11:15:12 +01:00
Akim Demaille
5807bb9156 Merge remote-tracking branch 'origin/maint'
* origin/maint:
  doc: minor fixes
  doc: improve the index
  doc: introduce api.pure full, rearrange some examples
  yacc.c: support "%define api.pure full"
  local.at: improvements

Conflicts:
	NEWS
	data/yacc.c
	doc/bison.texi
	tests/calc.at
2012-11-29 15:20:03 +01:00
Theophile Ranquet
6428a8a4a5 yacc.c: support "%define api.pure full"
This makes the interface for yyerror() pure without the need for a spurious
parse_param.

* data/yacc.c (b4_pure_if, b4_pure_flag): New definition, accept three states.
(b4_yacc_pure_if): Rename as...
(b4_yyerror_arg_loc_if): This, and use b4_pure_flag.
* tests/actions.at (%define api.pure): Modernize.
* test/calc.at (Simple LALR Calculator): Modernize.
* tests/local.at (AT_YYERROR_ARG_LOC_IF): Adjust.
2012-11-29 11:08:36 +01:00
Akim Demaille
c6b1772473 Merge remote-tracking branch 'origin/maint'
* origin/maint:
  yacc.c: always initialize yylloc
  scanner: issue a single error for groups of invalid characters
  tests: formatting changes
  doc: one of the fixes for an ambiguous grammar was ambiguous too
  doc: fix the dangling else with precedence directives
  doc: prefer "token" to TOKEN
  doc: formatting changes
  scanner: use explicit "ignore" statements

Conflicts:
	src/scan-gram.l
2012-11-26 09:41:35 +01:00
Akim Demaille
c6bf97ccb4 Merge remote-tracking branch 'origin/branch-2.6' into maint
* origin/branch-2.6:
  yacc.c: always initialize yylloc
  doc: one of the fixes for an ambiguous grammar was ambiguous too
  doc: fix the dangling else with precedence directives
  doc: prefer "token" to TOKEN
  doc: formatting changes

Conflicts:
	NEWS
	doc/bison.texi
2012-11-26 09:05:28 +01:00
Theophile Ranquet
fb4c8a7cb9 yacc.c: always initialize yylloc
The initial location might be used if the parser starts by an empty
reduction, so really ensure proper initialization of the initial
location.  The previous approach fails for PostgreSQL, which uses
Reported by Peter Eisentraut.
http://lists.gnu.org/archive/html/bug-bison/2012-11/msg00023.html
With help from Théophile Ranquet.

* data/yacc.c (b4_declare_scanner_communication_variables): Be sure
to initialize yylloc, even when its structure is unknown.
(yyparse): Simplify the call to b4_dollar_pushdef.
* tests/actions.at (Initial location): Check of similar pattern
as in the case of PostgreSQL.
2012-11-23 15:44:19 +01:00
Akim Demaille
06ec0105b1 Merge remote-tracking branch 'origin/maint'
* origin/maint:
  tests: close files in glr-regression
  xml: match DOT output and xml2dot.xsl processing
  xml: factor xslt space template
  graph: fix a memory leak
  xml: documentation
  output: capitalize State
2012-11-13 10:59:55 +01:00
Theophile Ranquet
be3517b007 xml: match DOT output and xml2dot.xsl processing
Make the DOT produced by XSLT processing equivalent to the one made with the
--graph option.

* data/xslt/xml2dot.xsl: Stylistic changes, and add support for reductions.
* doc/bison.texi (Xml): Update.
* src/graphviz.c (conclude_red): Minor stylistic changes to DOT internals.
(output_red): Swap enabled and disabled reductions output, for coherence
with XSLT output.
* src/print_graph.c (print_core): Minor stylistic change to States' output.
(print_actions): Swap order of output for reductions and transitions.
* tests/local.at (AT_BISON_CHECK_XML): Ignore differences in order.
* tests/output.at: Adjust to changes in DOT internals.
2012-11-12 16:46:55 +01:00
Theophile Ranquet
489b320d4a xml: factor xslt space template
* data/xslt/bison.xsl (space): New, import from...
* data/xslt/xml2text.xsl: Here.
2012-11-12 16:45:09 +01:00
Akim Demaille
e42906f790 Merge remote-tracking branch 'origin/maint'
* origin/maint: (24 commits)
  tests: calc: modernize the use of locations
  tests: remove useless location initializations
  lalr1.cc: always initialize yylval.
  tests: check that C and C++ objects can be linked together.
  yacc.c: also disable -Wuninitialized.
  glr.cc, yacc.c: initialize yylloc properly
  yacc.c, glr.c: a better YY_LOCATION_PRINT
  yacc.c: simplify initialization
  doc: formatting changes
  c++: fix position operator signatures
  tests: remove useless location initialization.
  tests: fix locations in C
  tests: handle %parse-param in the generated yyerror
  tests: simplifications
  grammars: fix display of nul character in error message
  tests: sort
  tests: cosmetic changes
  comment changes
  autoconf: update
  gnulib: update
  ...

Conflicts:
	data/lalr1.cc
	gnulib
	src/scan-gram.l
	submodules/autoconf
	tests/calc.at
2012-11-06 18:30:16 +01:00