Re: [dev] nscript - a little stack-based scripting language interpretter I wrote

From: Nikhilesh S <s.nikhilesh_AT_gmail.com>
Date: Thu, 26 Aug 2010 03:02:08 +0300 (AST)

On Wed, 25 Aug 2010, Kris Maglione wrote:

> Personally, I don't think that a special syntax for variable definition fits
> well in a stack-based language. I prefer the PostScript syntax of quoting the
> word and using the def keyword, so:
>
> 2 $var def
>
> or
>
> { 'hi' print } $foo def
>
> or the reverse, or another quoting character. It could also replace &foo to
> push a block onto the stack, since executing the quoted word would be
> equivalent to executing its associated block.

Hmm, I will have to think about this.

The current way of doing it makes the implementation very simple - if it
encounters a '$' it just reads the variable name and makes a new one. If
it encounters an '&', it just sets 'callFunc' to 0 and continues like
a normal name-read except it won't execute it now - it'll just push the
object onto the stack. Then 'callFunc' is set back to 1 (the default).

$bla can be used to reassign to variables too. So even after 'foo' is
defined, running '3 $foo' will set foo to 3, whatever it was before.

For it to work your way, I'll have to change the implementation a bit.
It might have to search ahead for a 'def' and do things differently.
What advantages does your idea provide?

Actually I will probably rewrite the whole parser in a more proper way
some time - right now it just runs through the characters with a primitive
state system and some forward-peeking, and simply executes the code as
it goes by (the whole thing is in 'ns_interpret' in nscript.c). Should
I use 'bison' or something instead?
Received on Thu Aug 26 2010 - 02:02:08 CEST

This archive was generated by hypermail 2.2.0 : Thu Aug 26 2010 - 01:12:02 CEST