guile-user
[Top][All Lists]
Advanced

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

Re: Nyacc question: [found] where are the actions bound?


From: tomas
Subject: Re: Nyacc question: [found] where are the actions bound?
Date: Sat, 14 Mar 2020 12:59:19 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

On Sun, Mar 08, 2020 at 08:10:50AM -0700, Matt Wette wrote:
> 
> 
> On 3/8/20 3:14 AM, address@hidden wrote:
> >Hi,

[...]

> >My question is: where is the stuff resolved which is mentioned
> >in grammar actions?

Hah. Managed to answer my own question by reading the source.

For the benefits of others who might have a similar question
(without knowing how to articulate it, like it happened to
me), here's the answer:

Yes, the actions are "resolved" wrt the (calling) module's
top level environment. The magic happens here (that's wrt the
all-fresh V1.01.2), around lines 47 ff, in module/nyacc/parse.scm:

  (define (make-xct av)
    (if (procedure? (vector-ref av 0))
        av
        (vector-map (lambda (ix f) (eval f (current-module)))
      (vector-map (lambda (ix actn) (wrap-action actn)) av))))

It's the (eval f (current-module)) which does the trick. The
trick happens in make-lalr-parser.

Background: I envisioned something like

  (let ( ...some environment for the actions...)
    ...make-lalr-parser...)

and have make-lalr-parser pick up the bindings in the lexical
environment.

but had to realize that make-lalr-parser ignores the lexical
environment. That's now clear to me, because (eval ... (current-module))
looks at the caller's module's top-level bindings.

One would have to call local-eval (from (ice-9 local-eval)) and
explicitly pass (the-environment) (from the same module) to
achieve what I had in mind.

Not that I'm proposing that, mind you. I still barely know what
I'm doing at this point. Probably there are very good reasons
to resort to the (top-level) module bindings.

I just wanted to understand, and I think I do now :-)

As to your other proposal (writing out the pre-compiled parser
with write-lalr-*), I think it's orthogonal to my issue. This
might come in handy when the parser is heavy enough that it
takes a significant time constructing it (which it is not in my
little use case for now)

Thanks & cheers
-- tomás

Attachment: signature.asc
Description: Digital signature


reply via email to

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