From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.devel,gmane.lisp.guile.user Subject: nyacc support for extension languages Date: Sun, 12 Aug 2018 12:48:49 -0700 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1534103220 29618 195.159.176.226 (12 Aug 2018 19:47:00 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 12 Aug 2018 19:47:00 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 To: guile-devel@gnu.org, guile-user@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Aug 12 21:46:56 2018 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fowKF-0007c1-VO for guile-devel@m.gmane.org; Sun, 12 Aug 2018 21:46:56 +0200 Original-Received: from localhost ([::1]:36211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fowMK-0001JJ-RO for guile-devel@m.gmane.org; Sun, 12 Aug 2018 15:49:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56635) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fowME-0001He-Dh for guile-devel@gnu.org; Sun, 12 Aug 2018 15:48:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fowMD-0006fl-J3 for guile-devel@gnu.org; Sun, 12 Aug 2018 15:48:58 -0400 Original-Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:39153) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fowM8-0006fN-Pc; Sun, 12 Aug 2018 15:48:52 -0400 Original-Received: by mail-pg1-x529.google.com with SMTP id a11-v6so6568750pgw.6; Sun, 12 Aug 2018 12:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=j7+3IIJ2RgDjRwKsEyJ2SZlDqduF5R/I7UX2kjdwaHI=; b=AJ4hMD9/bh+F5YujOrss+bMBXzuT4f5WfJIW0lnTZvF5rAAGEa8k5gGV8PhW0z0Q9p YKaPm7WmX+JLXEdQEJuTN2YsLHZje7N/Yk8Y7059SE0DqCRKdPh9m/9NMx9RfrzqN23x 4OP+qJ8JFwu8HC4ZWfCL+J5vYWEtLgCtotTILkXYELspEKGnf5+2cRcKf9jTwkIqugYj K9mizDXvBtd4EareWVgXhUnlN4zsZcwWNN2CPQUkhXA9cjE92F5ZIRa/EwXBp+VMi2QB XBfxZYQjffUQ7r+3ngD9Fx+cf0uF3xeIQtNLsppk6v00asTc4zR4AcMacQSJFW15fwDV FQlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=j7+3IIJ2RgDjRwKsEyJ2SZlDqduF5R/I7UX2kjdwaHI=; b=QHiXdyacSaBYEisY6gRPedW/lNsZfiUR4Cjws31P6THD8/ck2sS/NWp9VdAz/XlQRZ 4Ixr/k7UaukpuhiZK7ZOlVNh//4ux9BW6Su1BFuVznfNIo3OWcrsCSBK6q4ViUkCQkFg qr7g4jVMua1LvVDQNcBYnD8AIG8Q93YTZ7iRv1aYoN6G2PVarODJXX+6LJtaBcZ6ZTp3 lNdFfUhQq6O+HoLM6eupzx3Dtbx3zLUudoUBr4IvxH6v3+c5RSmtx6VioXKbd8Ty4S7x 6yLynBAVjKzFBviRTKZvX3bA2Hmtlz8IImWf/Td7BHtEb1maznEXTvH3nlLbF40NlS1v I5+g== X-Gm-Message-State: AOUpUlGFfeztIyVzZXTQQ4Bv6ORN2HlbiXbrVYMkPEWrepGaA85P2zZr ogMWhhS84rQ46wwBLTbqWRIoUhxD X-Google-Smtp-Source: AA+uWPymC5mqMAaKjcM61ph11V0u79QRo3pRZFzTsTHKF7skt1kyxSx+9daimZSkWRRwnSQmFONgag== X-Received: by 2002:a62:b604:: with SMTP id j4-v6mr16169539pff.199.1534103331043; Sun, 12 Aug 2018 12:48:51 -0700 (PDT) Original-Received: from [192.168.2.183] (216-165-229-229.championbroadband.com. [216.165.229.229]) by smtp.gmail.com with ESMTPSA id d81-v6sm28363500pfj.122.2018.08.12.12.48.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Aug 2018 12:48:50 -0700 (PDT) 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::529 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:19621 gmane.lisp.guile.user:14733 Archived-At: I am working on providing a module to add to the nyacc distribution for the purpose of generating extension languages, and putting together a few extensions for demo. So far I'm playing with javascript and matlab. These languages use a "nx-" prefix to designate them as "nyacc extension". One can interpret "nx" to also mean "not exactly", so "nx-matlab" is not exactly MATLAB. It has taken some work to get my yacc like parser to parse expressions instead of files, so some work has gone into updating the nyacc parser. nyacc/parse.scm now has parser generators that provide an #:interactive option and more robust default-reductions for generating parsers which work well in interactive mode. nyacc/parse.scm fragment: (define* (make-lalr-parser/num mach #:key (skip-if-unexp '()) interactive) (let* ((len-v (assq-ref mach 'len-v)) (rto-v (assq-ref mach 'rto-v)) (pat-v (assq-ref mach 'pat-v)) (xct-v (make-xct (assq-ref mach 'act-v))) (start (assq-ref (assq-ref mach 'mtab) '$start))) (lambda* (lexr #:key debug) (let iter ((state (list 0)) ; state stack (stack (list '$@)) ; sval stack (nval #f) ; prev reduce to non-term val (lval #f)) ; lexical value (from lex'er) (cond ((and interactive nval (eqv? (car nval) start)) ; done (cdr nval)) ((not (or nval lval)) (if (eqv? $default (caar (vector-ref pat-v (car state)))) (iter state stack (cons $default #f) lval) ; default reduction (iter state stack nval (lexr)))) ; reload (else ... Here is a demo for "nx-matlab": $ cat simp0.m function [c,d,e] = simp0(a, b) x = a + 1; y = b + 1; c = x * y; d = 1; e = 2; end $ guild compile --from=nx-matlab simp0.m wrote `/home/mwette/.cache/......./simp0.m.go' $ guile scheme@(guile-user)> (load "simp0.m") scheme@(guile-user)> (call-with-values (lambda () (simp0 1 2)) ... (lambda (c d e) (simple-format #t "~S\n~S\n~S\n" c d e))) 6 1 2 scheme@(guile-user)> ,L nx-matlab Happy hacking with nx-matlab! To switch back, type `,L scheme'. nx-matlab@(guile-user)> [c,d,e] = simp0(1, 2); nx-matlab@(guile-user)> c $1 = 6 nx-matlab@(guile-user)> d $2 = 1 nx-matlab@(guile-user)> e $3 = 2 I am working in the nxdev branch of git://git.savannah.nongnu.org/nyacc.git. Matt