BASIC and strings

Hardware Hacking, Programming and Game Solutions/Cheats
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

BASIC and strings

Post by jedie »

Where can i find information about quotes, double quotes, escape in BASIC code?

In Python this is possible:

Code: Select all

print "normal"
print 'normal'
print 'foo " bar'
print "foo ' bar"
print "foo \" bar"
print """foo " bar"""
And a few more. The output is:

Code: Select all

normal
normal
foo " bar
foo ' bar
foo " bar
foo " bar
My question is for the BAS2WAV converter: viewtopic.php?f=8&t=4231

If i will create a WAV or CAS file, i need to parse the BASIC code to replace the BASIC keywords with tokens. (Otherwise i can only output a ASCII version)
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
User avatar
robcfg
Posts: 1530
Joined: Sat Apr 04, 2009 10:16 pm
Location: Stockholm, Sweden
Contact:

Re: BASIC and strings

Post by robcfg »

Have you got around how the dragon's basic generates the line pointers?

Otherwise, you can only save ascii and be able to load it again. Which isn't bad anyway...
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: BASIC and strings

Post by jedie »

robcfg wrote:Have you got around how the dragon's basic generates the line pointers?

Otherwise, you can only save ascii and be able to load it again. Which isn't bad anyway...
No, i don't :(

My Idea: A offset + length of previous line?
But a fixed offset makes no sense, because it's too "restricted" :?: I will ask on the CoCo ML...

EDIT: http://five.pairlist.net/pipermail/coco ... 70938.html
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
User avatar
Rolo
Posts: 228
Joined: Sun Feb 10, 2013 7:36 pm

Re: BASIC and strings

Post by Rolo »

Well, my approach simply would be to do it the way most of us learnt BASIC back in 198x. We read the manuals of our computers. For example the C64 manual (less than 100 pages) or the Dragon manual :D . The world was not so complicated back then and manuals could be read within minutes to hours.

Well out of the top of my head:
Single quotes do have no meaning in BASIC (at least in that kind of BASIC). It is just an ASCII-character like any letter. It never came to my mind to write something like PRINT 'HELLO WORLD'.
The concept of escaping characters was unknown to me until I started with C. If I needed an ESCAPE or a non-printable character, for example a printer control command, i would use CHR$(xxx), like PRINT CHR$(27)+CHR$(66). Same for double quotes (CHR$(34))
Strings are concatenated with "+" (PRINT "HALLO"+CHR$(20)+"WORLD").
Strings and/or Variables are printed with a TAB in between if you type a comma "," (PRINT "HALLO",A);
Strings and/or Variables are printed with a SPACE in between if you type a semicolon ";" (PRINT "HALLO";A);
Same for comma and semi-colon at the end of the line.
Leaving out the closing double quotes at the end of the command line was not "punished". New line, new context.

I think that are 95% of the rules. Really simple. Did I forget something?
User avatar
JeeK
Posts: 67
Joined: Fri Aug 16, 2013 10:45 am
Location: Vienna, Austria
Contact:

Re: BASIC and strings

Post by JeeK »

Rolo wrote:Well, my approach simply would be to do it the way most of us learnt BASIC back in 198x. We read the manuals of our computers. For example the C64 manual (less than 100 pages) or the Dragon manual :D . The world was not so complicated back then and manuals could be read within minutes to hours.

Well out of the top of my head:
Single quotes do have no meaning in BASIC (at least in that kind of BASIC). It is just an ASCII-character like any letter. It never came to my mind to write something like PRINT 'HELLO WORLD'.
[..]
I think that are 95% of the rules. Really simple. Did I forget something?
Right, this kind of MS Basic interpreters (didn't see anything other in Dragon ROM) knows only two states:
1. inside a string: everything has to be taken "as-is" until the next double quote or end of line will be reached. (EDITED)
2. outside a string: token interpretation/expansion occurs until the next double quote or end of line. (EDITED)

On line beginning the starting state is always "1". (EDITED)

This strategy can be also seen in a (some sort of "official") Commodore utility which converts Basic 4.0 code into Basic 7.0, which just uses a flip variable to track the state. ;)
Last edited by JeeK on Thu Aug 29, 2013 12:39 pm, edited 1 time in total.
Sarah
Posts: 177
Joined: Wed Apr 13, 2011 3:36 pm
Contact:

Re: BASIC and strings

Post by Sarah »

Just a couple more quick points that might affect what you're doing:

A single quote starts a comment, but obviously not when inside double quotes. It could be followed by a double quote without starting a string and there may be an odd number of such double quotes; the same obviously applies to REM statements too.

In some circumstances it's possible to get away without explicitly terminating a string, e.g.

10 PRINT "HELLO WORLD
20 GOTO 10

This runs without error despite the PRINT string not being explicitly terminated, because the end of statement does so implicitly.

Actually, just noticed Rolo already mentioned this, but it's easily missed. :)
User avatar
JeeK
Posts: 67
Joined: Fri Aug 16, 2013 10:45 am
Location: Vienna, Austria
Contact:

Re: BASIC and strings

Post by JeeK »

Sarah wrote:Just a couple more quick points that might affect what you're doing:

A single quote starts a comment, but obviously not when inside double quotes. It could be followed by a double quote without starting a string and there may be an odd number of such double quotes; the same obviously applies to REM statements too.
[..]
Just to note:
At least on CBMs REMs might have unexpected side effects. String quotes after REM (I presume after a single quote remark to) are honored. On CBMs you can enter graphical characters or uppercase letters (in lowercase mode) which represents token values. Such will be be expanded (by LIST) if not quoted with double quotes. I didn't checked or found a situation so far if this could happen in Dragon Basic (maybe on a Dragon 64?), too.
The dragon on my side: http://klasek.at/hc/dragon/
Sarah
Posts: 177
Joined: Wed Apr 13, 2011 3:36 pm
Contact:

Re: BASIC and strings

Post by Sarah »

Dragon BASIC doesn't touch the contents of comments, as far as I know. The comment text can contain some special characters - only if achieved through modification - but usually won't, as most comments will have been entered using the keyboard.

I used to quite enjoy POKEing some ASCII 8 (DEL) characters into comment lines at the start of BASIC programs, so that they'd appear to LIST without line numbers! :)
User avatar
JeeK
Posts: 67
Joined: Fri Aug 16, 2013 10:45 am
Location: Vienna, Austria
Contact:

Re: BASIC and strings

Post by JeeK »

Sarah wrote:Dragon BASIC doesn't touch the contents of comments, as far as I know. The comment text can contain some special characters - only if achieved through modification - but usually won't, as most comments will have been entered using the keyboard.
I didn't meant that BASIC changed anything of the program contents, it's just LIST which interprets (translates to the cleartext of a token) control characters in token number range. This was the question, if keyboard sequences exist which correlates to token codes (beside poking directly into the BASIC text).
Sarah wrote:I used to quite enjoy POKEing some ASCII 8 (DEL) characters into comment lines at the start of BASIC programs, so that they'd appear to LIST without line numbers! :)
Right, quite popular on CBM where the whole set of control characters provides a poor man's program protection (to hide machine code calls, passwords and secrets) ... :twisted:
The dragon on my side: http://klasek.at/hc/dragon/
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: BASIC and strings

Post by jedie »

Thanks for the information.

Seems that it makes sense to build a example BASIC program with all variants for testing.
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
Post Reply