Files
fz-lang/include/compiler/fzl_token.h
T
2026-10-15 02:23:43 +03:00

72 lines
1.4 KiB
C

#ifndef FZL_TOKEN_H
#define FZL_TOKEN_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
// Token type
typedef enum
{
FZL_TOKTYPE_RETURN, // return
FZL_TOKTYPE_IF, // if
FZL_TOKTYPE_ELSE, // else
FZL_TOKTYPE_NAME, // abc
FZL_TOKTYPE_TYPE, // i16
FZL_TOKTYPE_LPAREN, // (
FZL_TOKTYPE_RPAREN, // )
FZL_TOKTYPE_LBRACE, // {
FZL_TOKTYPE_RBRACE, // }
FZL_TOKTYPE_COMMA, // ,
FZL_TOKTYPE_DOT, // .
FZL_TOKTYPE_SEMICOLON, // ;
FZL_TOKTYPE_STR_LITERAL, // ""
FZL_TOKTYPE_NUM_LITERAL, // 123
FZL_TOKTYPE_BOOL_LITERAL, // true
FZL_TOKTYPE_DAMPERSAND, // &&
FZL_TOKTYPE_DVBAR, // ||
FZL_TOKTYPE_EQEQ, // ==
FZL_TOKTYPE_REQ, // >=
FZL_TOKTYPE_LEQ, // <=
FZL_TOKTYPE_NEQ, // !=
FZL_TOKTYPE_LANGLE, // <
FZL_TOKTYPE_RANGLE, // >
FZL_TOKTYPE_NOT, // !
FZL_TOKTYPE_STAR, // *
FZL_TOKTYPE_SLASH, // /
FZL_TOKTYPE_PLUS, // +
FZL_TOKTYPE_MINUS, // -
FZL_TOKTYPE_CARET, // ^
FZL_TOKTYPE_PERCENT, // %
FZL_TOKTYPE_EQ // =
} fzl_toktype_t;
// Token descriptor
typedef struct
{
fzl_toktype_t type;
size_t ln;
size_t cn;
bool store_value;
void *value;
uint16_t value_sz;
} fzl_token_t;
// Allocate new token
fzl_token_t *fzl_mktoken(const fzl_toktype_t type, size_t line, size_t col,
void *value, size_t value_sz);
// Free token and its contents
void fzl_freetoken(fzl_token_t *token);
#endif // FZL_TOKEN_H