Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8501301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:10:29+00:00 2026-06-11T01:10:29+00:00

[Replaced code by a complete program and versions update] The code below fails under

  • 0

[Replaced code by a complete program and versions update]

The code below fails under Windows with the following message (sorry manualy translated from
French, I don’t know how to force Visual C++ to work in English). This is
under Windows. It works under Linux. You can compile with
Linux: gcc LimaTokenizerParser.cpp -o LimaTokenizerPars -lboost_system-mt -lstdc++
Windows(fails): cl LimaTokenizerParser.cpp /Ic:\boost\path\include /EHsc

I use Boost 1.50 with Visual C++ 2010 under Windows and Boost 1.48
and gcc 4.6.3 under Linux.

The assertion in boost grammar.hpp is accompanied by this comment:

// If you see the assertion below failing then the start rule
// passed to the constructor of the grammar is not compatible with
// the grammar (i.e. it uses different template parameters).

but I don’t understand how to understand it in my case…

Any idea ?

Regards,

Gaël

Code:

LimaTokenizerParser.cpp

#include "SpiritTokenizerParser.hpp"

#include <iostream>
#include <fstream>

void readStream(std::istream &is,std::string &dest)
{
  while (is.good() && !is.eof())
  {
    const int bufferSize = 10240;
    char buffer[bufferSize];
    is.read(buffer,bufferSize);
    const int size = is.gcount();
    if (size>0)
      dest.insert(dest.end(),buffer,buffer+size);
  }
}

int main(int argc, char* argv[])
{
  if (argc != 2)
  {
    std::cerr << "Needs exactly one argument" << std::endl;
    return 1;
  }
  namespace qi = boost::spirit::qi;
  namespace ascii = boost::spirit::ascii;
  using ascii::space;
  typedef std::string::const_iterator iterator_type;
  typedef tokenizer<iterator_type> tokenizer;

  // @ERROR DOES NOT WORK ON WINDOWS PORT
 tokenizer tokenizer_parser; 
  std::string str;
  std::ifstream file(argv[1]);
  readStream(file, str);

  std::string::const_iterator iter = str.begin();
  std::string::const_iterator end = str.end();

  tokenizer_automaton automaton;
  bool r = false;
  // @ERROR DOES NOT WORK ON WINDOWS PORT
  r = phrase_parse(iter, end, tokenizer_parser, skipper, automaton);

  if (r && iter == end)
  {
      std::cout << "Parsing succeeded: "<<automaton.size()<<" states" << std::endl;
  }
  else
  {
      std::string rest(iter, end);
      std::cout << "Parsing failed. Stopped at: \": " << rest << "\"\n";
  }

  return 0;
}

SpiritTokenizerParser.hpp

#ifndef SPIRITTOKENIZERPARSER_HPP
#define SPIRITTOKENIZERPARSER_HPP

#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/io.hpp>

#include <string>

namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;

#define skipper qi::space | ascii::char_('#') >> *(ascii::char_ - qi::eol) >> qi::eol
typedef BOOST_TYPEOF(skipper) skipper_type;

enum transitions {
  STORE,
  FLUSH,
  TOKEN,
  EXIT,
  LTOKEN
};

typedef std::vector<std::string> tokenizer_precondition;
typedef std::vector<std::string> tokenizer_postcondition;
struct tokenizer_transition
{
  std::vector<tokenizer_precondition> preconditions;
  std::vector<std::string> event;
  std::vector<tokenizer_postcondition> postconditions;
  transitions transition;
  std::string target;
  std::vector<std::string> statuses;
};

struct tokenizer_state
{
  std::string id;
  std::vector<tokenizer_transition> transitions;
};

typedef std::vector<tokenizer_state> tokenizer_automaton;

BOOST_FUSION_ADAPT_STRUCT(
                          tokenizer_transition,
                          (std::vector<tokenizer_precondition>, preconditions)
                          (std::vector<std::string>, event)
                          (std::vector<tokenizer_postcondition>, postconditions)
                          (transitions, transition)
                          (std::string, target)
                          (std::vector<std::string>, statuses)
                          )

BOOST_FUSION_ADAPT_STRUCT(
                          tokenizer_state,
                          (std::string, id)
                          (std::vector<tokenizer_transition>, transitions)
                          )

using ascii::space_type;

template <typename Iterator>
struct tokenizer : qi::grammar<Iterator, tokenizer_automaton(), skipper_type>
{
  struct transitionsymbol_ : qi::symbols<char, unsigned>
  {
    // > is +1 store
    // / is +1 flush (forget the current token)
    // = is +1 token
    // ^ is exit

    transitionsymbol_()
    {
      add
      (">", STORE)
      ("/", FLUSH)
      ("=", TOKEN)
      ("^", EXIT)
      ;
    }

  } transitionsymbol;

  tokenizer() : tokenizer::base_type(start)
  {
    using qi::alnum;
    using qi::lexeme;
    using ascii::char_;

    start %= *state ;
    state %= '(' >> identifier >> ')' >> '{' >> *transition >> '}';
    transition %= '-' >> *precondition >> event >> *postcondition >> transitionsymbol >> identifier >> -('(' >> identifier % ',' >> ')');
    identifier %= lexeme[+(alnum | char_('_'))];
    precondition %= '[' >> (identifier % '|') >> ']';
    event %= identifier % '|';
    postcondition %= identifier % '|';
  }

  qi::rule<Iterator, tokenizer_automaton(), skipper_type> start;
  qi::rule<Iterator, tokenizer_state(), skipper_type> state;
  qi::rule<Iterator, tokenizer_transition(), skipper_type> transition;
  qi::rule<Iterator, std::string(), skipper_type> identifier;
  qi::rule<Iterator, std::vector<std::string>(), skipper_type> precondition;
  qi::rule<Iterator, std::vector<std::string>(), skipper_type> event;
  qi::rule<Iterator, std::vector<std::string>(), skipper_type> postcondition;
};

//]

#endif // SPIRITTOKENIZERPARSER_HPP

Messages:

LimaTokenizerParser.cpp
c:\Program Files\boost\boost_1_50\include\boost/spirit/home/qi/nonterminal/grammar.hpp(77) : error C2664: 'boost::mpl::assertion_failed'<FF>: can not convert parameter 1 from 'boost::mpl::failed ************(__cdecl boost::spirit::qi::grammar<Iterator,T1,T2>::{ctor}::incompatible_start_rule::* ***********)(boost::spirit::qi::rule<Iterator,T1,boost::spirit::qi::alternative<Elements>>)' en 'boost::mpl::assert<false>::type'
        with
        [
            Iterator=iterator_type,
            T1=tokenizer_automaton (void),
            T2=skipper_type,
            Elements=boost::fusion::cons<boost::spirit::qi::char_class<boost::spirit::tag::char_code<boost::spirit::tag::space,boost::spirit::char_encoding::standard>>,boost::fusion::cons<boost::spirit::qi::sequence<boost::fusion::cons<boost::spirit::qi::literal_char<boost::spirit::char_encoding::ascii,false,false>,boost::fusion::cons<boost::spirit::qi::kleene<boost::spirit::qi::difference<boost::spirit::qi::char_class<boost::spirit::tag::char_code<boost::spirit::tag::char_,boost::spirit::char_encoding::ascii>>,boost::spirit::qi::eol_parser>>,boost::fusion::cons<boost::spirit::qi::eol_parser,boost::fusion::nil>>>>,boost::fusion::nil>>
        ]
        No constructor could take the source type, or the constructor overload resolution was ambiguous
        e:\projets\amose\sources\lima_linguisticprocessing\src\linguisticprocessing\core\flattokenizer\SpiritTokenizerParser.hpp(89)<FF>: see reference to function template instantiation 'boost::spirit::qi::grammar<Iterator,T1,T2>::grammar<Iterator,tokenizer_automaton(void),boost::spirit::qi::alternative<Elements>,boost::spirit::unused_type,boost::spirit::unused_type>(const boost::spirit::qi::rule<Iterator,T1,boost::spirit::qi::alternative<Elements>> &,const std::string &)' en cours de compilation
        with
        [
            Iterator=iterator_type,
            T1=tokenizer_automaton (void),
            T2=skipper_type,
            Elements=boost::fusion::cons<boost::spirit::qi::char_class<boost::spirit::tag::char_code<boost::spirit::tag::space,boost::spirit::char_encoding::standard>>,boost::fusion::cons<boost::spirit::qi::sequence<boost::fusion::cons<boost::spirit::qi::literal_char<boost::spirit::char_encoding::ascii,false,false>,boost::fusion::cons<boost::spirit::qi::kleene<boost::spirit::qi::difference<boost::spirit::qi::char_class<boost::spirit::tag::char_code<boost::spirit::tag::char_,boost::spirit::char_encoding::ascii>>,boost::spirit::qi::eol_parser>>,boost::fusion::cons<boost::spirit::qi::eol_parser,boost::fusion::nil>>>>,boost::fusion::nil>>
        ]

TokenizerParser.hpp(88)<FF>: during the compilation of the member function ':: tokenizer tokenizer <iterator> (void)' model class
        with
        [
            Iterator=iterator_type
        ]
        LimaTokenizerParser.cpp(33)<FF>: see reference to class template instantiation 'tokenizer <iterator>' being compiled
        with
        [
            Iterator=iterator_type
        ]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:10:31+00:00Added an answer on June 11, 2026 at 1:10 am

    When posting to the Spirit list (yep, I saw this posted there), it is best to provide something minimal. Making something minimal helps a lot. It avoids the visual clutter that tends to waste time when understanding the code. It is just a matter of elimination anyway that anyone asking for support could do. Attached is what I mean by minimal. If I’ve seen something like this instead, it would have taken me just a few secs, instead of 10s of minutes to understand the problem.

    Anyway, here’s the code distilled and as minimal as it can be while still exhibiting the problem:

    #include <boost/config/warning_disable.hpp>
    #include <boost/spirit/include/qi.hpp>
    #include <boost/fusion/include/adapt_struct.hpp>
    #include <string>
    
    namespace qi = boost::spirit::qi;
    typedef qi::space_type skipper_type;
    
    template <typename Iterator>
    struct tokenizer : qi::grammar<Iterator, skipper_type>
    {
      tokenizer() : tokenizer::base_type(start)
      {
      }
    
      qi::rule<Iterator, skipper_type> start;
    };
    
    
    
    int main()
    {
      typedef std::string::const_iterator iterator_type;
      typedef tokenizer<iterator_type> tokenizer;
    
      // @ERROR DOES NOT WORK ON WINDOWS PORT
      tokenizer tokenizer_parser;
      return 0;
    }
    

    I notice that if I rename “skipper_type” to “skipper_type_” (note trailing underscore). Then it compiles fine! This leads me to believe that it is an MSVC bug.

    Solution: just change the name skipper_type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so I have another Python Unicode problem. In IDLE windows 7,The following code:
As per my knowledge, all occurrences of NULL in code are replaced by a
I have a piece of code with a) which I replaced with b) purely
I've got the following code: Regex.Replace(text, words.ToString(), <dfn title=\ + this.FindDefinition($0) + \>$0</dfn>, RegexOptions.IgnoreCase
Anybody have a regular expression to replace the following code: <a href=originalLink>hi</a> with: <a
I've run into a weird error with a Qt program running on Windows. The
I am trying to replace 1234567890123456 with ************3456 with the following code: Regex.Replace(xml,@\b\d{13,16}\b, string.Concat(new
I don't understand why this is occurring. Take the following piece of psuedo code:
Quite often I see source code where language's keyword are replaced with full type
I've got the following code that shows a lightbox 'please wait' box, then does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.