Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2008-03-21 22:48:23


On 03/04/08 11:38, Eric Niebler wrote:
> Larry Evans wrote:
>> On 03/03/08 19:29, Eric Niebler wrote:
>> > Larry Evans wrote:
>> >> If T0,T1,...,Tn are all expression types, and Tag is an n-ary tag,
>> >> then expr<Tag,T0,T,...,Tn> is an expression type.
>> >
>> > Yes. It is also a grammar type that matches itself.
>> >
>> [snip]
>> Hmm... So a grammar is an expression and an expression is a grammar.
>> Sorta like lisp where a program is data and data is a program.
>> I guess proto::matches is like lisp eval. Is that sorta right?
>
> An expression is a grammar, but a grammar is not an expression. For
> example, not_<X> is only a grammar and not an expression.
>

The following grammar I think summarizes the difference between
grammar and expression:

expr //describes an expression.
   = terminal
   | expr+
     //i.e. 1 or more expressions (e.g. expr<tag::plus,expr0,expr1>)
   ;

gram //describes a grammar
   = expr
   | wildcard //struct wildcardns_::_ in matches.hpp
   | control //any struct or class template in namespace control in
              //matches.hpp
   ;
control
   = not_ >> gram
   | or_ >> gram >> gram+
   | and_ >> gram >> gram+
   | if_ >> gram >> gram
   ;

The '= expr' as first alternate of gram reflects the statement
'an expression is a grammar'. The absence of gram on the
rhs of the expr equation reflects the statement 'a grammar
is not an expression'.

Is that about right?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk