A glr_state keeps tracks of its predecessor using an offset relative
to itself (i.e., pointer subtraction). Unfortunately we sometimes
have to compute offsets for pointers that live in different
containers, in particular in yyfillin. In that case there is no
reason for the distance between the two objects to be a multiple of
the object size (0x40 on my machine), and the resulting ptrdiff_t may
be "wrong", i.e., it does allow to recover one from the other. We
cannot use "typed" pointer arithmetics here, the Euclidean division
has it wrong. So use "plain" char* pointers.
Fixes 718 (Duplicate representation of merged trees: glr2.cc) and
examples/c++/glr/c++-types.
Still XFAIL:
712: Improper handling of embedded actions and dollar(-N) in GLR parsers: glr2.cc
730: Incorrectly initialized location for empty right-hand side in GLR: glr2.cc
748: Incorrect lookahead during nondeterministic GLR: glr2.cc
* data/skeletons/glr2.cc (glr_state::as_pointer_): New.
(glr_state::pred): Use it.
* examples/c++/glr/c++-types.test: The test passes.
* tests/glr-regression.at (Duplicate representation of merged trees:
glr2.cc): Passes.
Examples in C++
This directory contains examples of Bison grammar files in C++.
You can run make to compile these examples. And make clean to tidy
afterwards.
simple.yy - Simple example in C++14
A very simple example in C++, based on variants and symbol constructors. Variants allow to use any C++ type as semantic value type, and symbol constructors ensure consistency between declared token kind and effective semantic value.
Run as ./simple.
Extracted from the documentation: A Simple C++ Example.
variant.yy - Self-contained example in C++98
A variation of simple.yy, in C++98.
Run as ./variant.
variant-11.yy - Self-contained example in modern C++
Another variation of simple.yy, closely related to the previous one, but exhibiting support for C++11's move semantics.
Run as ./variant or ./variant NUMBER.
calc++ - A Complete C++ Example
A fully featured C++ version of the canonical example for parsers: a calculator. Also uses Flex for the scanner.
Don't look at this example first: it is fully featured and can serve as a starting point for a clean parser in C++. The previous examples are better introductory examples, and the C examples are also useful introductory examples.
Extracted from the documentation: A Complete C++ Example.