March 2021
Mo Tu We Th Fr Sa Su
<< >>


On NekoML Syntax

Posted on Sep 18 2005

After some holidays and some work on, I'm back to Neko development. I'm currently working on the NekoML compiler, I finished this week the pattern matching compilation (type checking, completeness test and Neko generation) which was quite a big part. I'm currently playing with the compiler, trying to port the Neko compiler from OCaml to NekoML. I'm also trying to improve the syntax.

I came up with an idea that I think is interesting. In OCaml syntax you don't have like in C to use parenthesis and commas for calling functions : a b c can be translated into C a(b,c). One of the reason is "tuples". a(b,c) also have a meaning, which is : call a with one argument which is the tuple (b,c).

In NekoML, I wanted to be able to use C syntax, so I made the difference by specifying the tuple as argument : a((b,c)) will call a with the tuple while a(b,c) will call a with two arguments.

On the other hand, when you use imbricated calls for example, you don't want to write : f(g(h)). OCaml notation f (g h) is more readable. So I added also the fact that a b c and a(b,c) will be both acceptable ways for calling a function.

That's where the syntax get into trouble... in the following case : a b (c,d) are you doing a(b,(c,d)) or a(b(c,d)) ? I decided then to differentiate two kind of tokens for the left parenthesis : if there is any number of spaces at the left of an opening parenthesis, then it means we're not doing any call. If there is no spaces then it is acceptable for a call.

That might sound a little bit strange for language designers since most of the time spaces are simply ignored, but when you write NekoML programs it comes very naturally : a b (c,d) means a(b,(c,d)) while a b(c,d) means a(b(c,d)). In the same kind, you can rewrite the following OCaml expression :

ETry(f e,ident,f e2)

Into what looks more natural in my opinion :

ETry f(e) ident f(e2)

There is several other improvements in NekoML syntax over OCaml, I'll try to setup some documentation when I'm done with the compiler.

1 comment
  • Audi Nugraha
    Sep 06, 2018 at 19:37

    Just out of curiousity...

    Why there should be "rec" before "function" keyword to define recursive function in NekoML?

Name : Email : Website : Message :