a simple boost.spirit function compile error!

T

truelixin

1>
2> #include <boost/spirit/core.hpp>
3>
4> using namespace boost::spirit;
5>
6> rule<> expr, identity;
7>
8> expr = identity % '+';
9> identity = ch_p('X') | ch_p('Y');
10>
11> int main()
12> {
13> parse_info<> info = parse("X+Y", expr);
14> }

Just this simple program, I use VC8, but can't compile it.

------ Build started: Project: BoostSpiritTest, Configuration: Debug
Win32 ------
Compiling...
main.cpp
d:\mydocuments\visual studio 2005\projects\boostspirittest
\boostspirittest\main.cpp(8) : error C4430: missing type specifier -
int assumed. Note: C++ does not support default-int
d:\mydocuments\visual studio 2005\projects\boostspirittest
\boostspirittest\main.cpp(8) : error C2371: 'expr' : redefinition;
different basic types
d:\mydocuments\visual studio 2005\projects\boostspirittest
\boostspirittest\main.cpp(6) : see declaration of 'expr'
d:\mydocuments\visual studio 2005\projects\boostspirittest
\boostspirittest\main.cpp(8) : error C2440: 'initializing' : cannot
convert from 'boost::spirit::sequence<A,B>' to 'int'
with
[
A=boost::spirit::rule<>,

B=boost::spirit::kleene_star<boost::spirit::sequence<boost::spirit::chlit<char>,boost::spirit::rule<>>>
]
No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called
d:\mydocuments\visual studio 2005\projects\boostspirittest
\boostspirittest\main.cpp(9) : error C4430: missing type specifier -
int assumed. Note: C++ does not support default-int
d:\mydocuments\visual studio 2005\projects\boostspirittest
\boostspirittest\main.cpp(9) : error C2371: 'identity' : redefinition;
different basic types
d:\mydocuments\visual studio 2005\projects\boostspirittest
\boostspirittest\main.cpp(6) : see declaration of 'identity'
d:\mydocuments\visual studio 2005\projects\boostspirittest
\boostspirittest\main.cpp(9) : error C2440: 'initializing' : cannot
convert from 'boost::spirit::alternative<A,B>' to 'int'
with
[
A=boost::spirit::chlit<char>,
B=boost::spirit::chlit<char>
]
No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called
Build log was saved at "file://d:\MyDocuments\Visual Studio
2005\Projects\BoostSpiritTest\BoostSpiritTest\Debug\BuildLog.htm"
BoostSpiritTest - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========
 
A

Alf P. Steinbach

* (e-mail address removed):
1>
2> #include <boost/spirit/core.hpp>
3>
4> using namespace boost::spirit;
5>
6> rule<> expr, identity;
7>
8> expr = identity % '+';
9> identity = ch_p('X') | ch_p('Y');

You can't have assignments or other commands (statements that are not
declarations) directly at namespace scope.

10>
11> int main()
12> {

But you could have had them here.

13> parse_info<> info = parse("X+Y", expr);
14> }

I suggest waiting a little in trying out Boost Spirit, because it's a library
that uses and requires you to deal with advanced language features.

The error above is, in contrast, a typical novice error.

It may be that you have experience with other programming languages (e.g. your
clean 'main' seems to indicate that) and so feel that some "real" challenge such
as using Boost Spirit is just what you need to learn things, but still, if that
is the case, I recommend trying out simpler things first so as to learn the
basics of the language -- otherwise you'll be stumped at every turn.


Cheers & hth.,

- Alf
 
V

Victor Bazarov

Alf said:
* (e-mail address removed):

You can't have assignments or other commands (statements that are not
declarations) directly at namespace scope.

It looks like the OP wanted to initialise them and instead assigned to
them. Perhaps this would work:

But you could have had them here.

I am not familiar with Boost Spirit, but for may objects initialisation
works, so I dare say that the OP just as well could have had them there,
had he/she "combined the statements"...
I suggest waiting a little in trying out Boost Spirit, because it's a
library that uses and requires you to deal with advanced language features.

The error above is, in contrast, a typical novice error.

It may be that you have experience with other programming languages
(e.g. your clean 'main' seems to indicate that) and so feel that some
"real" challenge such as using Boost Spirit is just what you need to
learn things, but still, if that is the case, I recommend trying out
simpler things first so as to learn the basics of the language --
otherwise you'll be stumped at every turn.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top