New community dev tool uploaded: BASIC PREPROCESSOR

All aspects of programming on the Commander X16.
Ed Minchau
Posts: 508
Joined: Sat Jul 11, 2020 3:30 pm

New community dev tool uploaded: BASIC PREPROCESSOR

Post by Ed Minchau »


You're right, that is an ugly-but-simple syntax.  It could be prettier and simpler though, perhaps something like this:

GOSUB [QUERYNAME]

[+LOOP]

PRINT "HELLO ";N$;"! HOW ARE YOU?       ";

GOTO [LOOP]

[+QUERYNAME]

INPUT "WHAT IS YOUR NAME";N$

RETURN

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

New community dev tool uploaded: BASIC PREPROCESSOR

Post by rje »


Huh.  I never considered posting my script as a thing.  Huh!

 

Scott Robison
Posts: 952
Joined: Fri Mar 19, 2021 9:06 pm

New community dev tool uploaded: BASIC PREPROCESSOR

Post by Scott Robison »



30 minutes ago, Ed Minchau said:




You're right, that is an ugly-but-simple syntax.  It could be prettier and simpler though, perhaps something like this:



GOSUB [QUERYNAME]



[+LOOP]



PRINT "HELLO ";N$;"! HOW ARE YOU?       ";



GOTO [LOOP]



[+QUERYNAME]



INPUT "WHAT IS YOUR NAME";N$



RETURN



That is also another way it could be done. I was looking for a "self delimiting character" so I didn't want to use brackets, though I agree they are more readable. My scanning code is so simple and it trusts that @ is matched with @, " is matched with ", and that anything between the open and close character is part of the label. I could use apostrophe instead of @ as a "more readable self delimiting character".

Ed Minchau
Posts: 508
Joined: Sat Jul 11, 2020 3:30 pm

New community dev tool uploaded: BASIC PREPROCESSOR

Post by Ed Minchau »



1 hour ago, Scott Robison said:




That is also another way it could be done. I was looking for a "self delimiting character" so I didn't want to use brackets, though I agree they are more readable. My scanning code is so simple and it trusts that @ is matched with @, " is matched with ", and that anything between the open and close character is part of the label. I could use apostrophe instead of @ as a "more readable self delimiting character".



Maybe just use the + sign when declaring the label, and not use the minus? The easier it is to use, the more it will be used.

Scott Robison
Posts: 952
Joined: Fri Mar 19, 2021 9:06 pm

New community dev tool uploaded: BASIC PREPROCESSOR

Post by Scott Robison »


Perhaps. It's my own brand of OCD feeling like the first character defines the type of the "name" (definition or expansion). I was thinking about possibly other ones as well, this is just as far as I got when I decided to share it. "+" to add to symbol table, "-" to look up in symbol table. Maybe "!" to declare a long variable name that can be mapped to a short two character name.

It's very much a thought exercise seeing just how far I can get with pure BASIC, which I already violated to call the crunch routine in ML. ?

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

New community dev tool uploaded: BASIC PREPROCESSOR

Post by rje »


A thoughtful feature I like about this are the REM statements that show where the labels were.

 

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

New community dev tool uploaded: BASIC PREPROCESSOR

Post by rje »



On 4/21/2021 at 12:05 PM, Scott Robison said:




My second program will be BASIC EDIT. Not a competitor to x16 edit, but something very simple that can edit small text files. I will write it in BASIC PREPROCESSOR syntax so it will serve as the first "big" example of BASIC PREPROCESSOR. My intent is to write the smallest possible editor I can that allows me to add text, remove text, save files, and load files. Once I have that done I will try to do all my dev "natively" in the emulator (which is a contradiction in terms, but it is hopefully clear enough in context).



I actually started a vi-like editor, in BASIC, in February.  I dinked with it for two days then put it on the shelf.

 

It uses the left-arrow as the escape to command mode.  Which I had forgotten, and therefore is probably a bad idea.

 

On the cutesy side, I apparently named it "xvi", which is therefore a pun both on vi and on the x16.

 

 

 


main-vi.list
vi.bas
rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

New community dev tool uploaded: BASIC PREPROCESSOR

Post by rje »



49 minutes ago, Scott Robison said:




Perhaps. It's my own brand of OCD feeling like the first character defines the type of the "name" (definition or expansion).



Maybe you're an LL(0) kind of guy.

That's my preference as well.  Simplifies the parsing logic, without actual pain for the developer.

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

New community dev tool uploaded: BASIC PREPROCESSOR

Post by rje »



10 hours ago, Scott Robison said:




As for ASCII vs PETSCII, it would be nice if there was some sort of a BOM character like exists for Unicode that could be used as the first character in a file to identify the encoding.



I think..... just off the top of my head..... there are characters that are non-printable codes in one but printable in the other.... if the file is on the X16 then, surely there's a character that renders "wrong" (for some value of "wrong") if it's ASCII..... and therefore would never have a right to exist in a text file... hrmmmmmm.....

Establish guardrails, such as "this must be a text file", and then you'll be able to detect whether or not it's PETSCII by whether or not that first character is actually PETSCII printable.  If it ain't, then assume that's a flag indicating the rest of the file is ASCII...? 

 

For example, ASCII 15, 16, 21, 22, 23, 25, 26 appear to be printable, but not in PETSCII.

Scott Robison
Posts: 952
Joined: Fri Mar 19, 2021 9:06 pm

New community dev tool uploaded: BASIC PREPROCESSOR

Post by Scott Robison »



32 minutes ago, rje said:




A thoughtful feature I like about this are the REM statements that show where the labels were.



 



As it turned out, that was a lazy hack on my part that wound up being useful. Since a label may be defined on a line by itself (or not) there needs to be a line number to associate with the label, as I don't really know at the time of parsing what the next generated line number would be. So rather than making the system more complex, I just had it generate a REM so that I could target the line.

Post Reply