mirror of
https://github.com/adamdunkels/ubasic.git
synced 2026-11-22 12:39:44 +00:00
Adjust debugging
Adjust logging of pointers and tokens to made debugging easier
This commit is contained in:
parent
7db3e7fe76
commit
daf68b7a12
4 changed files with 210 additions and 166 deletions
|
|
@ -1 +1,26 @@
|
||||||
1 print "start of test"
2 a$= "abcdefghi"
3 b$="123456789"
5 print "Length of a$+", len(a$)
6 print "Length of b$=", len(b$)
7 if len(a$) = len(b$) then print "same length"
8 if (a$ = b$) then print "same string"
9 c$=left$(a$+ b$,12)
10 print c$
11 c$=right$(a$+b$, 12)
12 print c$
13 c$=mid$(a$+b$, 8,8)
14 print c$
15 c$=str$(13+42)
16 print c$
17 print len(c$)
18 print len("this" + "that")
19 c$ = chr$(34)
20 print c$
21 j = asc(c$)
22 print j
23 print val("12345")
24 i=instr(3, "123456789", "67")
24 print "position of '67' in '123456789' is", i
25 print mid$(a$,2,2)+"xyx"
30 print "end of test"
|
1 print "start of test"
|
||||||
|
2 a$= "abcdefghi"
|
||||||
|
3 b$="123456789"
|
||||||
|
5 print "Length of a$+", len(a$)
|
||||||
|
6 print "Length of b$=", len(b$)
|
||||||
|
7 if len(a$) = len(b$) then print "same length"
|
||||||
|
8 if (a$ = b$) then print "same string"
|
||||||
|
9 c$=left$(a$+ b$,12)
|
||||||
|
10 print c$
|
||||||
|
11 c$=right$(a$+b$, 12)
|
||||||
|
12 print c$
|
||||||
|
13 c$=mid$(a$+b$, 8,8)
|
||||||
|
14 print c$
|
||||||
|
15 c$=str$(13+42)
|
||||||
|
16 print c$
|
||||||
|
17 print len(c$)
|
||||||
|
18 print len("this" + "that")
|
||||||
|
19 c$ = chr$(34)
|
||||||
|
20 print c$
|
||||||
|
21 j = asc(c$)
|
||||||
|
22 print j
|
||||||
|
23 print val("12345")
|
||||||
|
24 i=instr(3, "123456789", "67")
|
||||||
|
24 print "position of '67' in '123456789' is", i
|
||||||
|
25 print mid$(a$,2,2)+"xyx"
|
||||||
|
30 print "end of test"
|
||||||
|
|
|
||||||
112
tokenizer.c
112
tokenizer.c
|
|
@ -28,7 +28,9 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 1
|
||||||
|
#define VERBOSE 1
|
||||||
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#define DEBUG_PRINTF(...) printf(__VA_ARGS__)
|
#define DEBUG_PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
|
@ -41,7 +43,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static char const *ptr, *nextptr;
|
static char const *ptr, *nextptr, *startptr;
|
||||||
|
|
||||||
static char const *prog;
|
static char const *prog;
|
||||||
|
|
||||||
|
|
@ -74,13 +76,50 @@ static const struct keyword_token keywords[] = {
|
||||||
{NULL, TOKENIZER_ERROR}
|
{NULL, TOKENIZER_ERROR}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct keyword_token tokens[] = {
|
||||||
|
{"TOKENIZER_ERROR",TOKENIZER_ERROR},
|
||||||
|
{"TOKENIZER_ENDOFINPUT",TOKENIZER_ENDOFINPUT},
|
||||||
|
{"TOKENIZER_NUMBER",TOKENIZER_NUMBER},
|
||||||
|
{"TOKENIZER_STRING",TOKENIZER_STRING},
|
||||||
|
{"TOKENIZER_VARIABLE",TOKENIZER_VARIABLE},
|
||||||
|
{"TOKENIZER_LET",TOKENIZER_LET},
|
||||||
|
{"TOKENIZER_PRINT",TOKENIZER_PRINT},
|
||||||
|
{"TOKENIZER_IF",TOKENIZER_IF},
|
||||||
|
{"TOKENIZER_THEN",TOKENIZER_THEN},
|
||||||
|
{"TOKENIZER_ELSE",TOKENIZER_ELSE},
|
||||||
|
{"TOKENIZER_FOR",TOKENIZER_FOR},
|
||||||
|
{"TOKENIZER_TO",TOKENIZER_TO},
|
||||||
|
{"TOKENIZER_NEXT",TOKENIZER_NEXT},
|
||||||
|
{"TOKENIZER_GOTO",TOKENIZER_GOTO},
|
||||||
|
{"TOKENIZER_GOSUB",TOKENIZER_GOSUB},
|
||||||
|
{"TOKENIZER_RETURN",TOKENIZER_RETURN},
|
||||||
|
{"TOKENIZER_CALL",TOKENIZER_CALL},
|
||||||
|
{"TOKENIZER_REM",TOKENIZER_REM},
|
||||||
|
{"TOKENIZER_PEEK",TOKENIZER_PEEK},
|
||||||
|
{"TOKENIZER_POKE",TOKENIZER_POKE},
|
||||||
|
{"TOKENIZER_END",TOKENIZER_END},
|
||||||
|
{"TOKENIZER_COMMA",TOKENIZER_COMMA},
|
||||||
|
{"TOKENIZER_SEMICOLON",TOKENIZER_SEMICOLON},
|
||||||
|
{"TOKENIZER_PLUS",TOKENIZER_PLUS},
|
||||||
|
{"TOKENIZER_MINUS",TOKENIZER_MINUS},
|
||||||
|
{"TOKENIZER_AND",TOKENIZER_AND},
|
||||||
|
{"TOKENIZER_OR",TOKENIZER_OR},
|
||||||
|
{"TOKENIZER_ASTR",TOKENIZER_ASTR},
|
||||||
|
{"TOKENIZER_SLASH",TOKENIZER_SLASH},
|
||||||
|
{"TOKENIZER_MOD",TOKENIZER_MOD},
|
||||||
|
{"TOKENIZER_HASH",TOKENIZER_HASH},
|
||||||
|
{"TOKENIZER_LEFTPAREN",TOKENIZER_LEFTPAREN},
|
||||||
|
{"TOKENIZER_RIGHTPAREN",TOKENIZER_RIGHTPAREN},
|
||||||
|
{"TOKENIZER_LT",TOKENIZER_LT},
|
||||||
|
{"TOKENIZER_GT",TOKENIZER_GT},
|
||||||
|
{"TOKENIZER_EQ",TOKENIZER_EQ},
|
||||||
|
{"TOKENIZER_LF",TOKENIZER_LF},
|
||||||
|
{"TOKENIZER_CR",TOKENIZER_CR}
|
||||||
|
};
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int singlechar(void){
|
||||||
singlechar(void)
|
|
||||||
{
|
|
||||||
if(*ptr == '\n') {
|
if(*ptr == '\n') {
|
||||||
return TOKENIZER_CR;
|
|
||||||
} else if(*ptr == '\r'){
|
|
||||||
return TOKENIZER_LF;
|
return TOKENIZER_LF;
|
||||||
} else if(*ptr == ',') {
|
} else if(*ptr == ',') {
|
||||||
return TOKENIZER_COMMA;
|
return TOKENIZER_COMMA;
|
||||||
|
|
@ -116,13 +155,11 @@ singlechar(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int get_next_token(void){
|
||||||
get_next_token(void)
|
|
||||||
{
|
|
||||||
struct keyword_token const *kt;
|
struct keyword_token const *kt;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
DEBUG_PRINTF("get_next_token(): '%s'\n", ptr);
|
DEBUG_PRINTF("get_next_token: %p.\n", ptr-startptr);
|
||||||
|
|
||||||
// eat all whitespace
|
// eat all whitespace
|
||||||
while(*ptr == ' ' || *ptr == '\t' || *ptr == '\r') ptr++;
|
while(*ptr == ' ' || *ptr == '\t' || *ptr == '\r') ptr++;
|
||||||
|
|
@ -138,16 +175,16 @@ get_next_token(void)
|
||||||
nextptr = ptr + i;
|
nextptr = ptr + i;
|
||||||
return TOKENIZER_NUMBER;
|
return TOKENIZER_NUMBER;
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTF("get_next_token: error due to too short number\n");
|
DEBUG_PRINTF("get_next_token: error due to too short number.\n");
|
||||||
return TOKENIZER_ERROR;
|
return TOKENIZER_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!isdigit(ptr[i])) {
|
if(!isdigit(ptr[i])) {
|
||||||
DEBUG_PRINTF("get_next_token: error due to malformed number\n");
|
DEBUG_PRINTF("get_next_token: error due to malformed number.\n");
|
||||||
return TOKENIZER_ERROR;
|
return TOKENIZER_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DEBUG_PRINTF("get_next_token: error due to too long number\n");
|
DEBUG_PRINTF("get_next_token: error due to too long number.\n");
|
||||||
return TOKENIZER_ERROR;
|
return TOKENIZER_ERROR;
|
||||||
} else if(singlechar()) {
|
} else if(singlechar()) {
|
||||||
nextptr = ptr + 1;
|
nextptr = ptr + 1;
|
||||||
|
|
@ -173,21 +210,18 @@ get_next_token(void)
|
||||||
return TOKENIZER_VARIABLE;
|
return TOKENIZER_VARIABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return TOKENIZER_ERROR;
|
return TOKENIZER_ERROR;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void tokenizer_goto(const char *program)
|
void tokenizer_goto(const char *program){
|
||||||
{
|
|
||||||
ptr = program;
|
ptr = program;
|
||||||
current_token = get_next_token();
|
current_token = get_next_token();
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void tokenizer_init(const char *program){
|
||||||
tokenizer_init(const char *program)
|
|
||||||
{
|
|
||||||
ptr = program;
|
ptr = program;
|
||||||
prog = program;
|
prog = program;
|
||||||
|
startptr = program;
|
||||||
current_token = get_next_token();
|
current_token = get_next_token();
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
@ -197,15 +231,13 @@ tokenizer_token(void)
|
||||||
return current_token;
|
return current_token;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void tokenizer_next(void){
|
||||||
tokenizer_next(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(tokenizer_finished()) {
|
if(tokenizer_finished()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_PRINTF("tokenizer_next: %p\n", nextptr);
|
DEBUG_PRINTF("tokenizer_next: %p.\n", nextptr - startptr);
|
||||||
ptr = nextptr;
|
ptr = nextptr;
|
||||||
|
|
||||||
while(*ptr == ' ') {
|
while(*ptr == ' ') {
|
||||||
|
|
@ -223,7 +255,7 @@ tokenizer_next(void)
|
||||||
tokenizer_next();
|
tokenizer_next();
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_PRINTF("tokenizer_next: '%s' %d\n", ptr, current_token);
|
DEBUG_PRINTF("tokenizer_next: %p %s.\n", ptr-startptr, tokenizer_token_name(current_token));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
@ -233,9 +265,7 @@ tokenizer_num(void)
|
||||||
return atoi(ptr);
|
return atoi(ptr);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void tokenizer_string(char *dest, int len){
|
||||||
tokenizer_string(char *dest, int len)
|
|
||||||
{
|
|
||||||
char *string_end;
|
char *string_end;
|
||||||
int string_len;
|
int string_len;
|
||||||
|
|
||||||
|
|
@ -257,7 +287,7 @@ tokenizer_string(char *dest, int len)
|
||||||
void
|
void
|
||||||
tokenizer_error_print(void)
|
tokenizer_error_print(void)
|
||||||
{
|
{
|
||||||
DEBUG_PRINTF("tokenizer_error_print: '%s'\n", ptr);
|
DEBUG_PRINTF("tokenizer_error_print: %p.\n", ptr-startptr);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int
|
int
|
||||||
|
|
@ -272,8 +302,26 @@ tokenizer_variable_num(void)
|
||||||
return *ptr - 'a';
|
return *ptr - 'a';
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
char const *
|
char const *tokenizer_pos(void){
|
||||||
tokenizer_pos(void)
|
|
||||||
{
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char const *tokenizer_start(void) {
|
||||||
|
return startptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//char* tokenizer_token_name(int token){
|
||||||
|
// struct keyword_token kt;
|
||||||
|
// kt = keywords[token];
|
||||||
|
// char* name = kt.keyword;
|
||||||
|
// return(name);
|
||||||
|
//}
|
||||||
|
|
||||||
|
char *tokenizer_token_name(int token) {
|
||||||
|
for (int i = 0; tokens[i].keyword != NULL; i++) {
|
||||||
|
if (tokens[i].token == token) {
|
||||||
|
return tokens[i].keyword; // return string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL; // not found
|
||||||
|
}
|
||||||
19
tokenizer.h
19
tokenizer.h
|
|
@ -33,12 +33,12 @@
|
||||||
#include "vartype.h"
|
#include "vartype.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TOKENIZER_ERROR,
|
TOKENIZER_ERROR, // 0
|
||||||
TOKENIZER_ENDOFINPUT,
|
TOKENIZER_ENDOFINPUT, // 1
|
||||||
TOKENIZER_NUMBER,
|
TOKENIZER_NUMBER, // 2
|
||||||
TOKENIZER_STRING,
|
TOKENIZER_STRING, // 3
|
||||||
TOKENIZER_VARIABLE,
|
TOKENIZER_VARIABLE, // 4
|
||||||
TOKENIZER_LET,
|
TOKENIZER_LET, // 5
|
||||||
TOKENIZER_PRINT,
|
TOKENIZER_PRINT,
|
||||||
TOKENIZER_IF,
|
TOKENIZER_IF,
|
||||||
TOKENIZER_THEN,
|
TOKENIZER_THEN,
|
||||||
|
|
@ -69,8 +69,8 @@ enum {
|
||||||
TOKENIZER_LT,
|
TOKENIZER_LT,
|
||||||
TOKENIZER_GT,
|
TOKENIZER_GT,
|
||||||
TOKENIZER_EQ,
|
TOKENIZER_EQ,
|
||||||
TOKENIZER_CR,
|
TOKENIZER_LF,
|
||||||
TOKENIZER_LF
|
TOKENIZER_CR
|
||||||
};
|
};
|
||||||
|
|
||||||
void tokenizer_goto(const char *program);
|
void tokenizer_goto(const char *program);
|
||||||
|
|
@ -85,5 +85,8 @@ int tokenizer_finished(void);
|
||||||
void tokenizer_error_print(void);
|
void tokenizer_error_print(void);
|
||||||
|
|
||||||
char const *tokenizer_pos(void);
|
char const *tokenizer_pos(void);
|
||||||
|
char const *tokenizer_start(void);
|
||||||
|
|
||||||
|
char *tokenizer_token_name(int token);
|
||||||
|
|
||||||
#endif /* __TOKENIZER_H__ */
|
#endif /* __TOKENIZER_H__ */
|
||||||
|
|
|
||||||
218
ubasic.c
218
ubasic.c
|
|
@ -28,7 +28,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 1
|
||||||
|
#define VERBOSE 0
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#define DEBUG_PRINTF(...) printf(__VA_ARGS__)
|
#define DEBUG_PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
|
@ -82,8 +83,7 @@ poke_func poke_function = NULL;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
ubasic_init(const char *program)
|
ubasic_init(const char *program){
|
||||||
{
|
|
||||||
program_ptr = program;
|
program_ptr = program;
|
||||||
for_stack_ptr = gosub_stack_ptr = 0;
|
for_stack_ptr = gosub_stack_ptr = 0;
|
||||||
index_free();
|
index_free();
|
||||||
|
|
@ -91,9 +91,7 @@ ubasic_init(const char *program)
|
||||||
ended = 0;
|
ended = 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void ubasic_init_peek_poke(const char *program, peek_func peek, poke_func poke){
|
||||||
ubasic_init_peek_poke(const char *program, peek_func peek, poke_func poke)
|
|
||||||
{
|
|
||||||
program_ptr = program;
|
program_ptr = program;
|
||||||
for_stack_ptr = gosub_stack_ptr = 0;
|
for_stack_ptr = gosub_stack_ptr = 0;
|
||||||
index_free();
|
index_free();
|
||||||
|
|
@ -103,39 +101,34 @@ ubasic_init_peek_poke(const char *program, peek_func peek, poke_func poke)
|
||||||
ended = 0;
|
ended = 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void accept(int token){
|
||||||
accept(int token)
|
|
||||||
{
|
|
||||||
if(token != tokenizer_token()) {
|
if(token != tokenizer_token()) {
|
||||||
DEBUG_PRINTF("Token not what was expected (expected %d, got %d)\n",
|
DEBUG_PRINTF("accept: Token not what was expected (expected '%s', got %d).\n",
|
||||||
token, tokenizer_token());
|
tokenizer_token_name(token),
|
||||||
|
tokenizer_token());
|
||||||
tokenizer_error_print();
|
tokenizer_error_print();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
DEBUG_PRINTF("Expected %d, got it\n", token);
|
DEBUG_PRINTF("accept: Expected '%s', got it.\n", tokenizer_token_name(token));
|
||||||
tokenizer_next();
|
tokenizer_next();
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int varfactor(void){
|
||||||
varfactor(void)
|
|
||||||
{
|
|
||||||
int r;
|
int r;
|
||||||
DEBUG_PRINTF("varfactor: obtaining %d from variable %d\n", variables[tokenizer_variable_num()], tokenizer_variable_num());
|
DEBUG_PRINTF("varfactor: obtaining %d from variable %d.\n", variables[tokenizer_variable_num()], tokenizer_variable_num());
|
||||||
r = ubasic_get_variable(tokenizer_variable_num());
|
r = ubasic_get_variable(tokenizer_variable_num());
|
||||||
accept(TOKENIZER_VARIABLE);
|
accept(TOKENIZER_VARIABLE);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int factor(void){
|
||||||
factor(void)
|
|
||||||
{
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
DEBUG_PRINTF("factor: token %d\n", tokenizer_token());
|
DEBUG_PRINTF("factor: token '%s'.\n", tokenizer_token_name(tokenizer_token()));
|
||||||
switch(tokenizer_token()) {
|
switch(tokenizer_token()) {
|
||||||
case TOKENIZER_NUMBER:
|
case TOKENIZER_NUMBER:
|
||||||
r = tokenizer_num();
|
r = tokenizer_num();
|
||||||
DEBUG_PRINTF("factor: number %d\n", r);
|
DEBUG_PRINTF("factor: number %d.\n", r);
|
||||||
accept(TOKENIZER_NUMBER);
|
accept(TOKENIZER_NUMBER);
|
||||||
break;
|
break;
|
||||||
case TOKENIZER_LEFTPAREN:
|
case TOKENIZER_LEFTPAREN:
|
||||||
|
|
@ -147,24 +140,23 @@ factor(void)
|
||||||
r = varfactor();
|
r = varfactor();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
DEBUG_PRINTF("term: %d.\n", r);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int term(void){
|
||||||
term(void)
|
|
||||||
{
|
|
||||||
int f1, f2;
|
int f1, f2;
|
||||||
int op;
|
int op;
|
||||||
|
|
||||||
f1 = factor();
|
f1 = factor();
|
||||||
op = tokenizer_token();
|
op = tokenizer_token();
|
||||||
DEBUG_PRINTF("term: token %d\n", op);
|
DEBUG_PRINTF("term: token '%s'.\n", tokenizer_token_name(op));
|
||||||
while(op == TOKENIZER_ASTR ||
|
while(op == TOKENIZER_ASTR ||
|
||||||
op == TOKENIZER_SLASH ||
|
op == TOKENIZER_SLASH ||
|
||||||
op == TOKENIZER_MOD) {
|
op == TOKENIZER_MOD) {
|
||||||
tokenizer_next();
|
tokenizer_next();
|
||||||
f2 = factor();
|
f2 = factor();
|
||||||
DEBUG_PRINTF("term: %d %d %d\n", f1, op, f2);
|
DEBUG_PRINTF("term: %d %d %d.\n", f1, op, f2);
|
||||||
switch(op) {
|
switch(op) {
|
||||||
case TOKENIZER_ASTR:
|
case TOKENIZER_ASTR:
|
||||||
f1 = f1 * f2;
|
f1 = f1 * f2;
|
||||||
|
|
@ -178,26 +170,25 @@ term(void)
|
||||||
}
|
}
|
||||||
op = tokenizer_token();
|
op = tokenizer_token();
|
||||||
}
|
}
|
||||||
DEBUG_PRINTF("term: %d\n", f1);
|
DEBUG_PRINTF("term: factor=%d.\n", f1);
|
||||||
return f1;
|
return f1;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static VARIABLE_TYPE
|
static VARIABLE_TYPE expr(void)
|
||||||
expr(void)
|
|
||||||
{
|
{
|
||||||
int t1, t2;
|
int t1, t2;
|
||||||
int op;
|
int op;
|
||||||
|
|
||||||
t1 = term();
|
t1 = term();
|
||||||
op = tokenizer_token();
|
op = tokenizer_token();
|
||||||
DEBUG_PRINTF("expr: token %d\n", op);
|
DEBUG_PRINTF("expr: token %s.\n", tokenizer_token_name(op));
|
||||||
while(op == TOKENIZER_PLUS ||
|
while(op == TOKENIZER_PLUS ||
|
||||||
op == TOKENIZER_MINUS ||
|
op == TOKENIZER_MINUS ||
|
||||||
op == TOKENIZER_AND ||
|
op == TOKENIZER_AND ||
|
||||||
op == TOKENIZER_OR) {
|
op == TOKENIZER_OR) {
|
||||||
tokenizer_next();
|
tokenizer_next();
|
||||||
t2 = term();
|
t2 = term();
|
||||||
DEBUG_PRINTF("expr: %d %d %d\n", t1, op, t2);
|
DEBUG_PRINTF("expr: %d %d %d.\n", t1, op, t2);
|
||||||
switch(op) {
|
switch(op) {
|
||||||
case TOKENIZER_PLUS:
|
case TOKENIZER_PLUS:
|
||||||
t1 = t1 + t2;
|
t1 = t1 + t2;
|
||||||
|
|
@ -214,25 +205,23 @@ expr(void)
|
||||||
}
|
}
|
||||||
op = tokenizer_token();
|
op = tokenizer_token();
|
||||||
}
|
}
|
||||||
DEBUG_PRINTF("expr: %d\n", t1);
|
DEBUG_PRINTF("expr: term=%d.\n", t1);
|
||||||
return t1;
|
return t1;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int
|
static int relation(void){
|
||||||
relation(void)
|
|
||||||
{
|
|
||||||
int r1, r2;
|
int r1, r2;
|
||||||
int op;
|
int op;
|
||||||
|
|
||||||
r1 = expr();
|
r1 = expr();
|
||||||
op = tokenizer_token();
|
op = tokenizer_token();
|
||||||
DEBUG_PRINTF("relation: token %d\n", op);
|
DEBUG_PRINTF("relation: token %d.\n", op);
|
||||||
while(op == TOKENIZER_LT ||
|
while(op == TOKENIZER_LT ||
|
||||||
op == TOKENIZER_GT ||
|
op == TOKENIZER_GT ||
|
||||||
op == TOKENIZER_EQ) {
|
op == TOKENIZER_EQ) {
|
||||||
tokenizer_next();
|
tokenizer_next();
|
||||||
r2 = expr();
|
r2 = expr();
|
||||||
DEBUG_PRINTF("relation: %d %d %d\n", r1, op, r2);
|
DEBUG_PRINTF("relation: %d %d %d.\n", r1, op, r2);
|
||||||
switch(op) {
|
switch(op) {
|
||||||
case TOKENIZER_LT:
|
case TOKENIZER_LT:
|
||||||
r1 = r1 < r2;
|
r1 = r1 < r2;
|
||||||
|
|
@ -246,15 +235,15 @@ relation(void)
|
||||||
}
|
}
|
||||||
op = tokenizer_token();
|
op = tokenizer_token();
|
||||||
}
|
}
|
||||||
|
DEBUG_PRINTF("relation: expr=%d.\n", r1);
|
||||||
return r1;
|
return r1;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void index_free(void) {
|
||||||
index_free(void) {
|
|
||||||
if(line_index_head != NULL) {
|
if(line_index_head != NULL) {
|
||||||
line_index_current = line_index_head;
|
line_index_current = line_index_head;
|
||||||
do {
|
do {
|
||||||
DEBUG_PRINTF("Freeing index for line %d.\n", line_index_current);
|
DEBUG_PRINTF("Freeing index for line %d.\n", line_index_current->line_number);
|
||||||
line_index_head = line_index_current;
|
line_index_head = line_index_current;
|
||||||
line_index_current = line_index_current->next;
|
line_index_current = line_index_current->next;
|
||||||
free(line_index_head);
|
free(line_index_head);
|
||||||
|
|
@ -263,8 +252,7 @@ index_free(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static char const*
|
static char const* index_find(int linenum) {
|
||||||
index_find(int linenum) {
|
|
||||||
struct line_index *lidx;
|
struct line_index *lidx;
|
||||||
lidx = line_index_head;
|
lidx = line_index_head;
|
||||||
|
|
||||||
|
|
@ -276,24 +264,30 @@ index_find(int linenum) {
|
||||||
lidx = lidx->next;
|
lidx = lidx->next;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
#if VERBOSE
|
||||||
if(lidx != NULL) {
|
if(lidx != NULL) {
|
||||||
DEBUG_PRINTF("index_find: Step %3d. Found index for line %d: %d.\n",
|
DEBUG_PRINTF("index_find: Step %3d. Found index for line %d: %p.\n",
|
||||||
step, lidx->line_number,
|
step,
|
||||||
lidx->program_text_position);
|
lidx->line_number,
|
||||||
|
lidx->program_text_position - tokenizer_start());
|
||||||
}
|
}
|
||||||
step++;
|
step++;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if(lidx != NULL && lidx->line_number == linenum) {
|
if(lidx != NULL && lidx->line_number == linenum) {
|
||||||
|
#if DEBUG
|
||||||
|
#if VERBOSE
|
||||||
DEBUG_PRINTF("index_find: Returning index for line %d.\n", linenum);
|
DEBUG_PRINTF("index_find: Returning index for line %d.\n", linenum);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
return lidx->program_text_position;
|
return lidx->program_text_position;
|
||||||
}
|
}
|
||||||
DEBUG_PRINTF("index_find: Returning NULL.\n", linenum);
|
DEBUG_PRINTF("index_find: Returning NULL.\n", linenum);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void index_add(int linenum, char const* sourcepos) {
|
||||||
index_add(int linenum, char const* sourcepos) {
|
|
||||||
if(line_index_head != NULL && index_find(linenum)) {
|
if(line_index_head != NULL && index_find(linenum)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -312,30 +306,32 @@ index_add(int linenum, char const* sourcepos) {
|
||||||
line_index_current = new_lidx;
|
line_index_current = new_lidx;
|
||||||
line_index_head = line_index_current;
|
line_index_head = line_index_current;
|
||||||
}
|
}
|
||||||
DEBUG_PRINTF("index_add: Adding index for line %d: %d.\n", linenum,
|
//DEBUG_PRINTF("index_add: Adding index for line %d: %p.\n", linenum,
|
||||||
sourcepos);
|
// sourcepos - tokenizer_start());
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void jump_linenum_slow(int linenum)
|
||||||
jump_linenum_slow(int linenum)
|
|
||||||
{
|
{
|
||||||
tokenizer_init(program_ptr);
|
tokenizer_init(program_ptr);
|
||||||
while(tokenizer_num() != linenum) {
|
while(tokenizer_num() != linenum) {
|
||||||
do {
|
do {
|
||||||
do {
|
do {
|
||||||
tokenizer_next();
|
tokenizer_next();
|
||||||
} while(tokenizer_token() != TOKENIZER_CR &&
|
} while(tokenizer_token() != TOKENIZER_LF &&
|
||||||
tokenizer_token() != TOKENIZER_ENDOFINPUT);
|
tokenizer_token() != TOKENIZER_ENDOFINPUT);
|
||||||
if(tokenizer_token() == TOKENIZER_CR) {
|
if(tokenizer_token() == TOKENIZER_LF) {
|
||||||
tokenizer_next();
|
tokenizer_next();
|
||||||
}
|
}
|
||||||
} while(tokenizer_token() != TOKENIZER_NUMBER);
|
} while(tokenizer_token() != TOKENIZER_NUMBER);
|
||||||
DEBUG_PRINTF("jump_linenum_slow: Found line %d\n", tokenizer_num());
|
#if DEBUG
|
||||||
|
#if VERBOSE
|
||||||
|
DEBUG_PRINTF("jump_linenum_slow: Found line %d.\n", tokenizer_num());
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void jump_linenum(int linenum)
|
||||||
jump_linenum(int linenum)
|
|
||||||
{
|
{
|
||||||
char const* pos = index_find(linenum);
|
char const* pos = index_find(linenum);
|
||||||
if(pos != NULL) {
|
if(pos != NULL) {
|
||||||
|
|
@ -343,24 +339,22 @@ jump_linenum(int linenum)
|
||||||
tokenizer_goto(pos);
|
tokenizer_goto(pos);
|
||||||
} else {
|
} else {
|
||||||
/* We'll try to find a yet-unindexed line to jump to. */
|
/* We'll try to find a yet-unindexed line to jump to. */
|
||||||
DEBUG_PRINTF("jump_linenum: Calling jump_linenum_slow.\n", linenum);
|
DEBUG_PRINTF("jump_linenum: Calling jump_linenum_slow for line %d.\n", linenum);
|
||||||
jump_linenum_slow(linenum);
|
jump_linenum_slow(linenum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void goto_statement(void)
|
||||||
goto_statement(void)
|
|
||||||
{
|
{
|
||||||
accept(TOKENIZER_GOTO);
|
accept(TOKENIZER_GOTO);
|
||||||
jump_linenum(tokenizer_num());
|
jump_linenum(tokenizer_num());
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void print_statement(void)
|
||||||
print_statement(void)
|
|
||||||
{
|
{
|
||||||
accept(TOKENIZER_PRINT);
|
accept(TOKENIZER_PRINT);
|
||||||
|
DEBUG_PRINTF("print_statement: Loop.\n");
|
||||||
do {
|
do {
|
||||||
DEBUG_PRINTF("Print loop\n");
|
|
||||||
if(tokenizer_token() == TOKENIZER_STRING) {
|
if(tokenizer_token() == TOKENIZER_STRING) {
|
||||||
tokenizer_string(string, sizeof(string));
|
tokenizer_string(string, sizeof(string));
|
||||||
printf("%s", string);
|
printf("%s", string);
|
||||||
|
|
@ -373,25 +367,24 @@ print_statement(void)
|
||||||
} else if(tokenizer_token() == TOKENIZER_VARIABLE ||
|
} else if(tokenizer_token() == TOKENIZER_VARIABLE ||
|
||||||
tokenizer_token() == TOKENIZER_NUMBER) {
|
tokenizer_token() == TOKENIZER_NUMBER) {
|
||||||
printf("%d", expr());
|
printf("%d", expr());
|
||||||
|
} else if (tokenizer_token() == TOKENIZER_CR){
|
||||||
|
tokenizer_next();
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while(tokenizer_token() != TOKENIZER_CR &&
|
} while(tokenizer_token() != TOKENIZER_LF &&
|
||||||
tokenizer_token() != TOKENIZER_ENDOFINPUT);
|
tokenizer_token() != TOKENIZER_ENDOFINPUT);
|
||||||
printf("\n");
|
DEBUG_PRINTF("print_statement: End of print.\n");
|
||||||
DEBUG_PRINTF("End of print\n");
|
|
||||||
tokenizer_next();
|
tokenizer_next();
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void if_statement(void){
|
||||||
if_statement(void)
|
|
||||||
{
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
accept(TOKENIZER_IF);
|
accept(TOKENIZER_IF);
|
||||||
|
|
||||||
r = relation();
|
r = relation();
|
||||||
DEBUG_PRINTF("if_statement: relation %d\n", r);
|
DEBUG_PRINTF("if_statement: relation %d.\n", r);
|
||||||
accept(TOKENIZER_THEN);
|
accept(TOKENIZER_THEN);
|
||||||
if(r) {
|
if(r) {
|
||||||
statement();
|
statement();
|
||||||
|
|
@ -399,20 +392,18 @@ if_statement(void)
|
||||||
do {
|
do {
|
||||||
tokenizer_next();
|
tokenizer_next();
|
||||||
} while(tokenizer_token() != TOKENIZER_ELSE &&
|
} while(tokenizer_token() != TOKENIZER_ELSE &&
|
||||||
tokenizer_token() != TOKENIZER_CR &&
|
tokenizer_token() != TOKENIZER_LF &&
|
||||||
tokenizer_token() != TOKENIZER_ENDOFINPUT);
|
tokenizer_token() != TOKENIZER_ENDOFINPUT);
|
||||||
if(tokenizer_token() == TOKENIZER_ELSE) {
|
if(tokenizer_token() == TOKENIZER_ELSE) {
|
||||||
tokenizer_next();
|
tokenizer_next();
|
||||||
statement();
|
statement();
|
||||||
} else if(tokenizer_token() == TOKENIZER_CR) {
|
} else if(tokenizer_token() == TOKENIZER_LF) {
|
||||||
tokenizer_next();
|
tokenizer_next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void let_statement(void){
|
||||||
let_statement(void)
|
|
||||||
{
|
|
||||||
int var;
|
int var;
|
||||||
|
|
||||||
var = tokenizer_variable_num();
|
var = tokenizer_variable_num();
|
||||||
|
|
@ -420,43 +411,37 @@ let_statement(void)
|
||||||
accept(TOKENIZER_VARIABLE);
|
accept(TOKENIZER_VARIABLE);
|
||||||
accept(TOKENIZER_EQ);
|
accept(TOKENIZER_EQ);
|
||||||
ubasic_set_variable(var, expr());
|
ubasic_set_variable(var, expr());
|
||||||
DEBUG_PRINTF("let_statement: assign %d to %d\n", variables[var], var);
|
DEBUG_PRINTF("let_statement: assign %d to %d.\n", variables[var], var);
|
||||||
accept(TOKENIZER_CR);
|
accept(TOKENIZER_LF);
|
||||||
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void gosub_statement(void){
|
||||||
gosub_statement(void)
|
|
||||||
{
|
|
||||||
int linenum;
|
int linenum;
|
||||||
accept(TOKENIZER_GOSUB);
|
accept(TOKENIZER_GOSUB);
|
||||||
linenum = tokenizer_num();
|
linenum = tokenizer_num();
|
||||||
accept(TOKENIZER_NUMBER);
|
accept(TOKENIZER_NUMBER);
|
||||||
accept(TOKENIZER_CR);
|
accept(TOKENIZER_LF);
|
||||||
if(gosub_stack_ptr < MAX_GOSUB_STACK_DEPTH) {
|
if(gosub_stack_ptr < MAX_GOSUB_STACK_DEPTH) {
|
||||||
gosub_stack[gosub_stack_ptr] = tokenizer_num();
|
gosub_stack[gosub_stack_ptr] = tokenizer_num();
|
||||||
gosub_stack_ptr++;
|
gosub_stack_ptr++;
|
||||||
jump_linenum(linenum);
|
jump_linenum(linenum);
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTF("gosub_statement: gosub stack exhausted\n");
|
DEBUG_PRINTF("gosub_statement: gosub stack exhausted.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void return_statement(void){
|
||||||
return_statement(void)
|
|
||||||
{
|
|
||||||
accept(TOKENIZER_RETURN);
|
accept(TOKENIZER_RETURN);
|
||||||
if(gosub_stack_ptr > 0) {
|
if(gosub_stack_ptr > 0) {
|
||||||
gosub_stack_ptr--;
|
gosub_stack_ptr--;
|
||||||
jump_linenum(gosub_stack[gosub_stack_ptr]);
|
jump_linenum(gosub_stack[gosub_stack_ptr]);
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTF("return_statement: non-matching return\n");
|
DEBUG_PRINTF("return_statement: non-matching return.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void next_statement(void){
|
||||||
next_statement(void)
|
|
||||||
{
|
|
||||||
int var;
|
int var;
|
||||||
|
|
||||||
accept(TOKENIZER_NEXT);
|
accept(TOKENIZER_NEXT);
|
||||||
|
|
@ -470,18 +455,16 @@ next_statement(void)
|
||||||
jump_linenum(for_stack[for_stack_ptr - 1].line_after_for);
|
jump_linenum(for_stack[for_stack_ptr - 1].line_after_for);
|
||||||
} else {
|
} else {
|
||||||
for_stack_ptr--;
|
for_stack_ptr--;
|
||||||
accept(TOKENIZER_CR);
|
accept(TOKENIZER_LF);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTF("next_statement: non-matching next (expected %d, found %d)\n", for_stack[for_stack_ptr - 1].for_variable, var);
|
DEBUG_PRINTF("next_statement: non-matching next (expected %d, found %d).\n", for_stack[for_stack_ptr - 1].for_variable, var);
|
||||||
accept(TOKENIZER_CR);
|
accept(TOKENIZER_LF);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void for_statement(void) {
|
||||||
for_statement(void)
|
|
||||||
{
|
|
||||||
int for_variable, to;
|
int for_variable, to;
|
||||||
|
|
||||||
accept(TOKENIZER_FOR);
|
accept(TOKENIZER_FOR);
|
||||||
|
|
@ -491,25 +474,23 @@ for_statement(void)
|
||||||
ubasic_set_variable(for_variable, expr());
|
ubasic_set_variable(for_variable, expr());
|
||||||
accept(TOKENIZER_TO);
|
accept(TOKENIZER_TO);
|
||||||
to = expr();
|
to = expr();
|
||||||
accept(TOKENIZER_CR);
|
accept(TOKENIZER_LF);
|
||||||
|
|
||||||
if(for_stack_ptr < MAX_FOR_STACK_DEPTH) {
|
if(for_stack_ptr < MAX_FOR_STACK_DEPTH) {
|
||||||
for_stack[for_stack_ptr].line_after_for = tokenizer_num();
|
for_stack[for_stack_ptr].line_after_for = tokenizer_num();
|
||||||
for_stack[for_stack_ptr].for_variable = for_variable;
|
for_stack[for_stack_ptr].for_variable = for_variable;
|
||||||
for_stack[for_stack_ptr].to = to;
|
for_stack[for_stack_ptr].to = to;
|
||||||
DEBUG_PRINTF("for_statement: new for, var %d to %d\n",
|
DEBUG_PRINTF("for_statement: new for, var %d to %d.\n",
|
||||||
for_stack[for_stack_ptr].for_variable,
|
for_stack[for_stack_ptr].for_variable,
|
||||||
for_stack[for_stack_ptr].to);
|
for_stack[for_stack_ptr].to);
|
||||||
|
|
||||||
for_stack_ptr++;
|
for_stack_ptr++;
|
||||||
} else {
|
} else {
|
||||||
DEBUG_PRINTF("for_statement: for stack depth exceeded\n");
|
DEBUG_PRINTF("for_statement: for stack depth exceeded.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void peek_statement(void){
|
||||||
peek_statement(void)
|
|
||||||
{
|
|
||||||
VARIABLE_TYPE peek_addr;
|
VARIABLE_TYPE peek_addr;
|
||||||
int var;
|
int var;
|
||||||
|
|
||||||
|
|
@ -518,13 +499,12 @@ peek_statement(void)
|
||||||
accept(TOKENIZER_COMMA);
|
accept(TOKENIZER_COMMA);
|
||||||
var = tokenizer_variable_num();
|
var = tokenizer_variable_num();
|
||||||
accept(TOKENIZER_VARIABLE);
|
accept(TOKENIZER_VARIABLE);
|
||||||
accept(TOKENIZER_CR);
|
accept(TOKENIZER_LF);
|
||||||
|
|
||||||
ubasic_set_variable(var, peek_function(peek_addr));
|
ubasic_set_variable(var, peek_function(peek_addr));
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void poke_statement(void)
|
||||||
poke_statement(void)
|
|
||||||
{
|
{
|
||||||
VARIABLE_TYPE poke_addr;
|
VARIABLE_TYPE poke_addr;
|
||||||
VARIABLE_TYPE value;
|
VARIABLE_TYPE value;
|
||||||
|
|
@ -533,21 +513,18 @@ poke_statement(void)
|
||||||
poke_addr = expr();
|
poke_addr = expr();
|
||||||
accept(TOKENIZER_COMMA);
|
accept(TOKENIZER_COMMA);
|
||||||
value = expr();
|
value = expr();
|
||||||
accept(TOKENIZER_CR);
|
accept(TOKENIZER_LF);
|
||||||
|
|
||||||
poke_function(poke_addr, value);
|
poke_function(poke_addr, value);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void end_statement(void)
|
||||||
end_statement(void)
|
|
||||||
{
|
{
|
||||||
accept(TOKENIZER_END);
|
accept(TOKENIZER_END);
|
||||||
ended = 1;
|
ended = 1;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void statement(void){
|
||||||
statement(void)
|
|
||||||
{
|
|
||||||
int token;
|
int token;
|
||||||
|
|
||||||
token = tokenizer_token();
|
token = tokenizer_token();
|
||||||
|
|
@ -590,14 +567,12 @@ statement(void)
|
||||||
let_statement();
|
let_statement();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
DEBUG_PRINTF("ubasic.c: statement(): not implemented %d\n", token);
|
DEBUG_PRINTF("statement: not implemented %d.\n", token);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void line_statement(void){
|
||||||
line_statement(void)
|
|
||||||
{
|
|
||||||
DEBUG_PRINTF("----------- Line number %d ---------\n", tokenizer_num());
|
DEBUG_PRINTF("----------- Line number %d ---------\n", tokenizer_num());
|
||||||
index_add(tokenizer_num(), tokenizer_pos());
|
index_add(tokenizer_num(), tokenizer_pos());
|
||||||
accept(TOKENIZER_NUMBER);
|
accept(TOKENIZER_NUMBER);
|
||||||
|
|
@ -605,11 +580,9 @@ line_statement(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void ubasic_run(void){
|
||||||
ubasic_run(void)
|
|
||||||
{
|
|
||||||
if(tokenizer_finished()) {
|
if(tokenizer_finished()) {
|
||||||
DEBUG_PRINTF("uBASIC program finished\n");
|
DEBUG_PRINTF("ubasic_run: Program finished.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -617,22 +590,17 @@ ubasic_run(void)
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int
|
int
|
||||||
ubasic_finished(void)
|
ubasic_finished(void){
|
||||||
{
|
|
||||||
return ended || tokenizer_finished();
|
return ended || tokenizer_finished();
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void ubasic_set_variable(int varnum, VARIABLE_TYPE value){
|
||||||
ubasic_set_variable(int varnum, VARIABLE_TYPE value)
|
|
||||||
{
|
|
||||||
if(varnum >= 0 && varnum <= MAX_VARNUM) {
|
if(varnum >= 0 && varnum <= MAX_VARNUM) {
|
||||||
variables[varnum] = value;
|
variables[varnum] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
VARIABLE_TYPE
|
VARIABLE_TYPE ubasic_get_variable(int varnum){
|
||||||
ubasic_get_variable(int varnum)
|
|
||||||
{
|
|
||||||
if(varnum >= 0 && varnum <= MAX_VARNUM) {
|
if(varnum >= 0 && varnum <= MAX_VARNUM) {
|
||||||
return variables[varnum];
|
return variables[varnum];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue