Document optional line numbers

Chapter 2 gets the rule and the refusal, chapter 4 gets the payoff for
LABEL, chapter 9 says DSAVE writes the numbers it handed out and to
RENUMBER first if you want gaps, chapter 10 shows a host loading numberless
source, chapter 13 gets the QuickBASIC-shaped divergence, and chapter 14's
source[] passage gets its second half.

Chapter 14 said "two prescans" and listed two; there were three before this
and there are four now, so it lists all four and says which of them reports
against the right line.

TODO.md section 6 records four things found on the way and deliberately not
fixed: set_label() filing into the active scope rather than the root, three
prescans reporting the wrong line number, duplicate written line numbers
still replacing silently, and renumber.c's file-scope scratch arrays.

examples/embed.c runs the same program twice, numbered and not, so the
example compiles the feature rather than describing it. Its header pointed
at ./build/examples/embed, which is not where the binary lands.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-01 16:43:14 -04:00
parent 6273be580a
commit 28ea99a638
8 changed files with 240 additions and 5 deletions

View File

@@ -12,8 +12,8 @@ READY
`READY` is printed whenever the interpreter is waiting for you, which is at startup
and after a program stops.
Anything you type **with a line number** is stored as part of a program. Anything you
type **without** one runs immediately:
At the prompt, anything you type **with a line number** is stored as part of a program,
and anything you type **without** one runs immediately:
```basic repl
PRINT 2 + 2
@@ -23,6 +23,9 @@ PRINT 2 + 2
4
```
That rule is the prompt's, and only the prompt's. **A program in a file does not need
line numbers at all** — see [Line numbers](#line-numbers) below.
## Your first program
```basic repl
@@ -69,6 +72,50 @@ range, and `RENUMBER` tidies the whole program up — it rewrites every `GOTO` a
`AUTO 10` turns on automatic numbering so you do not have to type them; `AUTO 0` turns
it off again.
### A program in a file does not need them
Numbers are what tells the *prompt* a program line from a statement to run now. A file
has no such problem, so a program loaded from one — or handed to the library as a string
by a host — may leave them out entirely:
```basic
PRINT "COUNTING:"
FOR I# = 1 TO 3
PRINT I# * I#
NEXT I#
PRINT "DONE"
```
```output
COUNTING:
1
4
9
DONE
```
Lines with no number are given the next one going, so they still run in the order you
wrote them, and a blank line costs nothing. You can mix the two: a numbered line sets
where the next unnumbered one goes.
**A program written this way branches by `LABEL`**, which is what makes it worth doing —
see [Chapter 4](04-control-flow.md#labels). Numbers you never wrote are not numbers you
can branch to, and saying so is the one thing the interpreter is strict about:
```basic
PRINT "A"
GOTO 2
```
```output
? 2 : PARSE ERROR Line 2: branch to line 2, which the program did not number. Branch by LABEL, or RENUMBER first
```
`LIST` shows the numbers it handed out, so you can still edit a loaded program at the
prompt, and `DSAVE` writes them into the file. They come out one apart, with no gaps to
insert into — `RENUMBER` before you save if you want the gaps back.
## Several statements on one line
Statements are separated by colons: