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

* Re: nyacc support for extension languages
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Joshua Branson @ 2018-08-19 21:28 UTC (permalink / raw)
  To: guile-user

Matt Wette <matt.wette@gmail.com> writes:

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

This is super cool!  Is the goal to eventually make it exactly
matlab/exactly javascript?  Or will there always be some portability
issues?

>
> Matt



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

* Re: nyacc support for extension languages
  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
  0 siblings, 2 replies; 6+ messages in thread
From: Matt Wette @ 2018-08-19 21:30 UTC (permalink / raw)
  To: guile-user

On 08/19/2018 02:28 PM, Joshua Branson wrote:

> Matt Wette <matt.wette@gmail.com> writes:
>
>> 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.
>>
> This is super cool!  Is the goal to eventually make it exactly
> matlab/exactly javascript?  Or will there always be some portability
> issues?
>
I thought about this a bit.  I think hope for 100% compatibility is not there.
For example, javascript strings are always 16bit code points, whereas Guile strings
are either 8-bit characters or 32-bit code points.

Also, I'd like to "fix" some problems in javascript.  For example

var a = 1;
if (1) {
   var a = 2;
}
a => 2
if (1) {
   let a = 3;
}
a => 2

I have made "var" inside blocks illegal. And "let" is not standard, but I'm adding it.

I also want to make the underlying data model consistent among languages, so that may
take some "massaging" of the language def's.

Matt




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

* Re: nyacc support for extension languages
  2018-08-19 21:30   ` Matt Wette
@ 2018-08-20  3:56     ` Nala Ginrut
  2018-08-20 16:00     ` Joshua Branson
  1 sibling, 0 replies; 6+ messages in thread
From: Nala Ginrut @ 2018-08-20  3:56 UTC (permalink / raw)
  To: Matt Wette; +Cc: Guile User

Super neat!
I think nycc can help to alleviate the pain of writing/tweaking parser, and
let people concentrate on implementing better middle-end then convert to
tree-il.


Matt Wette <matt.wette@gmail.com> 于 2018年8月20日周一 05:31写道:

> On 08/19/2018 02:28 PM, Joshua Branson wrote:
>
> > Matt Wette <matt.wette@gmail.com> writes:
> >
> >> 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.
> >>
> > This is super cool!  Is the goal to eventually make it exactly
> > matlab/exactly javascript?  Or will there always be some portability
> > issues?
> >
> I thought about this a bit.  I think hope for 100% compatibility is not
> there.
> For example, javascript strings are always 16bit code points, whereas
> Guile strings
> are either 8-bit characters or 32-bit code points.
>
> Also, I'd like to "fix" some problems in javascript.  For example
>
> var a = 1;
> if (1) {
>    var a = 2;
> }
> a => 2
> if (1) {
>    let a = 3;
> }
> a => 2
>
> I have made "var" inside blocks illegal. And "let" is not standard, but
> I'm adding it.
>
> I also want to make the underlying data model consistent among languages,
> so that may
> take some "massaging" of the language def's.
>
> Matt
>
>
>


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

* Re: nyacc support for extension languages
  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
  1 sibling, 1 reply; 6+ messages in thread
From: Joshua Branson @ 2018-08-20 16:00 UTC (permalink / raw)
  To: guile-user

Matt Wette <matt.wette@gmail.com> writes:

> On 08/19/2018 02:28 PM, Joshua Branson wrote:
>
>> Matt Wette <matt.wette@gmail.com> writes:
>>
>>
> I thought about this a bit.  I think hope for 100% compatibility is not there.
> For example, javascript strings are always 16bit code points, whereas Guile strings
> are either 8-bit characters or 32-bit code points.
>
> Also, I'd like to "fix" some problems in javascript.  For example
>
> var a = 1;
> if (1) {
>   var a = 2;
> }
> a => 2
> if (1) {
>   let a = 3;
> }
> a => 2
>
> I have made "var" inside blocks illegal. And "let" is not standard, but I'm adding it.

That's pretty cool to add let inside javascript!

>
> I also want to make the underlying data model consistent among languages, so that may
> take some "massaging" of the language def's.
>
> Matt



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

* Re: nyacc support for extension languages
  2018-08-20 16:00     ` Joshua Branson
@ 2018-08-20 23:40       ` Matt Wette
  0 siblings, 0 replies; 6+ messages in thread
From: Matt Wette @ 2018-08-20 23:40 UTC (permalink / raw)
  To: guile-user



On 08/20/2018 09:00 AM, Joshua Branson wrote:
> Also, I'd like to "fix" some problems in javascript. For example
>> var a = 1;
>> if (1) {
>>    var a = 2;
>> }
>> a => 2
>> if (1) {
>>    let a = 3;
>> }
>> a => 2
>>
>> I have made "var" inside blocks illegal. And "let" is not standard, but I'm adding it.
> That's pretty cool to add let inside javascript!
>
FYI, the code above was executed in nodejs.

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