Nafi Diallo | 2 Sep 16:54
Picon
Favicon

help on this grammar

Hi I defined a grammar as follows:
 
 mystr = lexeme_d[confix_p('\"' , *anychar_p, '\"')|(*alnum_p) ];
    
 or_term = lexeme_d[as_lower_d[!ch_p('(')>>(mystr)[list_actor(vec1)]
          >>*
          (*space_p>>keyword_p("or")>>*space_p>>
           mystr[list_actor(vec1)]
           )>>!ch_p(')')]
      ];
 and_term = lexeme_d[as_lower_d[*
         (*space_p>>keyword_p("and")>>*space_p>>
         !ch_p('(')>>mystr[list_actor(vec2)]
          >>!ch_p(')'))
         ]
     ];
     
 anded_or_term =
   lexeme_d[as_lower_d[confix_p('(',
           mystr[list_actor(vec3)]
           >>*(
           (*space_p >> keyword_p("or")
      >>*space_p)>> (mystr[list_actor(vec3)])
           )
           ,')')
         ]
     ];
     
 query = lexeme_d[!ch_p('(') >> or_term >>(and_term|(*anded_or_term))>>!ch_p(')')];
 
 BOOST_SPIRIT_DEBUG_NODE(query);
 
 
 
I feed it with (processing or oil or Gulf) , it parses as expected but then crashes afterwards.
following is the trace I get. What I am doing wrong?
 
 
 
 
 0x002c7794 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string
    () from /usr/lib/libstdc++.so.6
#1  0x08050992 in boost::spirit::impl::concrete_parser<boost::spirit::contiguous<boost::spirit::inhibit_case<boost::spirit::sequence<boost::spirit::sequence<boost::spirit::sequence<boost::spirit::optional<boost::spirit::chlit<char> >, boost::spirit::action<boost::spirit::rule<boost::spirit::scanner<char const*, boost::spirit::scanner_policies<boost::spirit::skipper_iteration_policy<boost::spirit::iteration_policy>, boost::spirit::match_policy, boost::spirit::action_policy> >, boost::spirit::nil_t, boost::spirit::nil_t>, refiner::list_actor> &gt ;, boost::spirit::kleene_star<boost::spirit::sequence<boost::spirit::sequence<boost::spirit::sequence<boost::spirit::kleene_star<boost::spirit::space_parser>, boost::spirit::contiguous<boost::spirit::sequence<boost::spirit::chseq<char const*>, boost::spirit::negated_empty_match_parser<boost::spirit::chset<char> > > > >, boost::spirit::kleene_star<boost::spirit::space_parser> >, boost::spirit::action<boost::spirit::rule<boost::spirit::scanner<char const*, boost::spirit::scanner_policies<boost::spirit::skipper_iteration_policy<boost::spirit::iteration_policy>, boost::spirit::match_policy, boost::spirit::action_policy> >, boost::spirit::nil_t, boost::spirit::nil_t>, refiner::list_actor> > > >, boo st::spirit::optional<boost::spirit::chlit<char> > > > >, boost::spirit::scanner<char const*, boost::spirit::scanner_policies<boost::spirit::skipper_iteration_policy<boost::spirit::iteration_policy>, boost::spirit::match_policy, boost::spirit::action_policy> >, boost::spirit::nil_t>::do_parse_virtual (this=0x9e17ad8, scan= <at> 0xbfde9e74)
    at /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h:104
#2  0x0804cc98 in boost::spirit::impl::concrete_parser<boost::spirit::contiguous<boost::spirit::sequence<boost::spirit::sequence<boost::spirit::sequence<boost::spirit::optional<boost::spirit::chlit<char> >, boost::spirit::rule<boost::spirit::scanner<char const*, boost::spirit::scanner_policies<boost::spirit::skipper_iteration_policy<b oost::spirit::iteration_policy>, boost::spirit::match_policy, boost::spirit::action_policy> >, boost::spirit::nil_t, boost::spirit::nil_t> >, boost::spirit::alternative<boost::spirit::rule<boost::spirit::scanner<char const*, boost::spirit::scanner_policies<boost::spirit::skipper_iteration_policy<boost::spirit::iteration_policy>, boost::spirit::match_policy, boost::spirit::action_policy> >, boost::spirit::nil_t, boost::spirit::nil_t>, boost::spirit::kleene_star<boost::spirit::rule<boost::spirit::scanner<char const*, boost::spirit::scanner_policies<boost::spirit::skipper_iteration_policy<boost::spirit::iteration_policy>, boost::spirit::match_policy, boost::spirit::action_policy> >, boost::spirit::nil_t, boost::spirit::nil_t> > > >, boost::spirit::optional<boost::spirit::chlit<char> > > >, boost::spirit::scanner<char const*, boost::spirit::scanner_ policies<boost::spirit::skipper_iteration_policy<boost::spirit::iteration_policy>, boost::spirit::match_policy, boost::spirit::action_policy> >, boost::spirit::nil_t>::do_parse_virtual (this=0x9e168a8, scan= <at> 0xbfde9fa4)
    at /usr/local/include/boost-1_35/boost/spirit/core/non_terminal/impl/rule.ipp:189
#3  0x0804a9ad in main ()
    at /usr/local/include/boost-1_35/boost/spirit/core/non_terminal/impl/rule.ipp:189


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Lutz Schneider | 3 Sep 01:19
Picon

Fwd: Sun C++ 5.7 spirit(boost 1.33) ???

Hi,

I had to make the following changes to get my spirit parser to work with Sun C++ 5.7:

boost/spirit/iterator/impl/file_iterator.ipp
323c323
< munmap(data, size);
---
> munmap(static_cast<char*>(data), size);
378c378
< munmap(p, stat_buf.st_size);
---
> munmap(static_cast<char*>(p), stat_buf.st_size);

boost/spirit/core/composite/epsilon.hpp
63c63,64
< BOOST_WORKAROUND(BOOST_MSVC, == 1400)
---
> BOOST_WORKAROUND(BOOST_MSVC, == 1400) || \
> BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)

Cheers,
Lutz


---------- Forwarded message ----------
From: Joel de Guzman <joel <at> boost-consulting.com>
Date: Tue, Aug 26, 2008 at 3:24 PM
Subject: Re: [Spirit-general] Sun C++ 5.7 spirit(boost 1.33) ???
To: spirit-general <at> lists.sourceforge.net


Lutz Schneider wrote:
> Hi Spirit folks,
>
> for various (unfortunate) reasons my company needs to use Sun C++ 5.7
> (Patch 117830-09 2006/11/01) on Sun. I am successfully using
> spirit(boost 1.33, version also currently fixed due to external
> requirements) on all other platforms using the gcc compiler.
>
> As far as my google research is concerned it is known that spirit(boost
> 1.33) does not compile with Sun C++ 5.7 due to the following error(among
> others):
>
> "spirit/core/composite/epsilon.hpp", line 76: Error: complex expression
> not allowed in dependent template argument expression. 1 Error(s) detected.
>
> In older versions of spirit an if-directive would lead to a workaround
> for Sun C++ 5.7.
>
> Would reintroducing this directive solve the problem?
>
> Does anyone have another suggestion how to handle this problem or is
> there no alternative to upgrading to a higher version of Sun C++ and/or
> boost?
>
> Thank you very much for any help/suggestions.

I can apply the patch. Can you please post it?

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


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Joel de Guzman | 3 Sep 02:58
Picon
Favicon

Re: help on this grammar

Nafi Diallo wrote:
> Hi I defined a grammar as follows:
>  
>  mystr = lexeme_d[confix_p('\"' , *anychar_p, '\"')|(*alnum_p) ];
>     
>  or_term = lexeme_d[as_lower_d[!ch_p('(')>>(mystr)[list_actor(vec1)]
>           >>*
>           (*space_p>>keyword_p("or")>>*space_p>>
>            mystr[list_actor(vec1)]
>            )>>!ch_p(')')]
>       ];
>  and_term = lexeme_d[as_lower_d[*
>          (*space_p>>keyword_p("and")>>*space_p>>
>          !ch_p('(')>>mystr[list_actor(vec2)]
>           >>!ch_p(')'))
>          ]
>      ];
>      
>  anded_or_term =
>    lexeme_d[as_lower_d[confix_p('(',
>            mystr[list_actor(vec3)]
>            >>*(
>            (*space_p >> keyword_p("or")
>       >>*space_p)>> (mystr[list_actor(vec3)])
>            )
>            ,')')
>          ]
>      ];
>      
>  query = lexeme_d[!ch_p('(') >> or_term 
>  >>(and_term|(*anded_or_term))>>!ch_p(')')];
>  
>  BOOST_SPIRIT_DEBUG_NODE(query);
>  
>  
>  
> I feed it with (processing or oil or Gulf) , it parses as expected but 
> then crashes afterwards.
> following is the trace I get. What I am doing wrong?

Hi Nafi,

Please post a minimal cpp file we can try to reproduce your problem.

Regards,
--

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

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Joel de Guzman | 3 Sep 03:11
Picon
Favicon

Re: Fwd: Sun C++ 5.7 spirit(boost 1.33) ???

Lutz Schneider wrote:
> Hi,
> 
> I had to make the following changes to get my spirit parser to work with 
> Sun C++ 5.7:
> 
> boost/spirit/iterator/impl/file_iterator.ipp
> 323c323
> < munmap(data, size);
> ---
>  > munmap(static_cast<char*>(data), size);
> 378c378
> < munmap(p, stat_buf.st_size);
> ---
>  > munmap(static_cast<char*>(p), stat_buf.st_size);

Patched.

> boost/spirit/core/composite/epsilon.hpp
> 63c63,64
> < BOOST_WORKAROUND(BOOST_MSVC, == 1400)
> ---
>  > BOOST_WORKAROUND(BOOST_MSVC, == 1400) || \
>  > BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)

I just looked and realized that this has already been fixed in
the latest version:

#if BOOST_WORKAROUND(BOOST_MSVC, == 1310) || \
     BOOST_WORKAROUND(BOOST_MSVC, == 1400) || \
     BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580)
// VC 7.1, VC8 and Sun CC <= 5.8 do not support general
// expressions of non-type template parameters in instantiations

Regards,
--

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

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Lutz Schneider | 3 Sep 19:25
Picon

Re: Fwd: Sun C++ 5.7 spirit(boost 1.33) ???

Hi Joel,

thanks a lot for your confirmation.

Cheers,

Lutz


On 9/3/08, Joel de Guzman <joel <at> boost-consulting.com> wrote:
Lutz Schneider wrote:
> Hi,
>
> I had to make the following changes to get my spirit parser to work with
> Sun C++ 5.7:
>
> boost/spirit/iterator/impl/file_iterator.ipp
> 323c323
> < munmap(data, size);
> ---
>  > munmap(static_cast<char*>(data), size);
> 378c378
> < munmap(p, stat_buf.st_size);
> ---
>  > munmap(static_cast<char*>(p), stat_buf.st_size);


Patched.


> boost/spirit/core/composite/epsilon.hpp
> 63c63,64
> < BOOST_WORKAROUND(BOOST_MSVC, == 1400)
> ---
>  > BOOST_WORKAROUND(BOOST_MSVC, == 1400) || \
>  > BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590)


I just looked and realized that this has already been fixed in
the latest version:

#if BOOST_WORKAROUND(BOOST_MSVC, == 1310) || \

     BOOST_WORKAROUND(BOOST_MSVC, == 1400) || \

     BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580)
// VC 7.1, VC8 and Sun CC <= 5.8 do not support general
// expressions of non-type template parameters in instantiations


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


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Singh, Diwakar V | 4 Sep 03:26
Picon
Favicon

spirit parser question

Hi,

I am a new user of spirit. I would like to know how to call my C++ function from within a parse call. For example,

 

struct variable_grammar

    : spirit::grammar<variable_grammar, stack4_closure::context_t>

{

    typedef spirit::symbols<boost::shared_ptr<function> > function_table_t;

    typedef spirit::symbols<double> var_table_t;

 

    function_table_t const & functions;

    var_table_t & vars;

      std::string strVal;

    stack::iterator it;

 

    variable_grammar(function_table_t const & f, var_table_t & v)

        : functions(f), vars(v)

    {}

 

    template <typename ScannerT>

    struct definition

    {

        definition(variable_grammar const & self)

            : expression(self.functions, self.vars)

        {

            using phoenix::arg1;

            using phoenix::arg2;

            using phoenix::construct_;

            using phoenix::if_;

            using phoenix::new_;

            using phoenix::var;

            using spirit::str_p;

            using spirit::ch_p;

            using spirit::alnum_p;

            using spirit::digit_p;

                  using spirit::assign_a;

            using spirit::anychar_p;

            using spirit::lexeme_d;

                  using std::string;

            using spirit::real_p;

 

                  top

                =  name1

                   [

                        MyFunction(str1, vector2),

                              self.sVal = construct_<std::string>(arg1, arg2),

                                testFn(),

                                //(self.sVal),

                    push_back(self.stk1,

                                new_<string_value_node>(self.sVal))

                   ]

 

I want to call a C++ function MyFunction that requires two parameters, string and a vector.

 

Can you show some example of how this is done?

 

Thanks

 

Diwakar

 

 

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Carl Barron | 4 Sep 04:39

Re: spirit parser question


On Sep 3, 2008, at 9:26 PM, Singh, Diwakar V wrote:

Hi,

I am a new user of spirit. I would like to know how to call my C++ function from within a parse call. For example,

 

struct variable_grammar

    : spirit::grammar<variable_grammar, stack4_closure::context_t>

{

    typedef spirit::symbols<boost::shared_ptr<function> > function_table_t;

    typedef spirit::symbols<double> var_table_t;

 

    function_table_t const & functions;

    var_table_t & vars;

      std::string strVal;

    stack::iterator it;

 

    variable_grammar(function_table_t const & f, var_table_t & v)

        : functions(f), vars(v)

    {}

 

    template <typename ScannerT>

    struct definition

    {

        definition(variable_grammar const & self)

            : expression(self.functions, self.vars)

        {

            using phoenix::arg1;

            using phoenix::arg2;

            using phoenix::construct_;

            using phoenix::if_;

            using phoenix::new_;

            using phoenix::var;

            using spirit::str_p;

            using spirit::ch_p;

            using spirit::alnum_p;

            using spirit::digit_p;

                  using spirit::assign_a;

            using spirit::anychar_p;

            using spirit::lexeme_d;

                  using std::string;

            using spirit::real_p;

 

                  top

                =  name1

                   [

                        MyFunction(str1, vector2),

                              self.sVal = construct_<std::string>(arg1, arg2),

                                testFn(),

                                //(self.sVal),

                    push_back(self.stk1,

                                new_<string_value_node>(self.sVal))

                   ]

 

I want to call a C++ function MyFunction that requires two parameters, string and a vector.

 

Can you show some example of how this is done?

 

Thanks

 

Diwakar

 

 
You need lazy functions [phoenix::functioon<...>]  to exceute your functions in code evaluated with phoenix.

a phoenix function requres a functor with a nested metafunction result and an operator () const  both
are templated with the same # ofr template paramenters as function arguments.

see function in phoenix docs for details.

beware phoenix functions require lazy args 


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general
Singh, Diwakar V | 4 Sep 05:15
Picon
Favicon

Re: spirit parser question

Hi Carl,

Thanks for your response. Is there any example available for me to look at the phoenix functor and function usage?

 

diwakar

 

From: spirit-general-bounces <at> lists.sourceforge.net [mailto:spirit-general-bounces <at> lists.sourceforge.net] On Behalf Of Carl Barron
Sent: Wednesday, September 03, 2008 7:39 PM
To: Spirit General Mailing List
Subject: Re: [Spirit-general] spirit parser question

 

 

On Sep 3, 2008, at 9:26 PM, Singh, Diwakar V wrote:



Hi,

I am a new user of spirit. I would like to know how to call my C++ function from within a parse call. For example,

 

struct variable_grammar

    : spirit::grammar<variable_grammar, stack4_closure::context_t>

{

    typedef spirit::symbols<boost::shared_ptr<function> > function_table_t;

    typedef spirit::symbols<double> var_table_t;

 

    function_table_t const & functions;

    var_table_t & vars;

      std::string strVal;

    stack::iterator it;

 

    variable_grammar(function_table_t const & f, var_table_t & v)

        : functions(f), vars(v)

    {}

 

    template <typename ScannerT>

    struct definition

    {

        definition(variable_grammar const & self)

            : expression(self.functions, self.vars)

        {

            using phoenix::arg1;

            using phoenix::arg2;

            using phoenix::construct_;

            using phoenix::if_;

            using phoenix::new_;

            using phoenix::var;

            using spirit::str_p;

            using spirit::ch_p;

            using spirit::alnum_p;

            using spirit::digit_p;

                  using spirit::assign_a;

            using spirit::anychar_p;

            using spirit::lexeme_d;

                  using std::string;

            using spirit::real_p;

 

                  top

                =  name1

                   [

                        MyFunction(str1, vector2),

                              self.sVal = construct_<std::string>(arg1, arg2),

                                testFn(),

                                //(self.sVal),

                    push_back(self.stk1,

                                new_<string_value_node>(self.sVal))

                   ]

 

I want to call a C++ function MyFunction that requires two parameters, string and a vector.

 

Can you show some example of how this is done?

 

Thanks

 

Diwakar

 

 

You need lazy functions [phoenix::functioon<...>]  to exceute your functions in code evaluated with phoenix.

 

a phoenix function requres a functor with a nested metafunction result and an operator () const  both

are templated with the same # ofr template paramenters as function arguments.

 

see function in phoenix docs for details.

 

beware phoenix functions require lazy args 

 

 

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Spirit-general mailing list
Spirit-general <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/spirit-general

Re: spirit parser question

On Thursday 04 September 2008, Singh, Diwakar V wrote:
> Hi Carl,
> 
> Thanks for your response. Is there any example available for me to look
> at the phoenix functor and function usage?
> 

Hello,

I think thatone of the Sprit examples (calc2_ast or something similar) was using phoenix function...

Or you can go to Phoenix docs - there are some examples (and tests in the test directory):
http://www.boost.org/doc/libs/1_36_0/libs/spirit/phoenix/doc/html/phoenix/starter_kit.html#phoenix.starter_kit.lazy_functions
http://www.boost.org/doc/libs/1_36_0/libs/spirit/phoenix/doc/html/phoenix/composite.html#phoenix.composite.function

Cheers,
Milosz

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Peng Yu | 5 Sep 03:25
Picon

How make a new vector by combining a few vectors?

Hi,

In the following code, I want make v3 out of v1 and v2. Is there a way
to do it with boost::fusion?

Thanks,
Peng

#include <boost/fusion/include/make_vector.hpp>
#include <boost/typeof/typeof.hpp>
#include <iostream>

int main() {
  BOOST_AUTO(v1, boost::fusion::make_vector(123, "hello", 12.5));
  BOOST_AUTO(v2, boost::fusion::make_vector("xyz", 3.8, 2));

  BOOST_AUTO(v3, boost::fusion::make_vector(123, "hello", 12.5, "xyz", 3.8, 2));
  // I want to make v3 out of v1 and v2.
}

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

Gmane