Extracting parsed value from a local variable

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Extracting parsed value from a local variable

Michele De Stefano
Dear all,

here is my issue. I am creating a rule that happens to parse (amongst several things) a double value into the qi::_a local variable. Now, while staying into the same semantic action, I need to use that parsed double value into another C++ instruction that requires a double value as input.

Think to this instruction as a generic

ouput_type f(double x)

The issue is that when I call (within the semantic action)

f(qi::_a)

the compiler complains that it cannot convert qi::_a into a double.

Is there a way to extract the double value from qi::_a (or anyway from any placeholder)?

Thanks in advance.

Best regards,
Michele

--

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Extracting parsed value from a local variable

Jens Kallup
Hello Michele,

try to use qi::_1 ... qi::_9  where _1 till _9 are placeholders
for your input like double.
The placeholder _1 is the first match, _2 the second, and so on...

Jens


On 10/23/2016 06:59 PM, Michele De Stefano wrote:

> Dear all,
>
> here is my issue. I am creating a rule that happens to parse (amongst
> several things) a double value into the qi::_a local variable. Now,
> while staying into the same semantic action, I need to use that parsed
> double value into another C++ instruction that requires a double value
> as input.
>
> Think to this instruction as a generic
>
> ouput_type f(double x)
>
> The issue is that when I call (within the semantic action)
>
> f(qi::_a)
>
> the compiler complains that it cannot convert qi::_a into a double.
>
> Is there a way to extract the double value from qi::_a (or anyway from
> any placeholder)?
>
> Thanks in advance.
>
> Best regards,
> Michele
>
> --
> Michele De Stefano
> Linked In <http://it.linkedin.com/in/micheledestefano>
> mds-utils: a general purpose Open Source library
> <http://sourceforge.net/projects/mds-utils/>
> Personal Web Site <https://sites.google.com/site/micdestefano/>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>
>
> _______________________________________________
> Spirit-general mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/spirit-general


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Extracting parsed value from a local variable

Michele De Stefano
Thanks ... I've found the solution myself ...

I actually need to use phoenix lazy actions ...
Here I wanted to create a rule that synthetized directly an std::complex<double> ... so I was storing the real part into qi::_a and the imaginary part into qi::_b ... and then I would have liked to write something like

qi::_val = std::complex(qi::_a,qi::_b)

and the compiler complained ...

Actuall, using

qi::_val = boost::phoenix::construct< std::complex<double> >(qi::_a,qi::_b)

fixed the issue.

Best regards to all,
Michele

2016-10-23 19:23 GMT+02:00 Jens Kallup <[hidden email]>:
Hello Michele,

try to use qi::_1 ... qi::_9  where _1 till _9 are placeholders
for your input like double.
The placeholder _1 is the first match, _2 the second, and so on...

Jens


On 10/23/2016 06:59 PM, Michele De Stefano wrote:
> Dear all,
>
> here is my issue. I am creating a rule that happens to parse (amongst
> several things) a double value into the qi::_a local variable. Now,
> while staying into the same semantic action, I need to use that parsed
> double value into another C++ instruction that requires a double value
> as input.
>
> Think to this instruction as a generic
>
> ouput_type f(double x)
>
> The issue is that when I call (within the semantic action)
>
> f(qi::_a)
>
> the compiler complains that it cannot convert qi::_a into a double.
>
> Is there a way to extract the double value from qi::_a (or anyway from
> any placeholder)?
>
> Thanks in advance.
>
> Best regards,
> Michele
>
> --
> Michele De Stefano
> Linked In <http://it.linkedin.com/in/micheledestefano>
> mds-utils: a general purpose Open Source library
> <http://sourceforge.net/projects/mds-utils/>
> Personal Web Site <https://sites.google.com/site/micdestefano/>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>
>
> _______________________________________________
> Spirit-general mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/spirit-general


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general



--

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Extracting parsed value from a local variable

sehe
In reply to this post by Jens Kallup
On 23-10-16 19:23, Jens Kallup wrote:
> try to use qi::_1 ... qi::_9  where _1 till _9 are placeholders
> for your input like double.
> The placeholder _1 is the first match, _2 the second, and so on...

Those are the regular attribute placeholders, not the inherited
attribute or qi::local<> placeholders. If you don't know the library
very well, it's quite easy to give bad advice that simply confuses users
more.


------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive.
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general