Work in progress

This commit is contained in:
2017-01-30 19:37:11 +01:00
parent 415688d5c5
commit 3eba81d2bd
13 changed files with 237 additions and 50 deletions

View File

@@ -1,4 +1,5 @@
#include "tokenizer.h"
#include "error.h"
static bool streq(const char* a, const char* b) {
while (*a != 0 && *b != 0) {
@@ -42,6 +43,7 @@ t_token_op tkn_tokens[] = {
{ "not", TOKEN_NOT },
{ "mod", TOKEN_MOD },
{ "dim", TOKEN_DIM },
{ "const", TOKEN_CONST },
{ "inc", TOKEN_INC },
{ "dec", TOKEN_DEC },
{ "strleft", TOKEN_STRLEFT },
@@ -60,8 +62,12 @@ t_token_op tkn_tokens[] = {
{ "updatescr", TOKEN_UPDATESCR },
{ "color", TOKEN_COLOR },
{ "border", TOKEN_BORDER },
{ "clrscr", TOKEN_CLRSCR },
{ "wait", TOKEN_WAIT },
};
static char hex_digit(const char digit) { return digit - (digit < 57 ? 48 : 55); }
#define CCHR *ptr
#define NEXT if(*ptr==10){line++;row=0;}else{row++;};ptr++
@@ -80,7 +86,7 @@ static void tkn_do_next() {
if (CCHR == 34) {
NEXT;
while (CCHR != 0 && CCHR != 34) { *id = CCHR; id++; NEXT; }
if (CCHR == 0) { current_token = TOKEN_ERROR; return; }
if (CCHR == 0) { current_token = TOKEN_ERROR; error_raise("Unexpected end of file."); return; }
*id = 0; NEXT;
current_token = TOKEN_STRING; return;
}
@@ -122,6 +128,27 @@ static void tkn_do_next() {
if (CCHR == '%') { NEXT; current_token = TOKEN_MOD; return; }
if (CCHR == 39) { NEXT; current_token = TOKEN_REM; while (CCHR != 0 && CCHR != 10) { NEXT; }; return; }
if (CCHR == '&') {
NEXT;
if ((CCHR | 32) == 'h') {
NEXT;
if ((CCHR >= 48 && CCHR <= 57) || (CCHR >= 65 && CCHR <= 70)) {
do { value = (value << 4) + hex_digit(CCHR); NEXT; } while ((CCHR >= 48 && CCHR <= 57) || (CCHR >= 65 && CCHR <= 70));
current_token = TOKEN_NUMBER; return;
}
}
if ((CCHR | 32) == 'b') {
NEXT;
if (CCHR == 48 || CCHR == 49) {
do { value = (value << 1) + (CCHR-48); NEXT; } while (CCHR == 48 || CCHR == 49);
current_token = TOKEN_NUMBER; return;
}
}
current_token = TOKEN_ERROR;
error_raise("Syntax error");
return;
}
// if no match, it's an error
current_token = TOKEN_ERROR; return;
}