More sytnax candy?

BlitzMax Forums/BlitzMax Programming/More sytnax candy?

Pineapple(Posted 2015) [#1]
I love BlitzMax and I've been using it for so long, I have so many random libraries and snippets that I have to rewrite any time I do something substantial in another language. But I feel like it has some serious lackings as far as usability goes. Operator and function overriding being a big one. Also conditional compiling, multiple inheritance, lambdas, macros, explicit function inlining, inlined C, and lots more. All of these could surely be accomplished without too much fuss just by writing a fairly simple preprocessor to translate the syntax candy into regular BlitzMax code.

And so I'm very tempted to write such a thing myself, but first: Has anyone done this already? It'd be much more convenient that way.


Brucey(Posted 2015) [#2]
I was considering applying interfaces, generics and overloading to bmx_ng at some point (since Monkey has them).


LT(Posted 2015) [#3]
True first-order functions would be nice, too.

EDIT: Make that first-class...


Yasha(Posted 2015) [#4]
just by writing a fairly simple preprocessor


My feeling is that a "preprocessor" that could handle anything as complicated as operator overloading or multiple inheritance would be a far more powerful piece of technology than the existing compiler anyway. The existing backend is completely redundant in that situation - if you're writing a full compiler (which you are, since it has to recognise the complete syntax of Max and do sophisticated type checking), you may as well target a more useful backend, like C or LLVM.

@LT you mean first-class/higher order? (first-order is more or less what it already has)


Did anyone (*cough* Brucey) obtain or reverse-engineer a proper grammar? (The last time I looked at it the backported Monkey compiler wasn't rule-based ...) Community language tools would be much more plausible if there was any kind of concrete, non ad-hoc information about the language itself.


LT(Posted 2015) [#5]
@Yasha - Yeah, first-class is what I meant.

As much as I love BlitzMax, I am finding myself running into a wall on some of the limitations.


Yahfree(Posted 2015) [#6]
I'm currently busy with some other obligations but I have the start of a formal grammar for bmax I put together over a couple hours. If anyone is interested here it is (*ISON / BNF), this is Jison, a JavaScript parser generator:



And here's more or less a working lexer:




Yasha(Posted 2015) [#7]
That's really cool, thanks.

I made an initial attempt at a Max translation of the lexer:



I can't directly translate the parser quite as easily, as TMeta.bmx is LL/top down. Am willing to try to follow that up later if anyone is interested though.


Yahfree(Posted 2015) [#8]
The parser isn't complete yet unfortunately. :\

It's difficult reverse engineering the language, since there are a lot of cases where you can do things multiple ways to do things, Like:

Graphics 200, 200
Local test = 10


Graphics(200, 200)
test = 10


But definitively possible. I was going to target SuperStrict mode first.

But the key is to get it into a parser generator language like Bison, because then you can generate a parser for basically any language, and any kind of parser that is powerful enough as well (LL, LALR(1), you name it).

I chose to do it in JavaScript because after I'm done writing it I wanted to put the parser in the browser so people can test their code with it and verify it produces a sensible abstract syntax tree.

If getting BlitzMax to parse BlitzMax is what you're after, I would still recommend finishing the Bison implementation, since you can generate a parser for C++ and can most definitively interop it with BlitzMax.


Yasha(Posted 2015) [#9]
Bison is the way forward for a serious implementation, yes.

TMeta is just something I came up with mainly because the two-stage build process of parser-generator -> source -> program was annoying when exploring a design space. It is combinator-based. It isn't very efficient, but I haven't seen any actual problems with performance yet. Unfortunately there's no syntactically elegant way to do combinators in BlitzMax... *sigh*.