|
G2Basic 0.1.1 (1e793fc)
BASIC interpreter for microcontrollers
|
Entering program lines, running statements, and running programs. More...
Functions | |
| int | g2basic_parse (const char *input, double *result, const char **error) |
| Process one line of input. | |
Entering program lines, running statements, and running programs.
| int g2basic_parse | ( | const char * | input, |
| double * | result, | ||
| const char ** | error | ||
| ) |
Process one line of input.
The line is classified in this order:
LIST, RUN, or NEW as the first word, in any letter case, runs that command. Any text after the command is ignored.Because of rule 2, an immediate expression cannot start with a digit: 2 + 3 stores line 2. Write PRINT 2 + 3 or (2 + 3) instead.
RUN executes the stored lines in line-number order. A runtime error stops the program and is reported through the text callback as Error in line N: message; g2basic_parse() still returns 3.
| input | NUL-terminated line without a line terminator. It is not modified or retained. | |
| [out] | result | Must not be NULL. Receives the statement's value for return value 0 (the value of an expression or assignment, otherwise 0), the line number for 1 and 2, and 0 for 3. Unchanged for -1. |
| [out] | error | Must not be NULL. Set only on failure, so initialize the pointed-to value to NULL before the call. The message is static and must not be freed. Some messages are rewritten by the next call. It is not set when the line number is out of range. |
| 0 | An immediate statement ran successfully. |
| 1 | A program line was deleted, or did not exist. |
| 2 | A program line was stored. |
| 3 | LIST, RUN, or NEW ran. |
| -1 | The immediate statement failed, or the line number is outside 0 to 65535. |