[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

nyacc support for extension languages

From: Matt Wette
Subject: nyacc support for extension languages
Date: Sun, 12 Aug 2018 12:48:49 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

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

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;

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

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://


reply via email to

[Prev in Thread] Current Thread [Next in Thread]