From: <tomas@tuxteam.de>
To: Matt Wette <matt.wette@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: Nyacc question: [found] where are the actions bound?
Date: Sat, 14 Mar 2020 12:59:19 +0100 [thread overview]
Message-ID: <20200314115919.GD4091@tuxteam.de> (raw)
In-Reply-To: <40b09b97-862e-6bb0-3205-45bb9dd35d46@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2033 bytes --]
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
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
next prev parent reply other threads:[~2020-03-14 11:59 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 ` tomas [this message]
2020-03-14 14:31 ` Nyacc question: [found] " Matt Wette
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=20200314115919.GD4091@tuxteam.de \
--to=tomas@tuxteam.de \
--cc=guile-user@gnu.org \
--cc=matt.wette@gmail.com \
/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).