Interpreter built with BlitzMax?

BlitzMax Forums/BlitzMax Programming/Interpreter built with BlitzMax?

SystemError51(Posted 2012) [#1]
Hey all,

short question. Has someone out there built some kind of interpreter or parser with BlitzMax? Not just for configuration files, more in the way that you write a certain script or sequence of commands with parameters, in your BlitzMax interprets that, and thus executes something?

I'm wondering in general as my current project may require such a functionality.

Cheers peeps


matibee(Posted 2012) [#2]
You mean more than the current scripting languages? Lua, BriskVM and Angelcode [edit *Angelscript*] (google them I'm too lazy for linkage:) )

I've always liked the look of Angelcode and had a long time respect for the author, right back to my early pc / internet based game dev days, literally sometime in the last century.

Last edited 2012


ImaginaryHuman(Posted 2012) [#3]
I did my own system, which I am revisiting at the moment. It wont be released but just FYI I'm using arrays of function pointers. The array stores a sequence of function references and then they are `played` with a simple `program counter` which increments and moves through the array, calling each function. So the array is kind of like a program, made up of small functions. Each of the functions of course has to have the same number of parameters so I made all function have zero parameters and have a second array with offsets for storing parameter data.

It works very efficiently because there is basically almost no time spend on `interpreting`, it just calls function after function, so the overhead is just the function calls. Of course this means the `language` has to be simple, akin to assembly language where you have have small distinct commands and each opcode has only a few fixed parameters.

The `program` is an array of function pointers so I basically convert the `program` into a function pointer program after loading it. You could maybe call that compiling, but it's a simple 1:1 match between a command a function, nothing too fancy.

Last edited 2012


matibee(Posted 2012) [#4]
Sounds good IH.. it's something I was going to do for interpreting math input eg "6*4" or "23.3+7" but I looked harder and found Bruceys parser mod. That actually does a bit more than just parsing math because it can call custom functions etc...

http://muparser.sourceforge.net/mup_features.html


Pineapple(Posted 2012) [#5]
I've written a token parser, it should be nearly trivial to make an interpreter using it, but I want to make a compiler (to bytecode) with it sometime.

Last edited 2012


jsp(Posted 2012) [#6]
I created a scanner, tokenizer and parser for Logic Gui. It can parse all MaxGUI commands and create an editable form for the designer.

The most difficult part was the parsing of all the different parameters a MaxGUI command can have.

@ImaginaryHuman
How do you handle the function parameters?


ziggy(Posted 2012) [#7]
@ImaginaryHuman: That's fun to see that's how generated bytecode is being interpreted in Harpl, the language I'm writing using Monkey.

http://code.google.com/p/harpl-project/

By the way, you can take a look to the Harpl source code, it's complex but quite complete on datatype and expressions evaluation. I'm still needing to make lots of work regarding data flow, arrays, classes, etc. and I'm considering converting the whole thing to a Jasmin compiled language, not sure just yet.

Last edited 2012


daaan(Posted 2012) [#8]
I did one a few years back. Everything written in BlitzMax, even a virtual machine with it's own byte code. Here is the gallery submission.

http://blitzmax.com/gallery/view_pic.php?id=1845&gallery=hr&page=21


Yasha(Posted 2012) [#9]
Unlikely to be at all what you're looking for (and I'm not 100% sure it works correctly), but I built one once too: Lambda Calculus

Started work on a full Lisp environment a while back, but gave up for various reasons to do it in C instead.


ziggy(Posted 2012) [#10]
By the way, I've just found this ultra simple script language I wrote years ago, it might be a good starting point? It's not byte-code based, it's string-code based wich makes it a lot easier to debug.
I don't think the implementation is very good, but you can get a basic idea of how to make a script compiler and vm in a very simplified way.

http://www.blitzmax.com/codearcs/codearcs.php?code=2103


SystemError51(Posted 2012) [#11]
Wow thanks ziggy :) I'll have a look at that!