Page 1 of 2

BASIC and strings

Posted: Wed Aug 28, 2013 1:01 pm
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)

Re: BASIC and strings

Posted: Wed Aug 28, 2013 2:24 pm
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...

Re: BASIC and strings

Posted: Wed Aug 28, 2013 2:38 pm
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

Re: BASIC and strings

Posted: Wed Aug 28, 2013 2:59 pm
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?

Re: BASIC and strings

Posted: Wed Aug 28, 2013 8:37 pm
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. ;)

Re: BASIC and strings

Posted: Wed Aug 28, 2013 9:17 pm
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. :)

Re: BASIC and strings

Posted: Thu Aug 29, 2013 1:13 pm
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.

Re: BASIC and strings

Posted: Thu Aug 29, 2013 6:32 pm
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! :)

Re: BASIC and strings

Posted: Thu Aug 29, 2013 10:05 pm
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:

Re: BASIC and strings

Posted: Fri Aug 30, 2013 8:48 am
by jedie
Thanks for the information.

Seems that it makes sense to build a example BASIC program with all variants for testing.