Looking for a BASIC code tidier / uncruncher!

discuss general risc os software applications and utilities
Related forum: adventures


Post Reply
philpem
Posts: 594
Joined: Fri Apr 04, 2014 6:42 pm
Contact:

Looking for a BASIC code tidier / uncruncher!

Post by philpem » Wed Sep 16, 2020 11:41 pm

Is anyone aware of an app for RISC OS which can tidy up rotten BASIC code?

I've got a stack of code -- a mix of "just badly written" and some which has gone through a BASIC cruncher/optimiser (e.g. SWIs are numbers, not names). I'd like to fix some of the bugs, but it's pretty hard when the code is as bad as it is...

Cheers
Phil.

User avatar
IanJeffray
Posts: 387
Joined: Sat Jun 06, 2020 3:50 pm
Contact:

Re: Looking for a BASIC code tidier / uncruncher!

Post by IanJeffray » Thu Sep 17, 2020 1:20 am

LISTO 7 as a start? :lol:

User avatar
BeebMaster
Posts: 3736
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: Looking for a BASIC code tidier / uncruncher!

Post by BeebMaster » Thu Sep 17, 2020 10:55 pm

Mmm...for doing find-and-replace of SWI numbers with their names you could do with a bulk find & replace tool which you could feed a list of search strings and the corresponding replace strings. That sort of thing would be useful in all sorts of ways to save having to do potentially dozens of repeat find and replace operations. I can't believe that such a tool doesn't already exist, but I don't know what it is. Maybe Kfilereplace can do it, but I've discontinued using it as it doesn't work on Pi Linux.
Image

User avatar
BeebMaster
Posts: 3736
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: Looking for a BASIC code tidier / uncruncher!

Post by BeebMaster » Thu Sep 17, 2020 11:17 pm

I don't know if it's ever been done, but in the same way that BASIC crunchers concatenate multiple lines, it should be straightforward enough to search for colons and put a line break in (as long as the colon doesn't succeed an IF or a REM etc), and with ARMBASIC it wouldn't even be necessary to try to devise a line number after every new break.

Renaming of variables and procedures & functions would be more difficult in case crunched variable names were picked up by mistake where the same string occurs for another purpose.

Most of my code ends up being a mess until I've got it basically working, then I tidy it up by moving sections into procedures and functions. This is mainly in 8-bit BASIC, and it isn't possible to do partial renumbers, so I use Edit to manually alter the line numbers to move sections about, or spool a section of code, exec it in as a new program, renumber it, spool it again, then load the original, delete the original section and exec the renumbered chunk back in. I think some of the Beeb BASIC extension utility ROMs do have a partial renumberer, although I've never used one. It would be good if there was something like MAKEPROC ThisProc,1000,1170 which would pull out lines 1000 to 1170 and put them at the end in a procedure called ThisProc.

"KILLGOTO" would be very popular as well!
Image

User avatar
BeebMaster
Posts: 3736
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: Looking for a BASIC code tidier / uncruncher!

Post by BeebMaster » Fri Sep 18, 2020 2:55 pm

I had a look at Kfilereplace on Ubuntu, it does have a multiple search & replace function, you can load in a set of strings stored in a text file. I did that a few years ago to all the HTML pages on my website when I was trying to standardise a few things. Somebody would need to generate a list of SWI numbers and names though...
Image

User avatar
Richard Russell
Posts: 1716
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Looking for a BASIC code tidier / uncruncher!

Post by Richard Russell » Sat Sep 19, 2020 10:07 am

philpem wrote:
Wed Sep 16, 2020 11:41 pm
Is anyone aware of an app for RISC OS which can tidy up rotten BASIC code?
Random thoughts:
  • The input to your 'uncruncher' must be tokenised BASIC. Once the tokens are converted to plain text (and assuming the cruncher removed all unnecessary spaces) it's impossible to disentangle keywords from variable names etc. reliably.

  • Spaces must be re-inserted where they are necessary for the code to be edited (but weren't for the code to run). Basically that means checking each token to see if it needs to be followed by a delimiter (some do, some don't), and inserting a space if required.
I am suffering from 'cognitive decline' and depression. If you have a comment about the style or tone of this message please report it to the moderators by clicking the exclamation mark icon, rather than complaining on the public forum.

Post Reply

Return to “32-bit acorn software: other”