CPCWiki forum

General Category => Programming => Topic started by: logiker on 14:39, 07 March 19

Title: BASIC: Get line per length
Post by: logiker on 14:39, 07 March 19
Hi!


Is there an easy way to get the length per line (tokens, not letters) of a basic program?


Thanks
Title: Re: BASIC: Get line per length
Post by: GeoffB17 on 17:21, 07 March 19
First of all, I'd not be sure that there is a reliably standard method for doing the conversion from a text program line to the tokenised version, so each implementation of BASIC could be different.

You don't specify which version of BASIC you're talking about.

Usually, keywords are converted.   Literal text, i.e. strings, may be in the nine as literal, but a variable may be actually stored somewhere else.   Numeric variable, I'm not sure.   How would you count these?

You may need to investigate, and work it out.

Does your BASIC allow the return of the address of a variable, even a $?

You may need to create a line of code with a $ at the start and finish, then get the address of the two marker $, then display the RAM contents from before the first to after the last marker and see just what is there, how your BASIC stores the data, and the full line.

Or does the manual for your BASIC define any of the details already?

Edit:  You might find some useful info here, although this relates to GW-BASIC.   While the details may be different, many of the general principles may be similar.

http://www.chebucto.ns.ca/~af380/GW-BASIC-tokens.html

Geoff
Title: Re: BASIC: Get line per length
Post by: SRS on 22:27, 07 March 19
I'm not sure what you are looking for .. this ?
A BASIC program is stored in a tokenised format. Here the keywords are represented by 1 or 2 byte unique sequences.
Each line of the BASIC program has the form:
OffsetSizeDescription
02Length of line data in bytes (note 1)
2216-bit decimal integer line number (note 2)
4nBASIC line encoded into tokens (note 3)
n+11"0" the end of line marker (note 4)
Notes: So peek(&170)+256*peek(&171) gives you length of first line
Title: Re: BASIC: Get line per length
Post by: logiker on 14:28, 10 March 19
Thanks for your replies.
I wanted to calculate the size of a line for the BASIC10Liners Compo. Now I found out, that only the "typed" characters count. Therefor this question is obsolet to me. Now the new question would be, how do I count the minimum required characters for typing. But that's another topic.
Powered by SMFPacks Menu Editor Mod