bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GLR: modification of $1


From: Frank Heckenbach
Subject: Re: GLR: modification of $1
Date: Fri, 3 Oct 2003 01:01:04 +0200
User-agent: semail 20030730

Paul Hilfinger wrote:

> > But rather than this I'd prefer if $1 would be writable. This would
> > give the grammar writer more freedom in the actions, and require
> > fewer changes to an existing LALR grammar.
> 
> Personally, I find this prospect a bit distasteful.  Part of it is
> knowing too much, I suppose: to me, writing ``$1 = E;'' suggests the 
> computation of an inherited attribute, which of course it is not.

Usually not, it's more like a temp variable. Though in the GNU C
example, it sometimes does a formal modification of an inherited
attribute (applying save_expr or truthvalue_conversion) which should
(or must) be done only once and may be needed both in the mid-rule
action and the final action.

> The ``transition from LALR'' argument would be fine except that (1)
> the feature as it stands is technically undefined (or "muddled", to
> use Paul E's term), and (2) no such situation would arise in a newly
> ported-to-GLR LALR(1) grammar (muddled or not), since LALR parsers
> don't "split" (furthermore, I believe you will find that on an LALR
> grammar, assignment to $1 in the GLR parser works the same as it does
> in the LALR parser.)

Indeed. But of course, the purpose of changing to GLR is that one
wants (or has) to introduce splitting somewhere. And (AFAIK) it's
not obvious from the grammar which rules may be active during a
split parser. So in practice, any rule that assigns to $1 would be
endangered in an "actual" GLR grammar.

So I'd appreciate Paul's suggestion of making $1 const, so such
problems are noticed at compile-time.

> When I've felt the need to do something like this in the past, I've
> instead had the semantic values be (constant) pointers (whose
> referents I can modify at will).

OK. I guess I'll do something like this then.

> But finally, it would take a certain implementation effort to realize
> your proposed semantics.  At the moment, the semantic actions are
> evaluated in a split parser by first copying semantic values from the
> graph structure representing the set of parse stacks to an array,
> whence they may be referenced by essentially the same algorithm used
> in the LALR skeleton.  Implementing assignment to $1 would require
> either copying back to the graph (a waste of time in the normal case),
> or accessing $n using a different algorithm.  

Apropos wasting time: I see that each occurrence of $1 gets expanded
to something like `yyvsp[YYFILL (0)].yystate.yysemantics.yysval'
where `YYFILL' is #defined to `yyfill (...)'. I hope gcc will inline
the function calls in `-O3', but are you sure it doesn't do any
redundant work if $1 is used several times in an action? (Or is that
also considered bad style?)

Frank

-- 
Frank Heckenbach, address@hidden
http://fjf.gnu.de/
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]