3

Can't compile any example on Ubuntu 16.04

$ g++ -std=c++14  main.cpp
In file included from /usr/include/boost/spirit/home/x3/nonterminal.hpp:14:0,
                 from /usr/include/boost/spirit/home/x3.hpp:20,
                 from main.cpp:23:
main.cpp:226:9: error: ‘client::calculator_grammar::parse_rule’ declared as an ‘inline’ variable
         BOOST_SPIRIT_DEFINE(
         ^
main.cpp:226:9: error: expected ‘)’ before ‘rule_’
         BOOST_SPIRIT_DEFINE(
         ^
main.cpp:226:9: error: expected primary-expression before ‘&’ token
         BOOST_SPIRIT_DEFINE(
         ^
main.cpp:226:9: error: ‘first’ was not declared in this scope
         BOOST_SPIRIT_DEFINE(
         ^

this is a spirit::x3 bug?

1 Answers1

1

Two changes:

  1. add the missing include

    #include <boost/foreach.hpp>
    
  2. choose "new style" macro usage:

    BOOST_SPIRIT_DEFINE(expression , term , factor);
    

To be honest, I didn't know the p = p_def style initialization was possible. I suspect it was the required syntax before X3 was released.

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Yes, [this](https://github.com/boostorg/spirit/blob/boost-1.64.0/example/x3/calc/calc5.cpp) is the example the OP wants ([diff](https://www.diffchecker.com/LZQmA4NQ)). – llonesmiz Jun 04 '17 at 11:07
  • @llonesmiz Ah, obviously. I never even checked the link :) – sehe Jun 04 '17 at 11:44