Boost logo

Boost Users :

From: Stephen Henry (Stephen.Henry_at_[hidden])
Date: 2005-08-23 07:27:55

Hi all,

I am having a problem with the following snippet of code. What I want to
do is parse a line of alpha numeric characters from a file_iterator and
then use the read characters to construct a new object which takes a
std::string and integer argument for it's constructor. To do this I am
using the statement below:

p >> (+alpha_p)[ create_dfa( self.m_dfa, construct_<DFA>(
construct_<std::string>( arg1 ), var(500) ) ) ];

This is the code I've got:

#include <vector>
#include <iostream>

#include <boost/spirit/core.hpp>
#include <boost/spirit/iterator/file_iterator.hpp>
#include <boost/spirit/attribute.hpp>
#include <boost/spirit/utility/confix.hpp>
#include <boost/spirit/actor.hpp>
#include <boost/spirit/phoenix.hpp>

using namespace boost::spirit;
using namespace phoenix;

struct DFA
        DFA( std::string s, int i )
                : m_name(s), m_i(i) {}

        std::string m_name;

        int m_i;

struct create_dfa_impl
        template<typename Container, typename Item>
        struct result
                typedef void type;
        template<typename Container, typename Item>
        void operator()( Container& c, Item const& item ) const
                c.push_back( item );
function<create_dfa_impl> const create_dfa = create_dfa_impl();

struct Script_parser : public grammar<Script_parser>
        Script_parser( std::vector<DFA> &dfa )
                : m_dfa( dfa ) {}

        template<typename ScannerT>
        struct definition
                definition( Script_parser const& self )
                        p = (*alpha_p)[ create_dfa( self.m_dfa,
construct_<DFA>( construct_<std::string>(arg1, arg2), 500 ) ) ];
                typedef rule<ScannerT> rule_t;

                rule_t p;

                rule_t const& start() const { return p; }
        std::vector<DFA> &m_dfa;

typedef char char_t;
typedef file_iterator<char_t> iterator_t;

int main( int argc, char *argv[] )
        using namespace std;

        if( argc != 2 )
                cout << "Invalid arguments" << endl;
                return -1;

        iterator_t first( argv[1] );
        iterator_t last = first.make_end();

        std::vector<DFA> vDFA;
        Script_parser p(vDFA);
        parser_info<iterator_t> info = parse( first, last, p );

        if( info.hit )
                cout << "Parsing successfull" << endl;

This doesn't even compile, and I have absolutely no idea why. All the
compiler shows is pages and pages of garbage that means absolutely
nothing. Please help!


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at