Qbasic style > BASIC transpiler - anyone interested?

Chat about anything CX16 related that doesn't fit elsewhere
Nate.N
Posts: 11
Joined: Sat Oct 03, 2020 10:15 pm

Qbasic style > BASIC transpiler - anyone interested?

Post by Nate.N »


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



User avatar
Cyber
Posts: 482
Joined: Mon Apr 27, 2020 7:36 am

Qbasic style > BASIC transpiler - anyone interested?

Post by Cyber »


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.

Nate.N
Posts: 11
Joined: Sat Oct 03, 2020 10:15 pm

Qbasic style > BASIC transpiler - anyone interested?

Post by Nate.N »



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?

User avatar
Cyber
Posts: 482
Joined: Mon Apr 27, 2020 7:36 am

Qbasic style > BASIC transpiler - anyone interested?

Post by Cyber »



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.

Nate.N
Posts: 11
Joined: Sat Oct 03, 2020 10:15 pm

Qbasic style > BASIC transpiler - anyone interested?

Post by Nate.N »



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.

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Qbasic style > BASIC transpiler - anyone interested?

Post by rje »


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.

 

 

John Chow Seymour
Posts: 143
Joined: Sun Jul 05, 2020 3:27 pm

Qbasic style > BASIC transpiler - anyone interested?

Post by John Chow Seymour »


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.

Nate.N
Posts: 11
Joined: Sat Oct 03, 2020 10:15 pm

Qbasic style > BASIC transpiler - anyone interested?

Post by Nate.N »



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.

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Qbasic style > BASIC transpiler - anyone interested?

Post by rje »


The #define is a nice touch.

User avatar
Cyber
Posts: 482
Joined: Mon Apr 27, 2020 7:36 am

Qbasic style > BASIC transpiler - anyone interested?

Post by Cyber »



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.

Post Reply