[proto][docs]what's diff between pattern, grammar, rule, metagrammar?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[proto][docs]what's diff between pattern, grammar, rule, metagrammar?

Larry Evans
Hi Eric,

I'm having a hard time understanding the differences between some
terms.  Based on:

 
http://boost-sandbox.sourceforge.net/libs/proto/doc/html/boost_proto/users_guide/expression_introspection/expression_patterns.html

proto::matches: ExprTmpl * Pattern -> Bool

i.e. the 1st arg to proto::matches is an expression template
(ExprTmpl), the 2nd argument is a Pattern, and the result is boolean.

However, based on:

http://boost-sandbox.sourceforge.net/libs/proto/doc/html/boost_proto/users_guide/expression_introspection/meta_grammars.html


the proto::matches signature is:

   ExprTmpl * (Pattern + MetaGrammar) -> Bool

IOW, the 2nd argument to proto::matches can be either a Pattern or a
MetaGrammar.  Is MetaGrammar a kind of Pattern?

http://boost-sandbox.sourceforge.net/libs/proto/doc/html/boost_proto/users_guide/expression_introspection/meta_grammars.html
also contains:

  Now let's define the rules for addition, subtraction, multiplication
  and division. Here, we can ignore issues of associativity and
  precedence -- the C++ compiler will enforce that for us. We only must
  enforce that the arguments to the operators must themselves conform
  to the CalculatorGrammar that we forward-declared above.

struct Plus
   : plus< CalculatorGrammar, CalculatorGrammar >
{};

struct Minus
   : minus< CalculatorGrammar, CalculatorGrammar >
{};


So what's the difference between a rule, a pattern, and a metagrammar?
Also, on:

http://boost-sandbox.sourceforge.net/libs/proto/doc/html/boost_proto/users_guide/expression_transformation/example__calculator_arity_transform.html


there's:
<------------- cut here -------------
Defining a Grammar

First, we must write the grammar for the calculator. It's really very
simple. Calculator expression can be made up of any combination of 5
constituents:

     * Placeholder 1
     * Placeholder 2
     * A literal
     * Unary operations
     * Binary operations

We can immediately write the calculator grammar as follows:

using namespace boost::proto;

struct CalculatorGrammar
   : or_<
          terminal< placeholder1 >
        , terminal< placeholder2 >
        , terminal< _ >
        , unary_expr< _, CalculatorGrammar >
        , binary_expr< _, CalculatorGrammar, CalculatorGrammar >
     >
{};
 >------------- cut here -------------

So a grammar looks like a metagrammar.  Is grammar another name for
metagrammar?

-regards,
Larry


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel
Reply | Threaded
Open this post in threaded view
|

Re: [proto][docs]what's diff between pattern, grammar, rule, metagrammar?

Eric Niebler

Larry Evans wrote:
> I'm having a hard time understanding the differences between some
> terms.

That's understandable. I haven't settled on terminology yet, and it
shows. I started calling them patterns, especially when I was only using
them for simple pattern matching. When I started building grammars, I
switched terminology. Joel calls them meta-grammars to differentiate
between Spirit grammars, and I used that term in a few places. And a
rule is a part of a grammar.

Basically, I need to go through the docs and replace "pattern" and
"meta-grammars" with "grammar". And it might be nice to have a glossary
of terms somewhere.

--
Eric Niebler
Boost Consulting
www.boost-consulting.com

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel