Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto]: How to use complex grammars in a domain/extension
From: Roland Bock (rbock_at_[hidden])
Date: 2010-09-21 10:19:48


On 09/21/2010 04:01 PM, Eric Niebler wrote:
> On 9/21/2010 9:51 AM, Eric Niebler wrote:
>
>> (proto lists members, see this thread for the rest of the discussion,
>> which has been happening on -users:
>> http://lists.boost.org/boost-users/2010/09/62747.php)
>>
>> On 9/21/2010 9:19 AM, Roland Bock wrote:
>>
>>> On 09/21/2010 11:55 AM, Thomas Heller wrote:
>>>
>>>> <snip>
>>>> Solved the mistery. here is the code, explanation comes afterward:
>>>>
>>>> <snip>
>>>> So, everything works as expected!
>>>>
>>>>
>>> Thomas,
>>>
>>> wow, this was driving me crazy, thanks for solving and explaining in all
>>> the detail! :-)
>>>
>>> I am still not sure if this isn't a conceptual problem, though:
>>>
>>> The "equation" grammar is perfectly OK. But without or-ing it with the
>>> "addition" grammar, the extension does not allow ANY valid expression to
>>> be created. I wonder if that is a bug or a feature?
>>>
>> It's a feature. Imagine this grammar:
>>
>> struct IntsOnlyPlease
>> : proto::or_<
>> proto::terminal<int>
>> , proto::nary_expr<proto::_, proto::vararg<IntsOnlyPlease> >
>> >
>> {};
>>
>> And a integer terminal "i" in a domain that obeys this grammar. Now,
>> what should this do:
>>
>> i + "hello!";
>>
>> You want it to fail because if it doesn't, you would create an
>> expression that doesn't conform to the domain's grammar. Right? Proto
>> accomplishes this by enforcing that all operands must conform to the
>> domain's grammar *and* the resulting expression must also conform.
>> Otherwise, the operator is disabled.
>>
>> Anything else would be fundamentally broken.
>>
> This explanation is incomplete. Naturally, this operator+ would be
> disabled anyway because the resulting expression doesn't conform to the
> grammar regardless of whether the LHS and RHS conform. It's a question
> of *when* the operator gets disabled. For a full explanation, see this
> bug report:
>
> https://svn.boost.org/trac/boost/ticket/2407
>
> The answer is simple and logically consistent: make sure *every* valid
> expression in your domain (including lone terminals) is accounted for by
> your grammar.
>
>
OK, it is sinking in, slowly :-)

Maybe I missed the equivalent part in the documentation, but the list
given by Thomas would make a very good section.

> 1) the operands must be in a compatible domain
> 2) the left hand operand and the right hand operand must match the grammar
> specified in the domain
> 3) the resulting expression must match the grammar specified in the domain.
>
Also, maybe as an illustrating example:

This grammar

proto::plus<proto::terminal<int>, proto::terminal<int> >

used in a domain would not allow

i + i;

with i being an int-terminal.

Thanks for all the answers!

Regards from Munich,

Roland


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net