Add lexer and error handling structures for improved token processing

This commit is contained in:
Kyler Olsen 2025-10-28 22:00:19 -06:00
parent bd80b899df
commit 29f047404e
2 changed files with 49 additions and 4 deletions

View File

@ -8,6 +8,16 @@
#include <stdint.h> #include <stdint.h>
#include "sls_errors.h"
typedef struct {
const char *filename;
const char *source_code;
size_t pos;
size_t column;
size_t line;
} LexerInfo;
typedef enum { typedef enum {
TOKEN_EOF, TOKEN_EOF,
TOKEN_IDENTIFIER, TOKEN_IDENTIFIER,
@ -91,9 +101,25 @@ typedef struct {
}; };
} Token; } Token;
typedef struct TokenStream { typedef struct LexerTokenResult {
Token token; SlsResultType type;
struct TokenStream *next; union {
} TokenStream; Token result;
SlsError error;
};
struct LexerTokenResult *next;
} LexerTokenResult;
typedef struct {
SlsResultType type;
union {
LexerTokenResult *result;
SlsError error;
};
} LexerResult;
void init_lexer(LexerInfo *lexer_info, const char *filename, const char *source_code);
LexerResult lexical_analysis(LexerInfo *lexer_info);
void clean_token_result(LexerTokenResult* head);
#endif // SLS_LEXER_H #endif // SLS_LEXER_H

View File

@ -0,0 +1,19 @@
// Kyler Olsen
// YREA SLS
// SLS Error Header
// October 2025
#ifndef SLS_ERROR_H
#define SLS_ERROR_H
typedef struct {
const char *message;
int code;
} SlsError;
typedef enum {
SLS_ERROR,
SLS_RESULT,
} SlsResultType;
#endif // SLS_ERROR_H