/* * Declarations for the tokenizer in the bootstrap compiler. * * Copyright © 2025 Samuel Lidén Borell * * SPDX-License-Identifier: EUPL-1.2+ */ #ifndef SLUL_TOKEN_H #define SLUL_TOKEN_H #include enum Token { T_EOL, /**< End of line */ /* Expressions */ T_UpperIdent, T_LowerIdent, T_Integer, T_String, T_SYM_Dot, T_SYM_LArrow, T_SYM_RArrow, T_SYM_SingleEqual, T_SYM_DoubleEqual, T_SYM_NotEqual, T_SYM_Less, T_SYM_Greater, T_SYM_LessEqual, T_SYM_GreaterEqual, T_SYM_Plus, T_SYM_Minus, T_SYM_Asterisk, T_SYM_Slash, T_SYM_LParen, T_SYM_RParen, T_SYM_LBracket, T_SYM_RBracket, /* Common stuff */ T_KW_end, /* Toplevels */ T_KW_class, T_KW_enum, T_KW_func, T_KW_record, T_KW_templates, T_KW_trait, /* Builtin types */ T_KW_bool, T_KW_byte, T_KW_int, T_KW_long, /* Qualifiers */ T_KW_var, T_KW_aliased, T_KW_volatile, T_KW_wrapping, T_KW_signed, T_KW_unsigned, /* Generics */ T_KW_of, T_KW_to, T_KW_from, /* Function sections */ T_KW_calledfrom, T_KW_code, T_KW_export, T_KW_io, T_KW_local, T_KW_modifies, T_KW_reads, T_KW_returns, T_KW_section, T_KW_sets, /* Statements */ T_KW_assert, T_KW_break, T_KW_case, T_KW_continue, T_KW_default, T_KW_elif, T_KW_else, T_KW_for, T_KW_if, T_KW_in, T_KW_loopend, T_KW_loopempty, T_KW_return, T_KW_switch, T_KW_while, /* Operators */ T_KW_and, T_KW_mod, T_KW_not, T_KW_or, /* Special values */ T_KW_false, T_KW_true, T_KW_none }; #define FIRST_QUALIFIER T_KW_var #define LAST_QUALIFIER T_KW_unsigned #define NUM_QUALIFIERS (LAST_QUALIFIER+1 - FIRST_QUALIFIER) #define TOKEN_CASES_QUALIFIERS \ case T_KW_var: \ case T_KW_aliased: \ case T_KW_volatile: \ case T_KW_wrapping: \ case T_KW_signed: \ case T_KW_unsigned: #define TOKEN_CASES_VALUE_START \ case T_LowerIdent: \ case T_Integer: \ case T_String: \ case T_SYM_LParen: \ case T_SYM_RParen: \ case T_SYM_LBracket: \ case T_KW_not: \ case T_KW_false: \ case T_KW_true: \ case T_KW_none: /* Type qualifiers */ #define Q_VAR 0x01 #define Q_ALIASED 0x02 #define Q_VOLATILE 0x04 #define Q_SIGNED 0x08 #define Q_UNSIGNED 0x10 #define Q_WRAPPING 0x20 struct LexemeInfo { size_t len; const char *string; /* Negative numbers are created with the unary minus operator */ uint64_t num; }; void tokenizer_init(FILE *f); bool tokenizer_next_line(void); bool tokenizer_line_is_indented(void); enum Token tokenize(struct LexemeInfo *li_out); void unread_token(void); void expect(struct LexemeInfo *li_out, enum Token expected, const char *errmsg); void expect_next_line(void); #endif