From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Newsgroups: gmane.lisp.guile.user Subject: Re: Nyacc question: [found] where are the actions bound? Date: Sat, 14 Mar 2020 12:59:19 +0100 Message-ID: <20200314115919.GD4091@tuxteam.de> References: <20200308101445.GB28250@tuxteam.de> <40b09b97-862e-6bb0-3205-45bb9dd35d46@gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="at6+YcpfzWZg/htY" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="46783"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/1.5.21 (2010-09-15) Cc: guile-user@gnu.org To: Matt Wette Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Mar 14 12:59:38 2020 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jD5S5-000C4t-Hn for guile-user@m.gmane-mx.org; Sat, 14 Mar 2020 12:59:37 +0100 Original-Received: from localhost ([::1]:44184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jD5S4-0003zN-DM for guile-user@m.gmane-mx.org; Sat, 14 Mar 2020 07:59:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33650) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jD5Rt-0003zF-MV for guile-user@gnu.org; Sat, 14 Mar 2020 07:59:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jD5Rr-0004mP-F3 for guile-user@gnu.org; Sat, 14 Mar 2020 07:59:24 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]:59557) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jD5Rq-0004fS-CC for guile-user@gnu.org; Sat, 14 Mar 2020 07:59:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:Date; bh=rmcVxOOuUEQ4VECvtMw1ZxTpuWBxlEcBZ1ft1BHwyQY=; b=b5+gmS1CcqRdt1kwGleajb1XrnnA0ZBxDcLrjXrnKfLBI7iGrX3OYrXHEVVLIYfNGt9nh6jThRLpLQMqV3oMSQMP59Sk4ug8ArCc2qznHxxEkoRh+xbw08V0hnBtDil9H/c3kHu9L9CvtEG3o0RRv+UxxutDO5nsVhcfSgF+10NVL/g9ZMml5LzP2xDLhcztDjhn3iTkGJt63eA74IAYR3s0dpAUwgQIhh0I1JyPpymlTsideLsui6W54Os0Qob/+EwRookzHUTXi+SyllDPg0CVVWip08gZWItmLN9RkRJMSiaMQGmOyTihQreCUPGd5NGZ6dBWgn+0h3QMfeYKkg==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1jD5Rn-0002pL-7x; Sat, 14 Mar 2020 12:59:19 +0100 Content-Disposition: inline In-Reply-To: <40b09b97-862e-6bb0-3205-45bb9dd35d46@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 5.199.139.25 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:16300 Archived-At: --at6+YcpfzWZg/htY Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Mar 08, 2020 at 08:10:50AM -0700, Matt Wette wrote: >=20 >=20 > 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=C3=A1s --at6+YcpfzWZg/htY Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAl5sxxcACgkQBcgs9XrR2kYuRwCbB6/lQQKXYVroo+qWsRWLX9Vr 5wcAn2jLbHDh/zAJEakFPemanGGZNjjK =5REJ -----END PGP SIGNATURE----- --at6+YcpfzWZg/htY--