I think i'm done, lexer works fine and errors work fine too, amazing actually, should be moving on to the parser so that i can construct the expression tree

This commit is contained in:
2026-03-10 07:27:35 -06:00
parent 73451fcca9
commit 903fdbd6ff
2 changed files with 39 additions and 2 deletions

View File

@@ -120,7 +120,11 @@ LexerErr tokenize(const char *input, ASTNodeArray *out) {
while (input[offset] != '\n' && input[offset] != '\0') {
int current = input[offset];
if (isdigit(current) && state == WAIT_FOR_NUMBER) {
if (isdigit(current)) {
if (state != WAIT_FOR_NUMBER) {
ASTNodeArray_free(&arr);
return LEXER_WRONG_SYNTAX;
}
ASTNode new_node;
LexerErr result = tokenize_number(input, &offset, &new_node);
@@ -131,7 +135,10 @@ LexerErr tokenize(const char *input, ASTNodeArray *out) {
ASTNodeArray_push(&arr, new_node);
state = WAIT_FOR_OPERATOR;
} else if (isoperator(current) && state == WAIT_FOR_OPERATOR) {
} else if (isoperator(current)) {
if (state != WAIT_FOR_OPERATOR) {
return LEXER_WRONG_SYNTAX;
}
ASTNode new_node = {
.type = NODE_BINARY_OP,
.data.binary.op = current,