|
@@ -8,6 +8,8 @@
|
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
+#include "Constants.h"
|
|
|
|
|
+
|
|
|
typedef struct {
|
|
typedef struct {
|
|
|
int line;
|
|
int line;
|
|
|
FILE* file;
|
|
FILE* file;
|
|
@@ -58,7 +60,7 @@ static bool isTokenEnd(char c) {
|
|
|
|
|
|
|
|
static const char* tokenizerAddLiteral(TState* t, const char* s) {
|
|
static const char* tokenizerAddLiteral(TState* t, const char* s) {
|
|
|
size_t index = 0;
|
|
size_t index = 0;
|
|
|
- char buffer[256] = {};
|
|
|
|
|
|
|
+ char buffer[MAX_LITERAL_LENGTH] = {};
|
|
|
buffer[index++] = *s;
|
|
buffer[index++] = *s;
|
|
|
while(true) {
|
|
while(true) {
|
|
|
char c = *(++s);
|
|
char c = *(++s);
|
|
@@ -67,7 +69,7 @@ static const char* tokenizerAddLiteral(TState* t, const char* s) {
|
|
|
} else if(!isAlphaNumeric(c)) {
|
|
} else if(!isAlphaNumeric(c)) {
|
|
|
tInvalidToken(t, c);
|
|
tInvalidToken(t, c);
|
|
|
} else if(index >= sizeof(buffer) - 1) {
|
|
} else if(index >= sizeof(buffer) - 1) {
|
|
|
- tTooMuchTokens(t);
|
|
|
|
|
|
|
+ THROW_ERROR("Too long literal");
|
|
|
}
|
|
}
|
|
|
buffer[index++] = c;
|
|
buffer[index++] = c;
|
|
|
}
|
|
}
|
|
@@ -117,7 +119,7 @@ static const char* tokenizerAddNumber(TState* t, const char* s) {
|
|
|
static const char* tokenizerAddString(TState* t, const char* s) {
|
|
static const char* tokenizerAddString(TState* t, const char* s) {
|
|
|
tAddToken(t, STRING);
|
|
tAddToken(t, STRING);
|
|
|
size_t index = 0;
|
|
size_t index = 0;
|
|
|
- char buffer[256] = {};
|
|
|
|
|
|
|
+ char buffer[MAX_STRING_LENGTH] = {};
|
|
|
while(true) {
|
|
while(true) {
|
|
|
char c = *(++s);
|
|
char c = *(++s);
|
|
|
if(c == '\0') {
|
|
if(c == '\0') {
|
|
@@ -126,7 +128,7 @@ static const char* tokenizerAddString(TState* t, const char* s) {
|
|
|
s++;
|
|
s++;
|
|
|
break;
|
|
break;
|
|
|
} else if(index >= sizeof(buffer) - 1) {
|
|
} else if(index >= sizeof(buffer) - 1) {
|
|
|
- tTooMuchTokens(t);
|
|
|
|
|
|
|
+ THROW_ERROR("Too long string");
|
|
|
}
|
|
}
|
|
|
buffer[index++] = c;
|
|
buffer[index++] = c;
|
|
|
}
|
|
}
|
|
@@ -164,7 +166,7 @@ static void tParseLineString(TState* t, const char* s) {
|
|
|
static void tParseLines(TState* t) {
|
|
static void tParseLines(TState* t) {
|
|
|
while(true) {
|
|
while(true) {
|
|
|
t->line++;
|
|
t->line++;
|
|
|
- char line[256] = {};
|
|
|
|
|
|
|
+ char line[MAX_LINE_LENGTH] = {};
|
|
|
if(fgets(line, sizeof(line), t->file) == nullptr) {
|
|
if(fgets(line, sizeof(line), t->file) == nullptr) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|