Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Cross-platform DBPro reimplementation

Author
Message
Memorix101
4
Years of Service
User Offline
Joined: 14th Feb 2016
Location:
Posted: 29th Sep 2019 17:59
Back in 2017, I've got the idea to do a cross-platform reimplementation of DBPro like MonoGame for XNA.
I've worked on it for a weekend and put it on hold since then.

However, I open-sourced it in the hope to find some people who are interested to support me and commit to it, because it's a lot of work to implement all DBPro commands myself.

The goal is to build a cross-platform compiler to compile DB/DBPro code for Windows, Linux, Mac and other platforms.

https://gitlab.com/Memorix101/darkgamekit


tboy
7
Years of Service
User Offline
Joined: 1st Jan 2013
Location:
Posted: 29th Sep 2019 21:43
Hi Memorix,

I think this is a cool idea and well worth pursuing, even if it's just for the experience of creating a product of this magnitude.

I know TGC have GameGuru and AppGameKit but I think they are well overdue a new DBPRO perhaps call it DarkBasicX (X for cross platform) and this
could provide them the start they need. I realise there are many different products now to choose from but I truely believe DBPRO resonates
with many people and will use it regardless of the competition.

I'll keep an eye on this project and help out when and if I can.

Best of luck!
Memorix101
4
Years of Service
User Offline
Joined: 14th Feb 2016
Location:
Posted: 30th Sep 2019 09:03
Hi,

DBPro was one of the first things that got me into programming when I was a child.
I started programming at the age of 10 years.
I love those little games and their old graphics style.
The thought that all of this would be kinda lost makes me sad.
Sometimes when I find old code in the TGC magazines it even doesn't work on actual Windows OSes anymore because DirectX has changed.

This project could work for any platform that raylib supports: Desktop, Raspberry Pi, Android, WebGL.
I rewrote it so many times. I started with SDL2 and OpenGl at first. Then changed it to a different engine and finally changed it to raylib because it's so much handier than SDL2 and OpenGL code.

Currently, I'm implementing all the base commands and try to get the audio and 2D part working.
Brian Lancaster
6
Years of Service
User Offline
Joined: 20th Dec 2013
Location: Oakland, CA
Posted: 8th Feb 2020 02:51
Holy crap, please let this come to fruition. I would love for Brigand: Oaxaca to run on Linux. I switched to AppGameKit for my next project and it forces me to use sprites instead of just pasting images. Anything I can do to promote it online?
TheComet
12
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 17th Feb 2020 19:38 Edited at: 17th Feb 2020 19:41
Hi @Memorix101

It's funny that I found this because I just started working on a cross platform DBP compiler myself. Mostly for the sake of learning more about parsers and compilers.
https://github.com/thecomet/opendarkbasic

Hit me up, maybe we can combine our codebases. My discord is TheComet#5387.

From a quick glance at your repo it looks like you've started reimplementing the SDK, which is something I've not started. Well, I see a lot of stubs, but that's more than what I've got!

I'm about 80% done with the parser. I still need to add support for function and subroutine definitions, UDTs, arrays, pointers, and commands. There are probably a few other obscure things I've forgotten about, but I've got enough DB code to throw at it to find almost everything.

For those interested in how one would approach something like this, I can go into a bit more detail on what I've done so far.

The parser is built using Flex and Bison. Flex is a lexical analyzer generator, which lets you specify a set regular expression rules that get matched against your input text to produce tokens. These are most of the rules for DarkBASIC:
https://github.com/TheComet/OpenDarkBASIC/blob/master/odb-compiler/src/Scanner.lex#L29

Bison lets you specify the language's syntax using an input grammar, which is a set of rules that it tries to match against the tokens produced by the Flex lexer. You can see the grammar for DarkBASIC here:
https://github.com/TheComet/OpenDarkBASIC/blob/master/odb-compiler/src/Parser.y#L139

The result is that something like this:


Gets converted into a structure of relationships between each token, also known as a "(abstract) syntax tree" or AST:



Here is a more complex example:


https://forum.thegamecreators.com/attachment/85329

Once you have the AST it's easy to manipulate it to do e.g. optimizations or to match references. It's also fairly straight forward to evaluate the program (interpret it) or use it to generate machine code.

The graphics above were generated by dumping the AST structure to DOT format and using graphviz to convert it to an image.
"Jeb Bush is a big fat mistake" -- Donald Trump
https://vt.tumblr.com/tumblr_o2rvwdLLSF1rmjly4.mp4

Attachments

Login to view attachments
TheComet
12
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 20th Feb 2020 21:06 Edited at: 20th Feb 2020 21:09
I guess I'll start posting updates in this thread? Sorry @Memorix101 if you don't want me to I can make my own thread

The parser now supports function calls, function declarations, gosub, subroutine declarations, and UDTs. It does not support goto and commands are still not fully working.

I wrote a parser which can load the original keyword.ini files and build a dictionary of keywords. This is necessary because otherwise statements such as the following would be too ambiguous to parse:


Or


I also wrote a CLI for interfacing with the compiler. This is what it looks like:



I've tried parsing iced.dba from the DBC samples and it gets about 90% of it right, which is a very good sign.

Here's the link to the github repo if you want to try and compile/run it for yourself. I'm developing it on linux but if you install Flex and Bison it will also work on Windows.
https://github.com/thecomet/opendarkbasic
"Jeb Bush is a big fat mistake" -- Donald Trump
https://vt.tumblr.com/tumblr_o2rvwdLLSF1rmjly4.mp4

Attachments

Login to view attachments
TheComet
12
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 23rd Feb 2020 04:42 Edited at: 23rd Feb 2020 04:43
I hit a milestone today. I was able to parse iced.dba, one of the original DBC samples. Here's the AST overview:



You can also click here to look at the SVG in your browser: https://forum.thegamecreators.com/attachment/85353

I went through manually and validated it as best as I could, and as far as I can tell, there's only some minor issues with operator precedence. For instance, this code


Looks like this in the AST:


Which translates back to:
"Jeb Bush is a big fat mistake" -- Donald Trump
https://vt.tumblr.com/tumblr_o2rvwdLLSF1rmjly4.mp4

Attachments

Login to view attachments
TheComet
12
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Mar 2020 19:13
I exhaustively tested all operators in DBP to figure out their precedence. Here they all are ordered lowest to highest:


The program I used to do this is here:


For example, if ^ has a higher precedence than / then this program will print "bca". Otherwise it will print "abc". This lets you test all operators and construct a sorted list, which I can then use to implement the grammar correctly.

DBP's operator precedence rules are a bit unusual. First off, they don't have operators with equal precedence. For example, + and - in most languages are usually treated equally strong, but in DBP, minus will bind first. This is true for all operators you might think are equal, like << and >>, or <> and =.

It is also strange that equals is stronger than all bitwise operators except for bitshift.

Anyway, my parser now follows the precedence rules of DBP exactly. I obviously have written unit tests to check for this:



I tried parsing an old game of mine called LightShip to see how fast it is, and I can process about 6k lines in 10ms without optimizations. So I'm fairly happy:



Select/case statements are also implemented, and so is goto.
"Jeb Bush is a big fat mistake" -- Donald Trump
https://vt.tumblr.com/tumblr_o2rvwdLLSF1rmjly4.mp4

Login to post a reply

Server time is: 2020-04-03 06:39:33
Your offset time is: 2020-04-03 06:39:33