Jon Lederman | 1 Jan 03:59
Picon

Parsing Doubles (Scientific Notation)

Hi All,

I am a newbie to spirit.  I am attempting to parse a list of doubles 
and have have the following parser setup:

namespace client
{
	namespace qi = boost::spirit::qi;
	namespace ascii = boost::spirit::ascii;
	void print (float const& d) 
	{
		std::cout<< d << std::endl;
	}
	
	template <typename Iterator>
	bool parse_numbers(Iterator first, Iterator last)
	{
using qi::double_;
using qi::phrase_parse;
using ascii::space;		
bool r = phrase_parse(
first,                          /*< start iterator >*/
last,                           /*< end iterator >*/
double_[&print]>> *(',' >> double_[std::cout << _1 << '\n']),  
 /*< the parser >*/
space                           /*< the skip-parser >*/
							  );
if (first != last) // fail if we did not get a full match
		return false;
		return r;
(Continue reading)

Adam Badura | 1 Jan 09:33
Picon
Favicon
Gravatar

Re: Expression Qi/Karma example

> Can you do that in EBNF or PEG (dynamic precedence)?

    Yes. It is just the order of operator rules use.

    By the way I would prefer your response in the "Char type" thread just 
like you promised. :)

    Adam Badura 

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
bytecolor | 1 Jan 10:15
Picon

Re: Parsing Doubles (Scientific Notation)

> namespace client
> {
> 	namespace qi = boost::spirit::qi;
> 	namespace ascii = boost::spirit::ascii;
> 	void print (float const& d) 
> 	{
> 		std::cout<< d << std::endl;
> 	}
> 	
> 	template <typename Iterator>
> 	bool parse_numbers(Iterator first, Iterator last)
> 	{
> using qi::double_;
> using qi::phrase_parse;
> using ascii::space;		
> bool r = phrase_parse(
> first,                          /*< start iterator >*/
> last,                           /*< end iterator >*/
> double_[&print]>> *(',' >> double_[std::cout << _1 << '\n']),  

Where is the ref to _1 ?
It should be qi::_1.
Also #include <boost/spirit/include/phoenix_operator.hpp>

You seem to be giving cout a funky manipulator somewhere.

Happy new year!

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
(Continue reading)

Joel de Guzman | 1 Jan 12:21
Picon
Favicon

Re: Expression Qi/Karma example

Adam Badura wrote:
>> Can you do that in EBNF or PEG (dynamic precedence)?
> 
>     Yes. It is just the order of operator rules use.

Dynamically? EBNF/PEG are both static. Once it is in place,
you can no longer change the order of the rules. What am
I missing?

>     By the way I would prefer your response in the "Char type" thread just 
> like you promised. :)

Sure thing. I need to get past this holiday first ;-)
But a promise is a promise :P

Regards,
--

-- 
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
Commander Pirx | 1 Jan 17:36
Picon

Re: JSON Parser

"John Freeman" <jfreeman08 <at> gmail.com> schrieb im Newsbeitrag 
news:4B3BDE09.4020905 <at> gmail.com...
> Commander Pirx wrote:
>> is there any chance to get updates from your code - if there one?
>>
>
> Is it broken now? I haven't looked at the code in a while (don't fix
> what's not broken, right?), but I'll try to update my copy of Spirit and
> take a look either today or tomorrow.
>
> - John

Hello John,

thanks for your reply. I found some minor issues with namespaces. 
ascii::char_('{') doesn't work since Spirit 2.1. I've substituted this with 
boost::spirit::lit('{'). Another problem is table.hpp. There is a operator 
declaration:

 table& operator= (const detail::table_args_t<ValueParser>& tab)
 { ... snip ...}

And VS2008 throws:

error C4716:

'turban::json::table<std::_String_const_iterator<char,std::char_traits<char>,std::allocator<char> 
 >,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char> 

>,pm::ast::cgraph::method_t,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> 
(Continue reading)

Richard Crossley | 1 Jan 17:54

QI - 'value_type' : is not a member of

I'm a bit lost as to why the following simplified example fails to compile
anymore using boost trunk and VC9, was working happily a couple of weeks
ago.

Any suggestions?

Thanks,

Richard.

//--
struct tester{
	int m_n;
	double m_x;
};

BOOST_FUSION_ADAPT_STRUCT(
	tester,
	(int,m_n)    
	(double,m_x)    
)

using namespace boost::spirit::qi;

template <typename Iterator>
struct test_grammar : public
grammar<Iterator,std::vector<tester>(),standard_wide::space_type>{
	test_grammar() : test_grammar::base_type(m_start)
	{		
		m_start %= +('M' >> int_ >> double_) >> *(int_ >> double_);
(Continue reading)

Joel de Guzman | 1 Jan 18:31
Picon
Favicon

Re: QI - 'value_type' : is not a member of

Richard Crossley wrote:
> I'm a bit lost as to why the following simplified example fails to compile
> anymore using boost trunk and VC9, was working happily a couple of weeks
> ago.
> 
> Any suggestions?
> 
> Thanks,
> 
> Richard.
> 
> //--
> struct tester{
> 	int m_n;
> 	double m_x;
> };
> 
> BOOST_FUSION_ADAPT_STRUCT(
> 	tester,
> 	(int,m_n)    
> 	(double,m_x)    
> )
> 
> using namespace boost::spirit::qi;
> 
> template <typename Iterator>
> struct test_grammar : public
> grammar<Iterator,std::vector<tester>(),standard_wide::space_type>{
> 	test_grammar() : test_grammar::base_type(m_start)
> 	{		
(Continue reading)

Hartmut Kaiser | 1 Jan 18:55
Picon
Gravatar

Re: QI - 'value_type' : is not a member of

> Richard Crossley wrote:
> > I'm a bit lost as to why the following simplified example fails to
> compile
> > anymore using boost trunk and VC9, was working happily a couple of
> weeks
> > ago.
> >
> > Any suggestions?
> >
> > Thanks,
> >
> > Richard.
> >
> > //--
> > struct tester{
> > 	int m_n;
> > 	double m_x;
> > };
> >
> > BOOST_FUSION_ADAPT_STRUCT(
> > 	tester,
> > 	(int,m_n)
> > 	(double,m_x)
> > )
> >
> > using namespace boost::spirit::qi;
> >
> > template <typename Iterator>
> > struct test_grammar : public
> > grammar<Iterator,std::vector<tester>(),standard_wide::space_type>{
(Continue reading)

Adam Badura | 1 Jan 23:27
Picon
Favicon
Gravatar

Re: Expression Qi/Karma example

>>> Can you do that in EBNF or PEG (dynamic precedence)?
>>
>>     Yes. It is just the order of operator rules use.
>
> Dynamically? EBNF/PEG are both static. Once it is in place,
> you can no longer change the order of the rules. What am
> I missing?

    There is a misunderstanding. By "dynamic" rules creation I mean 
something like:

if ( priority_of(ADD) > priority_of(MUL) )
    term := factor >> '+' >> factor;
else
    term := factor >> '*' >> factor;

    This gets not-so-trivial when you have:
1) few operators (like +, -, *, /) including unary ones,
2) you allow to define operators priorities (by the means of "priority_of" 
in this example),
3) you allow to define operators binding (whether a+b+c is (a+b)+c or 
a+(b+c)); for unary operators it is whether they are post fix or prefix,
4) you want to have output generator which encloses correctly in 
parenthesis.

    And there is no such example. The calc* examples only consider a grammar 
fixed at compile time with traditional arithmetic operators.

    Adam Badura 

(Continue reading)

OvermindDL1 | 2 Jan 00:54
Picon

Re: Expression Qi/Karma example

On Fri, Jan 1, 2010 at 3:27 PM, Adam Badura <abadura <at> o2.pl> wrote:
>>>> Can you do that in EBNF or PEG (dynamic precedence)?
>>>
>>>     Yes. It is just the order of operator rules use.
>>
>> Dynamically? EBNF/PEG are both static. Once it is in place,
>> you can no longer change the order of the rules. What am
>> I missing?
>
>    There is a misunderstanding. By "dynamic" rules creation I mean
> something like:
>
> if ( priority_of(ADD) > priority_of(MUL) )
>    term := factor >> '+' >> factor;
> else
>    term := factor >> '*' >> factor;
>
>    This gets not-so-trivial when you have:
> 1) few operators (like +, -, *, /) including unary ones,
> 2) you allow to define operators priorities (by the means of "priority_of"
> in this example),
> 3) you allow to define operators binding (whether a+b+c is (a+b)+c or
> a+(b+c)); for unary operators it is whether they are post fix or prefix,
> 4) you want to have output generator which encloses correctly in
> parenthesis.
>
>    And there is no such example. The calc* examples only consider a grammar
> fixed at compile time with traditional arithmetic operators.

I have a new terminal(?) I made and have been using, it implements a
(Continue reading)


Gmane