unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Matt Wette <matt.wette@gmail.com>
To: guile-user@gnu.org
Subject: Re: Nyacc question: [found] where are the actions bound?
Date: Sat, 14 Mar 2020 07:31:10 -0700	[thread overview]
Message-ID: <6b4d3cde-3b75-3a42-786e-1d381f6c7cb0@gmail.com> (raw)
In-Reply-To: <20200314115919.GD4091@tuxteam.de>

On 3/14/20 4:59 AM, tomas@tuxteam.de wrote:
> On Sun, Mar 08, 2020 at 08:10:50AM -0700, Matt Wette wrote:
>>
>> On 3/8/20 3:14 AM, tomas@tuxteam.de 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
I get it now.  What you expect makes much sense.
  I will think about that.

Matt




  reply	other threads:[~2020-03-14 14:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-08 10:14 Nyacc question: where are the actions bound? tomas
2020-03-08 15:10 ` Matt Wette
2020-03-09  9:07   ` tomas
2020-03-14 11:59   ` Nyacc question: [found] " tomas
2020-03-14 14:31     ` Matt Wette [this message]
2020-03-14 15:47       ` tomas
2020-07-30 13:50 ` Nyacc question: " Matt Wette
2020-07-30 17:17   ` tomas
2020-08-03 20:42   ` tomas
2020-08-03 23:37     ` Matt Wette

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6b4d3cde-3b75-3a42-786e-1d381f6c7cb0@gmail.com \
    --to=matt.wette@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).