Boost logo

Boost :

From: Larry Evans (jcampbell3_at_[hidden])
Date: 2001-05-30 14:33:18

joel de guzman wrote:

> From: "Larry Evans":
> > >
> > > Aggregates need not store subjects by value. A reference is fine since
> we
> > > know that the subject has a lifetime equal to or greater than the
> aggregate.
> > > Rules<> are composed by reference in Spirit. I such cases, the aggregate
> > > does not own the subject(s).
> >
> > This will work for FIRST and NILABLE because they are synthesized
> attributes.
> > However, FOLLOW requires an inherited attribute, which can be stored as
> part
> > of some type of smart pointer.
> pardon my ignorance, but who owns a follow? Rule?

It's owned by the Rule; however, using smart ptrs makes the calculation easier
because each smart ptr occurs in a specific part of the rhs of the rule, and,
if you look at section 4.4 of the Aho...'s Dragon book, you see FOLLOW
expressed in terms of a specific part of the rhs of a production.

Anyway, I tried it the other way and didn't get the right answer. Since
I was using smart pointers anyway, it seemed an easy solution.

> >
> > Also, if references are stored in a rule, then wouldn't this cause a
> problem if
> > Rule1 references Rule2 and Rule2 references Rule1? One or the other
> > must be created before a reference can be returned to it. Am I missing
> something?
> >
> I don't know if this applies in the context of the automata builder.
> I am speaking just from experience with Spirit. Rules in Spirit,
> just like in c++ need to be declared before being used. To allow
> cyclic structures typically found in BNF declarations, a rule
> may be declared but defined later (forward declared).
> Rule<> a, c;
> Rule<> b = c | a;
> a = ...
> b = ...
> In fact, we can just forward declare all rules.
> Rule<> a, b, c;
> b = c | a;
> a = ...
> c = ...

OK. I was confused by "reference" which I interpreted as meaning the
rule would have member variables declared as:

    Rule<...>& m_rule;

But I guess only pointers are stored to the rule's subrules. I took a quick
look at Spirit_Rule.h and only saw Rule::meta_rule. But I also saw the
Binary::a, which was a reference. So, I concluded that references were
required. I need to study your code more. Sorry.

Boost list run by bdawes at, gregod at, cpdaniel at, john at