|
Retro Rocket Kernel
BASIC-Powered Operating System
|
#include <kernel.h>Macros | |
| #define | MAX_VARNAME 50 |
| #define | GENERATE_ENUM(ENUM) ENUM, |
| #define | GENERATE_STRING(STRING) #STRING, |
| #define | GENERATE_ENUM_LIST(MACRO, NAME) enum NAME { MACRO(GENERATE_ENUM) }; |
| #define | GENERATE_ENUM_STRING_NAMES(MACRO, NAME) const char* NAME [] = { MACRO(GENERATE_STRING) }; |
| #define | TOKEN(T) |
| All tokens recognised by the interpreter. Note that built in function names are NOT tokens, they are parsed like user functions, just with a hard coded handler instead of redirecting into the user program. More... | |
Enumerations | |
| enum | token_t { ERROR , ENDOFINPUT , NUMBER , HEXNUMBER , STRING , VARIABLE , LET , PRINT , IF , THEN , ELSE , CHAIN , FOR , STEP , TO , NEXT , CURSOR , GOTO , GOSUB , RETURN , CALL , INPUT , COLOUR , COLOR , BACKGROUND , EVAL , OPENIN , READ , CLOSE , EOF , DEF , PROC , RETPROC , FN , END , REM , COMMA , SEMICOLON , PLUS , MINUS , AND , OR , NOT , EOR , ASTERISK , SLASH , MOD , OPENBRACKET , CLOSEBRACKET , LESSTHAN , GREATERTHAN , EQUALS , NEWLINE , AMPERSAND , TILDE , GLOBAL , SOCKREAD , SOCKWRITE , CONNECT , SOCKCLOSE , CLS , GCOL , LINE , TRIANGLE , RECTANGLE , CIRCLE , POINT , OPENOUT , OPENUP , WRITE , MKDIR , RMDIR , DELETE , REPEAT , UNTIL , DIM , REDIM , PUSH , POP , LOCAL , CHDIR , LIBRARY , YIELD , MOUNT } |
Functions | |
| *brief Initialise tokenizer **param program program text *param ctx context *void | tokenizer_init (const char *program, struct basic_ctx *ctx) |
| void | tokenizer_next (struct basic_ctx *ctx) |
| advance to next token More... | |
| int | tokenizer_token (struct basic_ctx *ctx) |
| peek to next token More... | |
| int64_t | tokenizer_num (struct basic_ctx *ctx, int token) |
| Get integer number as next token (do not advance the pointer) More... | |
| void | tokenizer_fnum (struct basic_ctx *ctx, int token, double *f) |
| Get real number as next token (do not advance the pointer) More... | |
| const char * | tokenizer_variable_name (struct basic_ctx *ctx) |
| Get a variable name as next token (do not advance the pointer) More... | |
| bool | tokenizer_string (char *dest, int len, struct basic_ctx *ctx) |
| Get a string constant as the next token (do not advance the pointer) More... | |
| int | tokenizer_finished (struct basic_ctx *ctx) |
| Returns true if the program is finished (does not advance the pointer) More... | |
| void | tokenizer_error_print (struct basic_ctx *ctx, const char *error) |
| display an error to the terminal and end the program More... | |
| int | get_next_token (struct basic_ctx *ctx) |
| Get the next token (advances the pointer past the end of the token) More... | |
| bool | tokenizer_decimal_number (struct basic_ctx *ctx) |
| Check if a decimal number is at the current program pointer. (does not advance the pointer) More... | |
| #define GENERATE_ENUM | ( | ENUM | ) | ENUM, |
These macros generate both an enum and an array of strings, these are used as part of the tokenizer to parse the names of the keywords out of the BASIC program without having to remember to match up a string and its token enum value in two places. It is also used for error reporting.
| #define GENERATE_ENUM_LIST | ( | MACRO, | |
| NAME | |||
| ) | enum NAME { MACRO(GENERATE_ENUM) }; |
| #define GENERATE_ENUM_STRING_NAMES | ( | MACRO, | |
| NAME | |||
| ) | const char* NAME [] = { MACRO(GENERATE_STRING) }; |
| #define MAX_VARNAME 50 |
| #define TOKEN | ( | T | ) |
All tokens recognised by the interpreter. Note that built in function names are NOT tokens, they are parsed like user functions, just with a hard coded handler instead of redirecting into the user program.
The #define below builds an enum, and can also build an array of strings of the names in the enum, which is built and used within basic.c for tokenization.
| enum token_t |
| int get_next_token | ( | struct basic_ctx * | ctx | ) |
Get the next token (advances the pointer past the end of the token)
| ctx | context |
| bool tokenizer_decimal_number | ( | struct basic_ctx * | ctx | ) |
Check if a decimal number is at the current program pointer. (does not advance the pointer)
| ctx | context |
| void tokenizer_error_print | ( | struct basic_ctx * | ctx, |
| const char * | error | ||
| ) |
display an error to the terminal and end the program
| ctx | context |
| error | error message |
| int tokenizer_finished | ( | struct basic_ctx * | ctx | ) |
Returns true if the program is finished (does not advance the pointer)
| ctx | context |
| void tokenizer_fnum | ( | struct basic_ctx * | ctx, |
| int | token, | ||
| double * | f | ||
| ) |
Get real number as next token (do not advance the pointer)
| ctx | context |
| token | token (NUMBER) |
| f | number read from program |
| * brief Initialise tokenizer* * param program program text* param ctx context* void tokenizer_init | ( | const char * | program, |
| struct basic_ctx * | ctx | ||
| ) |
| void tokenizer_next | ( | struct basic_ctx * | ctx | ) |
advance to next token
| ctx | context |
| int64_t tokenizer_num | ( | struct basic_ctx * | ctx, |
| int | token | ||
| ) |
Get integer number as next token (do not advance the pointer)
| ctx | context |
| token | token (NUMBER or HEXNUMBER) |
| bool tokenizer_string | ( | char * | dest, |
| int | len, | ||
| struct basic_ctx * | ctx | ||
| ) |
Get a string constant as the next token (do not advance the pointer)
| dest | destination string buffer |
| len | length of destination buffer |
| ctx | context |
| int tokenizer_token | ( | struct basic_ctx * | ctx | ) |
peek to next token
| ctx | context |
| const char* tokenizer_variable_name | ( | struct basic_ctx * | ctx | ) |
Get a variable name as next token (do not advance the pointer)
| ctx | context |