Jump to content
Nate.N

Qbasic style > BASIC transpiler - anyone interested?

Recommended Posts

Posted (edited)

UPDATE: This is now available on GitHub: https://github.com/natenorrish/enhanced-basic-transpiler

I've recoded the script completely to parse and output as a tokenized PRG.

I'm also planning to add inline ASM directives to use BASIC, but enabling the option to optimize parts of the program - this will be an experimental feature 🙂

 

------------------------------

Hey all,

My retro programming background is more Qbasic than BASIC, so for me getting used to the first 2 characters only being used for variables was quite painful for me. I'm also not a fan of using line numbers, and would prefer to use subroutines as with Qbasic.

I created a script (which I'll no doubt continue to develop) which converts Qbasic style code into BASIC with line numbers (please see screenshots)

The BASIC output isn't pretty, and I may work on that at some stage.

Features:

@LABEL:  Create labels using @LABEL: - this will be automatically converted to a line number, and anywhere in the code that references @LABEL will be converted to the line number

Variable names: can use alphanumeric characters with underscore (I know not valid in Qbasic). Script will convert variable names to a unique 2 letter variable. This eliminates the worry of having to chose your variable names.

Line numbers: automatically added in and whitspaces / blank lines are removed

Comments: Qbasic style comments with single quote '

 

Planning to add in sub routines which auto handle variables.

Anyone interested?

 

Nate

 

Screenshot 2020-10-06 165644.png

Screenshot 2020-10-06 165708.png

Edited by Nate.N
  • Like 2

Share this post


Link to post
Share on other sites

Actually quite interested, but X16 team is planning to make similar tool built-in.

But for the time being, it's good to have third party option already.

I would wish to have some control over generated variable names, so the generated code would be more readable. But I don't have good ideas on how to implement this.

Share this post


Link to post
Share on other sites
4 minutes ago, Cyber said:

Actually quite interested, but X16 team is planning to make similar tool built-in.

But for the time being, it's good to have third party option already.

I would wish to have some control over generated variable names, so the generated code would be more readable. But I don't have good ideas on how to implement this.

OK cool, I'll clean it up and put it on github.

The exported variables could be the 2 unique letters followed by the original name?

  • Like 1

Share this post


Link to post
Share on other sites
4 minutes ago, Nate.N said:

The exported variables could be the 2 unique letters followed by the original name?

Very nice! I forgot that variable may be of any length, but only first 2 symbols will be significant.

Share this post


Link to post
Share on other sites
17 minutes ago, Cyber said:

Very nice! I forgot that variable may be of any length, but only first 2 symbols will be significant.

Me too, I hadn't touched BASIC for a long time, and had tonnes more experience with Qbasic, so thought I'd make it easier.

The script is available here: https://github.com/natenorrish/x16-enhanced-basic-transpiler

You'll need NodeJS to run it.

Just a thought on the variable names, there are some rules about not being able to use keywords inside them, like: BTNCOLOR  - has COLOR in it, so BASIC will throw an error.

Share this post


Link to post
Share on other sites
Posted (edited)

Brilliant minds think alike... I've been using my own, primitive "transpiler", which lets me use labels, long var names, multiple files, and eschew line numbers.

 

 

Edited by rje
  • Like 2

Share this post


Link to post
Share on other sites

I too prefer a QBASIC-type experience.  Did anyone else ever use Petit Computer for the Nintendo DS?  It uses a BASIC called "SmileBASIC" which was also very QBASIC-like: automatically numbered lines for reporting errors (take that, Microsoft VBA) , but @LABELS for branching.  'Comments with a single-quote.  I remember thinking "typing on this tiny on-screen keyboard with the DS stylus is really annoying, but this flavor of BASIC is really convenient!"

I think once you get used to automatic line numbering, it's hard to go back to typing them manually.

11 hours ago, Cyber said:

 X16 team is planning to make similar tool built-in.

Wow, I hadn't heard that, I think that's great news.

  • Like 1

Share this post


Link to post
Share on other sites
1 minute ago, rje said:

Brilliant minds think alike... I've been using my own, primitive "transpiler", which lets me use labels, long var names, multiple files, and eschew line numbers.

 

 

awesome! 🙂  my next step is to implement an include statement, like you said, for multiple files.  Perhaps a C style #define directive could be good to reduce variable usage.

  • Like 1

Share this post


Link to post
Share on other sites
6 hours ago, John Chow Seymour said:
18 hours ago, Cyber said:

X16 team is planning to make similar tool built-in.

Wow, I hadn't heard that, I think that's great news.

David said in his video that he was impressed with BASIC editor on Maximite computer, and wants to implement similar editor on X16.

Later in Facebook group Lorin mentioned that this editor will have labels instead of line numbers, but under the hood it will generate code with line numbers, converting labels to numbers. Pretty much the same approach as in Nate's transpiler in this thread.

Besides this info, I hadn't heard anything else yet.

  • Like 2

Share this post


Link to post
Share on other sites

@Nate.N I downloaded and tried transpiler. It works and I'm quite happy with it. I added some issues to github page.

  • Like 1

Share this post


Link to post
Share on other sites
8 minutes ago, Cyber said:

@Nate.N I downloaded and tried transpiler. It works and I'm quite happy with it. I added some issues to github page.

Thanks for that! I've left comments on each, and I'll take a look at the variable name issue.

Share this post


Link to post
Share on other sites

I've actually developed a proper transpiler (tokenzing, parsing, etc.) which converts Qbasic to Javascript to run in the browser:

 

So I could modify it to convert to BASIC instead, but wanted to build a quick script in the meantime.

Share this post


Link to post
Share on other sites
Posted (edited)
2 hours ago, Nate.N said:

I've actually developed a proper transpiler (tokenzing, parsing, etc.) which converts Qbasic to Javascript to run in the browser

Ah, my transpiler is only a line scanner, kind of a macro expander only with a little bit of state added in.

Edited by rje

Share this post


Link to post
Share on other sites

Accidentally made a dupe post.  Didn't see anything when I searched for Quick Basic.  Didn't think to do QBasic, oh well.

I am interesting in helping out on this project.  I started tinkered together a rudimentary transcoder.  What you have here is far better.  Here are some of my thoughts.  Let me know what you think.  I was thinking it would also be useful to add an  include or using statement to link to other basic files to allow for creation of code libraries.  Then tweak one of the basic lexers in SciTE to have an ide for development so I can port over some of my old Quick Basic stuff.  After that it would be nice to be able to look at porting the code base into the X16 so it can run as a native app without any external dependencies. 

  • Like 1

Share this post


Link to post
Share on other sites
6 hours ago, Ziglag said:

Accidentally made a dupe post.  Didn't see anything when I searched for Quick Basic.  Didn't think to do QBasic, oh well.

I am interesting in helping out on this project.  I started tinkered together a rudimentary transcoder.  What you have here is far better.  Here are some of my thoughts.  Let me know what you think.  I was thinking it would also be useful to add an  include or using statement to link to other basic files to allow for creation of code libraries.  Then tweak one of the basic lexers in SciTE to have an ide for development so I can port over some of my old Quick Basic stuff.  After that it would be nice to be able to look at porting the code base into the X16 so it can run as a native app without any external dependencies. 

I didn't see much interest in the project so I sort of shelved it, and as it relies on NodeJS to transpile, I guess it's not ideal for most people.

I've had a lot of experience building transpilers and I could definitely rebuild it to work natively, including the inline ASM, but I'm afraid I don't have a lot of time right now.

If I get some time soon, I can get back on it.

Share this post


Link to post
Share on other sites
20 hours ago, Nate.N said:

I didn't see much interest in the project so I sort of shelved it, and as it relies on NodeJS to transpile, I guess it's not ideal for most people.

As an external tool it's not a big deal. I added NodeJS files once and it just works. And it does its job well, so currently no problem of stalled development.

I have many PC tools programs with last release date decades ago, but they just do their job and they do it fine.

Share this post


Link to post
Share on other sites
On 11/13/2020 at 3:57 PM, Cyber said:

As an external tool it's not a big deal. I added NodeJS files once and it just works. And it does its job well, so currently no problem of stalled development.

I have many PC tools programs with last release date decades ago, but they just do their job and they do it fine.

Great to hear that! I will continue to develop it then if it's of some use to others.

  • Like 1

Share this post


Link to post
Share on other sites

Yes, it is. )

But don't overpush yourself. The tool is useful today, but I'm not sure if it will be when X16 is released with similar tool on-board.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Please review our Terms of Use