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
#include
#include
#include
#include
#include
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
struct result
{
typedef void type;
};
template
void operator()( Container& c, Item const& item ) const
{
c.push_back( item );
}
};
function const create_dfa = create_dfa_impl();
struct Script_parser : public grammar
{
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 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 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!
Stephen