gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

OffTopic > FLISL (Forth-Like Interpreted Scripting Language)

#161009 - zzo38computer - Sat Jul 26, 2008 6:51 am

Do you think this is a good of scripting-language to embed to other program? Please make a comment of it.

Specifications and examples at: http://zzo38computer.cjb.net/flisl/

This is something I made today and think it is good idea for embedding scripting. I used it in my own program sometimes as well.
_________________
Important: Please send messages about FWNITRO to the public forum, not privately to me.

#161010 - nanou - Sat Jul 26, 2008 7:20 am

Context (please specify).

It definitely depends on what you intend to use it for and what the implementation does. At first I'm tempted to say "no", but if it code for it were close to to the size profile of an actual forth machine, then it could make a good extension language, for example. But for most uses of scripting, it would be a pain to use IMO.

OTOH, why not just implement Forth? I find stack machines awkward to program for so if I'm not getting the benefits of Forth, I don't want to put up with what I see as the drawbacks. But I guess some people love programming that way.
_________________
- nanou

#161016 - keldon - Sat Jul 26, 2008 8:52 am

Hmm; the syntax looks a little ambiguous/inconsistent to me! I created some incremental garbage collection code if you would like to have a look I could send it to you!

#161038 - zzo38computer - Sat Jul 26, 2008 4:46 pm

keldon wrote:
Hmm; the syntax looks a little ambiguous/inconsistent to me!
Can you tell me what you see as inconsistent/ambiguous? If there are mistakes, I would like to correct them.

(Note: Also, I have simplified the ]ELSE and ]ELSE[ commands to go to the end of the next block and executes the command ending that block.)

keldon wrote:
I created some incremental garbage collection code if you would like to have a look I could send it to you!
Can't you just post it here instead? Is that code relevant to this topic, please?
_________________
Important: Please send messages about FWNITRO to the public forum, not privately to me.

#161051 - keldon - Sun Jul 27, 2008 12:01 am

zzo38computer wrote:
Can you tell me what you see as inconsistent/ambiguous? If there are mistakes, I would like to correct them.


The WHILE loop seems a little pointless when compared with the if and does not seem to belong to the same trail of thought; so maybe it should appear more like below ...
Code:
x WHILE [commands ]

... although the "do while" loop does seem coherent and the "if next" loop is an interesting one. (EDIT; it might make complete sense in forth, I've never used it).

zzo38computer wrote:
Can't you just post it here instead? Is that code relevant to this topic, please?

I haven't published the code so I couldn't post a link to it. As for its relevance, it all depends on the type of data your vm operates on; any type of data construct with the need for resource management is a potential candidate for GC.

#161052 - sajiimori - Sun Jul 27, 2008 12:20 am

The WHILE should be inside the brackets because the ]LOOP command jumps back to the opening bracket, and if the WHILE was outside the brackets, it wouldn't be executed again.

Forth is very literal like that, which is part of its charm. =)

Edit: As for my opinion on using a Forth-like language for scripting: Forth is oriented toward the "how" more than the "what" of programming, and in that sense is not as expressive as I'd like.

It also requires a mechanical and diciplined style of thinking, which means technically-challenged scripters won't be able to cobble together bits of game logic without a lot of assistance.

#161053 - keldon - Sun Jul 27, 2008 1:00 am

Oh; I had a feeling it might be part of forth literature; I also noticed that I misread the definition of the IF WHILE construct. I thought it was the same as the loop, now that makes much more sense as a language!

#161054 - zzo38computer - Sun Jul 27, 2008 2:43 am

Code:
x IF[ commands y ]NEXT
is effectively the same as
Code:
x IF[ commands y ]WHILE
in FLISL, use whatever is most sensible to you (a proper implementation of FLISL should accept both ways). This type of loop allows you to have one condition for the first iteration and another condition for the rest of the iterations of the loop. If you want the same condition each time, the
Code:
[ x WHILE commands ]LOOP
format is better.

Some differences from Forth and FLISL and what the equivalent commands would be:
Code:
Forth  :::  FLISL

IF x ELSE y THEN  :::  IF[ x ]ELSE[ y ]
BEGIN x UNTIL  :::  [ x ]UNTIL
BEGIN x AGAIN  :::  [ x ]LOOP
BEGIN x WHILE y REPEAT  :::  [ x WHILE y ]LOOP
BEGIN WHILE REPEAT 0  :::  AND[ ]NEXT

_________________
Important: Please send messages about FWNITRO to the public forum, not privately to me.

#161134 - zzo38computer - Tue Jul 29, 2008 1:28 am

I just fixed it up a bit and added some stuff. (ELSE works a bit differently now) Now it is improved?
_________________
Important: Please send messages about FWNITRO to the public forum, not privately to me.

#161185 - nce - Wed Jul 30, 2008 12:39 am

Personnally I've implemented a stack machine in my project, but I've build a compiler to use the same syntax a C...

I find the FLISL syntax quite hard to follow, and would force me to focus to much on it...

If you just want a good scripting language why not using lua or something ? ( I think lua would have been too much for me, I was just in need of a scripting language for loading and triggering event with the lowest memory impact possible )

Now, if it's for the fun of doing your own that's a good start :)
_________________
-jerome-

#161191 - zzo38computer - Wed Jul 30, 2008 4:13 am

nce wrote:
Personnally I've implemented a stack machine in my project, but I've build a compiler to use the same syntax a C...

I find the FLISL syntax quite hard to follow, and would force me to focus to much on it...

If you just want a good scripting language why not using lua or something ? ( I think lua would have been too much for me, I was just in need of a scripting language for loading and triggering event with the lowest memory impact possible )

Now, if it's for the fun of doing your own that's a good start :)

I understand that, but I don't like Lua, however. FLISL is better (in my opinion). If you have implemented a stack machine in your project, maybe you can allow FLISL syntax to be available as well, in case you want to program more direct? (At least I would prefer the FLISL syntax when it is available, many other people would also, but not everyone) Then you have multiple ways of doing that. Lua is too much I think, FLISL should be even more low memory than Lua (and Lua is already low memory usage, compared to JavaScript).

I also added more optional commands, more examples, and a logo that you can use if you want to indicate which project uses FLISL.
_________________
Important: Please send messages about FWNITRO to the public forum, not privately to me.

#161342 - tepples - Fri Aug 01, 2008 8:22 pm

nce wrote:
If you just want a good scripting language why not using lua or something ? ( I think lua would have been too much for me, I was just in need of a scripting language for loading and triggering event with the lowest memory impact possible )

That might be Lua. I haven't tried Lua, but after I read the manual, a few things jumped out that I'd find hard to get used to, such as the absence of any data structure other than an associative array (which Lua calls a "table" and other languages call a "hash map" or "dict") and the convention of starting array indices as 1.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#161369 - nce - Sat Aug 02, 2008 4:43 am

tepples wrote:
... and the convention of starting array indices as 1.


yes I agree that something annoying but I work a lot with maxscript where it's exactly the same and you can get used to it ( I just do a lot of mistakes if I jump between max and c several time in a day )

btw : maxscript is one of my favorite scripting language

zzo38computer wrote:
If you have implemented a stack machine in your project, maybe you can allow FLISL syntax to be available as well, in case you want to program more direct?


yes technically that shouldn't be hard to do. It's just that I don't have any idea how to specify some part of the language with the flisl syntax ( I haven't look carrefully though ) I've defined my language to do just what I need so :

3 types of variable scope : local ( only defined inside of the function ) global ( defined for all scripts ) member ( defined for the entire instance of the script. )
3 types of variables : integer , vector ( 3 int ) , string ( 12 characters, same size as a vector )
no array, no struct, nothing fancy :)
A script is apply to an object ( character , trigger ,... ).
A script is a list of event that the object will try to call like : onLoad, onDestroy, onEnter, ....

btw, it also does the casting automatically when possible like :
int i = 0;
string x = "aName_" + i;
_________________
-jerome-

#161373 - keldon - Sat Aug 02, 2008 9:49 am

There is also GameMonkey - if you can get it to compile. In regards to Lua's restrictions on data types, you can do a lot with its associative array system, such as:
Code:
Table = {};
Table.X = 10;
Table["Y"] = 20;
print (Table["X"], Table.Y);

#161437 - zzo38computer - Sun Aug 03, 2008 4:20 pm

nce wrote:
tepples wrote:
... and the convention of starting array indices as 1.


yes I agree that something annoying but I work a lot with maxscript where it's exactly the same and you can get used to it ( I just do a lot of mistakes if I jump between max and c several time in a day )

btw : maxscript is one of my favorite scripting language

In BASIC you can set the array index starting to whatever you want to. In Forth (but not FLISL) you can also do that, like:
Code:
HERE 1- 5 ALLOT CONSTANT arrayname



nce wrote:
zzo38computer wrote:
If you have implemented a stack machine in your project, maybe you can allow FLISL syntax to be available as well, in case you want to program more direct?


yes technically that shouldn't be hard to do. It's just that I don't have any idea how to specify some part of the language with the flisl syntax ( I haven't look carrefully though ) I've defined my language to do just what I need so :

3 types of variable scope : local ( only defined inside of the function ) global ( defined for all scripts ) member ( defined for the entire instance of the script. )
3 types of variables : integer , vector ( 3 int ) , string ( 12 characters, same size as a vector )
no array, no struct, nothing fancy :)
A script is apply to an object ( character , trigger ,... ).
A script is a list of event that the object will try to call like : onLoad, onDestroy, onEnter, ....

btw, it also does the casting automatically when possible like :
int i = 0;
string x = "aName_" + i;

FLISL was invented for doing simple things in your scripting language like that (it was invented originally for PuzzleMesh, which needs a embedded scripting language like FLISL). FLISL is good if Lua is too much for you, if you can't or don't want to use Lua, or whatever other reason.

You could look at the PuzzleMesh code for a old version of FLISL implemented in PHP (together with a bunch of PuzzleMesh-specific commands). When the next version of PuzzleMesh is released it will be updated to correspond with the current FLISL specification.

If you want a more complex and full one, you can probably implement a full Forth interpreter (which is still pretty short). If your program is written in C you can also embed Lua if you want to, and there is Forth interpreter written in Lua. I found one which wasn't very good and made some improvements to it (and may continue making more improvements later): http://zzo38computer.cjb.net/luaforth/forth.lua Now I can program ToME in Forth (or I could, if ToME used 5.1. Actually it uses Lua 4.0, I checked, I hope they should fix that soon).
_________________
Important: Please send messages about FWNITRO to the public forum, not privately to me.