Implemented comments with REM.

This commit is contained in:
Danyil Bohdan 2013-12-22 14:23:14 +02:00
parent ea7a52e61f
commit 9c45ed4588
3 changed files with 19 additions and 4 deletions

View file

@ -34,6 +34,10 @@
#include <assert.h> #include <assert.h>
#include "ubasic.h" #include "ubasic.h"
static const char program_let[] =
"10 let a = 42\n\
20 end\n";
static const char program_loop[] = static const char program_loop[] =
"10 for i = 0 to 126\n\ "10 for i = 0 to 126\n\
20 for j = 0 to 126\n\ 20 for j = 0 to 126\n\
@ -44,16 +48,13 @@ static const char program_loop[] =
70 next i\n\ 70 next i\n\
80 end\n"; 80 end\n";
static const char program_let[] =
"10 let a = 42\n\
20 end\n";
static const char program_fibs[] = static const char program_fibs[] =
"20 let a = 1\n\ "20 let a = 1\n\
40 let b = 1\n\ 40 let b = 1\n\
60 for i = 0 to 8\n\ 60 for i = 0 to 8\n\
80 let b = a + b\n\ 80 let b = a + b\n\
100 let a = b - a\n\ 100 let a = b - a\n\
rem 120 print a, b\n\
140 next i\n\ 140 next i\n\
160 end\n"; 160 end\n";

View file

@ -65,6 +65,7 @@ static const struct keyword_token keywords[] = {
{"gosub", TOKENIZER_GOSUB}, {"gosub", TOKENIZER_GOSUB},
{"return", TOKENIZER_RETURN}, {"return", TOKENIZER_RETURN},
{"call", TOKENIZER_CALL}, {"call", TOKENIZER_CALL},
{"rem", TOKENIZER_REM},
{"end", TOKENIZER_END}, {"end", TOKENIZER_END},
{NULL, TOKENIZER_ERROR} {NULL, TOKENIZER_ERROR}
}; };
@ -188,10 +189,22 @@ tokenizer_next(void)
DEBUG_PRINTF("tokenizer_next: %p\n", nextptr); DEBUG_PRINTF("tokenizer_next: %p\n", nextptr);
ptr = nextptr; ptr = nextptr;
while(*ptr == ' ') { while(*ptr == ' ') {
++ptr; ++ptr;
} }
current_token = get_next_token(); current_token = get_next_token();
if (current_token == TOKENIZER_REM) {
while(!(*nextptr == '\n' || tokenizer_finished())) {
++nextptr;
}
if (*nextptr == '\n') {
++nextptr;
}
tokenizer_next();
}
DEBUG_PRINTF("tokenizer_next: '%s' %d\n", ptr, current_token); DEBUG_PRINTF("tokenizer_next: '%s' %d\n", ptr, current_token);
return; return;
} }

View file

@ -50,6 +50,7 @@ enum {
TOKENIZER_GOSUB, TOKENIZER_GOSUB,
TOKENIZER_RETURN, TOKENIZER_RETURN,
TOKENIZER_CALL, TOKENIZER_CALL,
TOKENIZER_REM,
TOKENIZER_END, TOKENIZER_END,
TOKENIZER_COMMA, TOKENIZER_COMMA,
TOKENIZER_SEMICOLON, TOKENIZER_SEMICOLON,