YREA-SLS/SLS_C/include/sls/lexer.h

100 lines
1.9 KiB
C

// Kyler Olsen
// YREA SLS
// Lexer Header
// October 2025
#ifndef SLS_LEXER_H
#define SLS_LEXER_H
#include <stdint.h>
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 enum {
INTEGER_I64,
INTEGER_I32,
INTEGER_I16,
INTEGER_I8,
INTEGER_U64,
INTEGER_U32,
INTEGER_U16,
INTEGER_U8,
} IntegerBuiltInType;
typedef struct {
const char *name;
size_t length;
uint8_t is_literal;
} Identifier;
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 TokenStream {
Token token;
struct TokenStream *next;
} TokenStream;
#endif // SLS_LEXER_H