Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   a simple boost.spirit function compile error! (http://www.velocityreviews.com/forums/t677266-a-simple-boost-spirit-function-compile-error.html)

truelixin@gmail.com 03-26-2009 03:30 AM

a simple boost.spirit function compile error!
 
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::sequen ce<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\Debu g\BuildLog.htm"
BoostSpiritTest - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========

Alf P. Steinbach 03-26-2009 03:56 AM

Re: a simple boost.spirit function compile error!
 
* truelixin@gmail.com:
> 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

--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!

Victor Bazarov 03-26-2009 01:18 PM

Re: a simple boost.spirit function compile error!
 
Alf P. Steinbach wrote:
> * truelixin@gmail.com:
>> 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.


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

rule<> identity = ch_p('X') | ch_p('Y'),
expr = identity % '+', i;

>
>
>> 10>
>> 11> int main()
>> 12> {

>
> 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"...

>
>
>> 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.


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


All times are GMT. The time now is 06:41 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.