From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- .../libs/metaparse/example/calculator/Jamfile.v2 | 6 + src/boost/libs/metaparse/example/calculator/README | 1 + .../libs/metaparse/example/calculator/main.cpp | 157 +++++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 src/boost/libs/metaparse/example/calculator/Jamfile.v2 create mode 100644 src/boost/libs/metaparse/example/calculator/README create mode 100644 src/boost/libs/metaparse/example/calculator/main.cpp (limited to 'src/boost/libs/metaparse/example/calculator') diff --git a/src/boost/libs/metaparse/example/calculator/Jamfile.v2 b/src/boost/libs/metaparse/example/calculator/Jamfile.v2 new file mode 100644 index 000000000..887cff6a8 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator/Jamfile.v2 @@ -0,0 +1,6 @@ +project : requirements + gcc:-ftemplate-depth=512 + clang:-ftemplate-depth=512 +; + +exe calculator : main.cpp ; diff --git a/src/boost/libs/metaparse/example/calculator/README b/src/boost/libs/metaparse/example/calculator/README new file mode 100644 index 000000000..8229ef4b0 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator/README @@ -0,0 +1 @@ +Calculator, working at compile-time diff --git a/src/boost/libs/metaparse/example/calculator/main.cpp b/src/boost/libs/metaparse/example/calculator/main.cpp new file mode 100644 index 000000000..fc0dbffa1 --- /dev/null +++ b/src/boost/libs/metaparse/example/calculator/main.cpp @@ -0,0 +1,157 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using boost::metaparse::sequence; +using boost::metaparse::lit_c; +using boost::metaparse::last_of; +using boost::metaparse::first_of; +using boost::metaparse::space; +using boost::metaparse::repeated; +using boost::metaparse::build_parser; +using boost::metaparse::int_; +using boost::metaparse::foldl_reject_incomplete_start_with_parser; +using boost::metaparse::get_result; +using boost::metaparse::one_of; +using boost::metaparse::token; +using boost::metaparse::entire_input; + +using boost::mpl::apply_wrap1; +using boost::mpl::fold; +using boost::mpl::front; +using boost::mpl::back; +using boost::mpl::plus; +using boost::mpl::minus; +using boost::mpl::times; +using boost::mpl::divides; +using boost::mpl::eval_if; +using boost::mpl::bool_; +using boost::mpl::equal_to; +using boost::mpl::bool_; + +/* + * The grammar + * + * expression ::= plus_exp + * plus_exp ::= prod_exp ((plus_token | minus_token) prod_exp)* + * prod_exp ::= int_token ((mult_token | div_token) int_token)* + */ + +typedef token > plus_token; +typedef token > minus_token; +typedef token > mult_token; +typedef token > div_token; + +typedef token int_token; + +template +struct is_c : bool_ {}; + +struct eval_plus +{ + template + struct apply : + eval_if< + is_c, '+'>, + plus::type>, + minus::type> + > + {}; +}; + +struct eval_mult +{ + template + struct apply : + eval_if< + is_c, '*'>, + times::type>, + divides::type> + > + {}; +}; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence, int_token>, + int_token, + eval_mult + > + prod_exp; + +typedef + foldl_reject_incomplete_start_with_parser< + sequence, prod_exp>, + prod_exp, + eval_plus + > + plus_exp; + +typedef last_of, plus_exp> expression; + +typedef build_parser > calculator_parser; + +#ifdef _STR +# error _STR already defined +#endif +#define _STR BOOST_METAPARSE_STRING + +#if BOOST_METAPARSE_STD < 2011 +int main() +{ + using std::cout; + using std::endl; + using boost::metaparse::string; + + cout + << apply_wrap1 >::type::value << endl + << + apply_wrap1< + calculator_parser, string<' ','1','+',' ','2','*','4','-','6','/','2'> + >::type::value + << endl + ; +} +#else +int main() +{ + using std::cout; + using std::endl; + + cout + << apply_wrap1::type::value << endl + << apply_wrap1::type::value << endl + ; +} +#endif + + -- cgit v1.2.3