127 lines
2.4 KiB
C
127 lines
2.4 KiB
C
// Kyler Olsen
|
|
// YREA SLS
|
|
// Lexer Header
|
|
// October 2025
|
|
|
|
#ifndef SLS_LEXER_H
|
|
#define SLS_LEXER_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 {
|
|
TOKEN_EOF,
|
|
TOKEN_IDENTIFIER,
|
|
TOKEN_INTEGER,
|
|
TOKEN_FLOAT,
|
|
TOKEN_DOUBLE,
|
|
TOKEN_STRING,
|
|
TOKEN_BOOLEAN,
|
|
TOKEN_ARRAY,
|
|
TOKEN_TOKEN_STRING,
|
|
TOKEN_TYPE_TUPLE,
|
|
} TokenType;
|
|
|
|
typedef struct {
|
|
const char *name;
|
|
size_t length;
|
|
uint8_t is_literal;
|
|
} Identifier;
|
|
|
|
typedef enum {
|
|
INTEGER_I64,
|
|
INTEGER_I32,
|
|
INTEGER_I16,
|
|
INTEGER_I8,
|
|
INTEGER_U64,
|
|
INTEGER_U32,
|
|
INTEGER_U16,
|
|
INTEGER_U8,
|
|
} IntegerBuiltInType;
|
|
|
|
typedef struct {
|
|
uint64_t value;
|
|
IntegerBuiltInType type;
|
|
} IntegerLiteral;
|
|
|
|
typedef struct {
|
|
const char *value;
|
|
size_t length;
|
|
} StringLiteral;
|
|
|
|
typedef struct {
|
|
TokenType type;
|
|
union {
|
|
Identifier *identifiers;
|
|
IntegerLiteral *integer_literals;
|
|
float *float_literals;
|
|
double *double_literals;
|
|
StringLiteral *string_literals;
|
|
uint8_t *boolean_literals;
|
|
ArrayLiteral *array_literals;
|
|
TokenString *token_strings;
|
|
TypeTuple *type_tuples;
|
|
};
|
|
size_t length;
|
|
} ArrayLiteral;
|
|
|
|
typedef struct {
|
|
const Token *tokens;
|
|
size_t length;
|
|
} TokenString;
|
|
|
|
typedef struct {
|
|
Identifier *input_identifiers;
|
|
size_t input_length;
|
|
Identifier *output_identifiers;
|
|
size_t output_length;
|
|
} TypeTuple;
|
|
|
|
typedef struct {
|
|
TokenType type;
|
|
union {
|
|
Identifier identifier;
|
|
IntegerLiteral integer_literal;
|
|
float float_literal;
|
|
double double_literal;
|
|
StringLiteral string_literal;
|
|
uint8_t boolean_literal;
|
|
ArrayLiteral array_literal;
|
|
TokenString token_string;
|
|
TypeTuple type_tuple;
|
|
};
|
|
} Token;
|
|
|
|
typedef struct LexerTokenResult {
|
|
SlsResultType type;
|
|
union {
|
|
Token result;
|
|
SlsError error;
|
|
};
|
|
FileInfo file_info;
|
|
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
|