unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* nyacc support for extension languages
@ 2018-08-12 19:48 Matt Wette
  2018-08-19 21:28 ` Joshua Branson
  0 siblings, 1 reply; 6+ messages in thread
From: Matt Wette @ 2018-08-12 19:48 UTC (permalink / raw)
  To: guile-devel, guile-user

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




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-08-20 23:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-12 19:48 nyacc support for extension languages Matt Wette
2018-08-19 21:28 ` Joshua Branson
2018-08-19 21:30   ` Matt Wette
2018-08-20  3:56     ` Nala Ginrut
2018-08-20 16:00     ` Joshua Branson
2018-08-20 23:40       ` Matt Wette

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).