From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.user Subject: Re: Nyacc question: where are the actions bound? Date: Sun, 8 Mar 2020 08:10:50 -0700 Message-ID: <40b09b97-862e-6bb0-3205-45bb9dd35d46@gmail.com> References: <20200308101445.GB28250@tuxteam.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="106951"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Mar 08 16:11:08 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 1jAxa8-000RhG-8o for guile-user@m.gmane-mx.org; Sun, 08 Mar 2020 16:11:08 +0100 Original-Received: from localhost ([::1]:58506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAxa6-0005aS-Sd for guile-user@m.gmane-mx.org; Sun, 08 Mar 2020 11:11:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36064) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAxZv-0005aK-Ij for guile-user@gnu.org; Sun, 08 Mar 2020 11:10:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAxZu-0007Nq-Ab for guile-user@gnu.org; Sun, 08 Mar 2020 11:10:55 -0400 Original-Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:36110) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jAxZu-0007NV-1p for guile-user@gnu.org; Sun, 08 Mar 2020 11:10:54 -0400 Original-Received: by mail-pf1-x42c.google.com with SMTP id i13so3654593pfe.3 for ; Sun, 08 Mar 2020 08:10:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=CdDVQxPLCMKHBkZRQ2514o0jDVjNgbuLauBY88s6v6Y=; b=B5palFtiS6ChusXp1HFA5Ncit5osGgl4ZsMEIsZb9N4JdgiFyUNDsPg7yU1mHocCTq Yu/iI8kHAmZ9TszerYBXQdHxcjRm87spmLKWgGIdsqe/qUTUhi2Ko/1DZlvx2jC+1LZH teddQZNu3ZZmN+F/ZRB1yonGwlkSs2dGt4OfeY13e7J08W3ssLuQ17aezGsbrG81O/K7 b6T2HuJmHPr+89KqtDRlhfnICAztrAY9zVhHGkjrPxF2nB1LfcD6bOsuk508/2ggNKO8 IdWzP2TB6S0FTOrmrXkTA9JkTZGIsLgv6DtxJfokdJdPuaSyN3+G3XvR7lT86ZtN2fMb 3WfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=CdDVQxPLCMKHBkZRQ2514o0jDVjNgbuLauBY88s6v6Y=; b=njt2S6kvkHKTx4g0dDkFSNnnYRkVVKdiz6S85mfgf1vKeAa7RJaVuoHDGTqXUy57UE YBWuceRVweNya54wMeUp9Y7DwylCjZILyROhI7VtZfBMkUAwejWBq82TK///4pBQMPRJ Dxqw+5YQxPLhbibo8F1/KrO5YJhPohDV0SHzVK3wqXIxpI8kiRIqzD84o7N/Gd0fYbXd XiKN8W08JSo/70h+Ntn/41l1oVdwGMfC3y3b3op8g/rbga+sYhpC9417pGkacubgIuHb 4cDsRklq2fRj8JMlIKyyU+T9YoSdPV7NqUOCZ8hg76V3MKP2D+YJH6H6Cd5LK7wvWTDs axWw== X-Gm-Message-State: ANhLgQ1gTM3JoK8fvfEKtzx7Ld8spw+uk13uG3BnLDVaOhqHuzd78KeS fuwa7To1MAGI/4Tk3TQN6PVUxiqW X-Google-Smtp-Source: ADFU+vt/rWAo5t5NQq2dx/LmBAwzC+JqOdu9OnR9WgCYJUcGbnlMs7eZsNsu7oNYi5WsoLoHjXa8iA== X-Received: by 2002:a63:e00c:: with SMTP id e12mr536712pgh.354.1583680251748; Sun, 08 Mar 2020 08:10:51 -0700 (PDT) Original-Received: from [192.168.2.183] (64-52-176-132.championbroadband.com. [64.52.176.132]) by smtp.gmail.com with ESMTPSA id a22sm9132868pfo.56.2020.03.08.08.10.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Mar 2020 08:10:51 -0700 (PDT) In-Reply-To: <20200308101445.GB28250@tuxteam.de> Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::42c 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:16267 Archived-At: On 3/8/20 3:14 AM, tomas@tuxteam.de wrote: > Hi, > > I'm playing around with Nyacc: I found a first little use case > to get my feet wet. > > First of all, than you, Matt, for this impressive package. > > Shamelessly stolen from the minimal example, playground looks > roughly like this: > > #+begin_source scheme > (use-modules (nyacc lalr)) > (use-modules (nyacc lex)) > (use-modules (nyacc parse)) > > ;; to be used in some ($$ ...) actions: > (define (collect arg) (display arg)) > > (define my-grammar > (lalr-spec > (start my-file) > (grammar > (my-file > (elt-list)) > ;; more productions, calling out to ($$... collect) > (name > ($ident))))) > > (define mach (make-lalr-machine aq-grammar)) > (define mtab (lalr-match-table mach)) > (define gen-lexer (make-lexer-generator mtab)) > (define raw-parse (make-lalr-parser mach)) > (define (parse) (raw-parse (gen-lexer))) > (parse) > #+end_source > > So I defined some function =collect= which will be called from > actions in the grammar. > > My question is: where is the stuff resolved which is mentioned > in grammar actions? My first experiments indicate that it's > looked up at (module) top level, as if (grammar ...) greedily > weaved that in at compile time. > > My idea would be to (pre-) define a grammar and to exchange > the actions later as needed. Or would I have to re-define the > grammar whenever I change my mind about actions? > > Note that I'm still very much in exploratory mode: "you're > holding it wrong" would be a perfectly adequate answer, as > would be "your mumblings are pretty unintelligible" :-) > > Cheers & thanks > -- tomás Nyacc was envisioned with the paradigm you propose, by using tags. But I have not tried that in a while.  If you look at the example calc in examples/nyacc/lang/calc/mach.scm you will see (define (gen-calc-files)   (write-lalr-actions    full-mach "mach.d/calc-full-act.scm" #:prefix "calc-full-")   (write-lalr-tables    full-mach "mach.d/calc-full-tab.scm" #:prefix "calc-full-")   (write-lalr-actions    stmt-mach "mach.d/calc-stmt-act.scm" #:prefix "calc-stmt-")   (write-lalr-tables    stmt-mach "mach.d/calc-stmt-tab.scm" #:prefix "calc-stmt-")   ) You can run this, then you can use the generated files to provide the parser (don't need to run make-lalr-machine anymore.  There are two files generated: one with all the parser tables and one with the actions (only).   You could (copy and) modify the actions file to get different parser actions.   That file includes comments to help: (define calc-full-act-v   (vector    ;; $start => prog    (lambda ($1 . $rest) $1)    ;; prog => stmt-list    (lambda ($1 . $rest) (tl->list $1))    ;; stmt-list => stmt    (lambda ($1 . $rest) (make-tl 'stmt-list $1))    ;; stmt-list => stmt-list stmt    (lambda ($2 $1 . $rest) (tl-append $1 $2))    ;; stmt => "\n"    (lambda ($1 . $rest) `(empty-stmt))    ... Hope this helps. Matt