
I am sure this has been asked before, but I am not able to find an
answer to my specific question in the archives. I wanted to create a
grammar that can accept statements like if_(expr)[ statement-list
].else_[statement-list]. I created a if_expr type using
proto::extends, and added a member called else_ to it, of type
proto::function
{ };
struct if_grammar :
proto::or_<
if_only_grammar,
proto::subscript
{ };
struct arith_expr_grammar : proto::or_< proto::plus< arith_expr_grammar, arith_expr_grammar>, proto::minus< arith_expr_grammar, arith_expr_grammar>, proto::multiplies< arith_expr_grammar, arith_expr_grammar>, proto::divides< arith_expr_grammar, arith_expr_grammar>, proto::terminal, proto::terminal<int>, rel_expr_grammar
{ };
struct rel_expr_grammar : proto::or_< proto::less< arith_expr_grammar, arith_expr_grammar>, proto::greater< arith_expr_grammar, arith_expr_grammar>, proto::less_equal< arith_expr_grammar, arith_expr_grammar>, proto::greater_equal< arith_expr_grammar, arith_expr_grammar>, proto::equal_to< arith_expr_grammar, arith_expr_grammar>, proto::not_equal_to< arith_expr_grammar, arith_expr_grammar>, proto::logical_not< rel_expr_grammar>
{ };
struct assign_grammar :
proto::or_<
proto::assign
{ };
struct statement_grammar : proto::or_< assign_grammar, if_grammar
{ };
struct bb_grammar :
proto::or_<
statement_grammar,
proto::comma
{ };
struct napl_grammar :
proto::or_<
proto::terminal<program>,
proto::subscript
{ };
template<typename Expr>
void check_and_execute(const Expr &e, mpl::true_)
{
cout << "Program printer TBD.\n";
}
template<typename Expr>
void check_and_execute(const Expr &e, mpl::false_)
{
cout << "Should not be here\n";
}
template<typename Expr>
void check_grammar(const Expr &e)
{
BOOST_MPL_ASSERT_MSG((proto::matches

Hi Manjunath, in the future please put the name of the library you're asking about in the subject as I have done. On 1/27/2010 2:31 PM, Manjunath Kudlur wrote:
I am sure this has been asked before, but I am not able to find an answer to my specific question in the archives. I wanted to create a grammar that can accept statements like if_(expr)[ statement-list ].else_[statement-list]. <snip>
Proto has experimental (undocumented) support for data members like .else_ in the above expression. Have a look at libs/proto/example/virtual_member.cpp, which does pretty much exactly what you're trying to do above. HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com

Eric,
I did find some threads mentioning this in the archives. However, I
had already written my code before I saw this, and I will feel better
if I understand what's going wrong in my code. Could you please take a
quick look?
Thanks,
Manjunath
On Tue, Jan 26, 2010 at 10:45 PM, Eric Niebler
Hi Manjunath, in the future please put the name of the library you're asking about in the subject as I have done.
On 1/27/2010 2:31 PM, Manjunath Kudlur wrote:
I am sure this has been asked before, but I am not able to find an answer to my specific question in the archives. I wanted to create a grammar that can accept statements like if_(expr)[ statement-list ].else_[statement-list].
<snip>
Proto has experimental (undocumented) support for data members like .else_ in the above expression. Have a look at libs/proto/example/virtual_member.cpp, which does pretty much exactly what you're trying to do above.
HTH,
-- Eric Niebler BoostPro Computing http://www.boostpro.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Eric Niebler
-
Manjunath Kudlur