116 lines
2.4 KiB
Markdown
116 lines
2.4 KiB
Markdown
|
|
# 2. Getting started
|
||
|
|
|
||
|
|
## The prompt
|
||
|
|
|
||
|
|
Run `basic` with no arguments and you get a prompt:
|
||
|
|
|
||
|
|
```
|
||
|
|
$ ./build/basic
|
||
|
|
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:
|
||
|
|
|
||
|
|
```
|
||
|
|
PRINT 2 + 2
|
||
|
|
4
|
||
|
|
READY
|
||
|
|
```
|
||
|
|
|
||
|
|
## Your first program
|
||
|
|
|
||
|
|
```
|
||
|
|
10 PRINT "WHAT IS YOUR NAME"
|
||
|
|
20 INPUT "> " N$
|
||
|
|
30 PRINT "HELLO, " + N$
|
||
|
|
RUN
|
||
|
|
```
|
||
|
|
|
||
|
|
Type `LIST` to see it back, `RUN` to run it again, and `NEW` to throw it away.
|
||
|
|
|
||
|
|
## Line numbers
|
||
|
|
|
||
|
|
Lines are stored under their numbers and run in numeric order, so the gaps are what
|
||
|
|
let you insert later:
|
||
|
|
|
||
|
|
```
|
||
|
|
10 PRINT "FIRST"
|
||
|
|
30 PRINT "THIRD"
|
||
|
|
20 PRINT "SECOND"
|
||
|
|
LIST
|
||
|
|
10 PRINT "FIRST"
|
||
|
|
20 PRINT "SECOND"
|
||
|
|
30 PRINT "THIRD"
|
||
|
|
```
|
||
|
|
|
||
|
|
Typing a line number with nothing after it deletes that line. `DELETE 20-40` removes a
|
||
|
|
range, and `RENUMBER` tidies the whole program up — it rewrites every `GOTO` and
|
||
|
|
`GOSUB` to match, so it will not break your branches.
|
||
|
|
|
||
|
|
`AUTO 10` turns on automatic numbering so you do not have to type them; `AUTO 0` turns
|
||
|
|
it off again.
|
||
|
|
|
||
|
|
## Several statements on one line
|
||
|
|
|
||
|
|
Statements are separated by colons:
|
||
|
|
|
||
|
|
```
|
||
|
|
10 A# = 1 : B# = 2 : PRINT A# + B#
|
||
|
|
```
|
||
|
|
|
||
|
|
There is one important limit: **block structures do not work inside a single line.**
|
||
|
|
|
||
|
|
```
|
||
|
|
10 FOR I# = 1 TO 3 : PRINT I# : NEXT I#
|
||
|
|
```
|
||
|
|
|
||
|
|
prints nothing at all. The loop body is skipped entirely, because the interpreter skips
|
||
|
|
forward a *line* at a time looking for the `NEXT` and never finds one on the line it is
|
||
|
|
already past. Write loops across several lines:
|
||
|
|
|
||
|
|
```
|
||
|
|
10 FOR I# = 1 TO 3
|
||
|
|
20 PRINT I#
|
||
|
|
30 NEXT I#
|
||
|
|
```
|
||
|
|
|
||
|
|
The same applies to `DO`/`LOOP`.
|
||
|
|
|
||
|
|
## Running a file
|
||
|
|
|
||
|
|
```sh
|
||
|
|
$ ./build/basic program.bas
|
||
|
|
```
|
||
|
|
|
||
|
|
The file is read, stored, and run. It is exactly the same as typing the program in and
|
||
|
|
saving yourself the trouble.
|
||
|
|
|
||
|
|
You can also pipe a program in:
|
||
|
|
|
||
|
|
```sh
|
||
|
|
$ echo '10 PRINT "HI"
|
||
|
|
RUN' | ./build/basic
|
||
|
|
```
|
||
|
|
|
||
|
|
## Saving and loading
|
||
|
|
|
||
|
|
```
|
||
|
|
DSAVE "myprogram.bas"
|
||
|
|
DLOAD "myprogram.bas"
|
||
|
|
```
|
||
|
|
|
||
|
|
`SAVE` and `LOAD` are the same verbs under their other names. `VERIFY "myprogram.bas"`
|
||
|
|
compares what is in memory against the file and prints `OK` if they match.
|
||
|
|
|
||
|
|
## Stopping
|
||
|
|
|
||
|
|
`QUIT` ends the interpreter. `STOP` stops a *program* and returns you to the prompt,
|
||
|
|
where `CONT` resumes it from where it stopped. `END` also stops the program, but does
|
||
|
|
not arm `CONT`.
|
||
|
|
|
||
|
|
In the SDL build, closing the window stops the program too.
|