BFC-Compiler
A C23 Brainfuck compiler
Loading...
Searching...
No Matches
bfc_token.h
Go to the documentation of this file.
1
8#ifndef BFC_TOKEN_H
9#define BFC_TOKEN_H
10
11#include <stddef.h>
12#include <stdint.h>
13
17#define TOKEN_MAP \
18 X(TT_INC, '+') \
19 X(TT_DEC, '-') \
20 X(TT_PTR_RIGHT, '>') \
21 X(TT_PTR_LEFT, '<') \
22 X(TT_LOOP_START, '[') \
23 X(TT_LOOP_END, ']') \
24 X(TT_OUTPUT, '.') \
25 X(TT_INPUT, ',')
26
30typedef enum
31{
32#define X(tok_type, ...) tok_type,
34#undef X
36
40typedef struct
41{
43 uint32_t line;
44 uint32_t col;
46
50typedef struct
51{
52 bfc_token_t* tokens;
53 size_t length;
55
59[[nodiscard, gnu::const]]
61bfc_make_token(bfc_token_type_t const tok_type, uint32_t const line, uint32_t const col);
62
67
68#endif // BFC_TOKEN_H
void bfc_token_stream_destroy(bfc_token_stream_t **ptok_stream)
Releases a token stream and nulls the caller pointer.
Definition bfc_token.c:23
bfc_token_t bfc_make_token(bfc_token_type_t const tok_type, uint32_t const line, uint32_t const col)
Constructs a token value without allocating memory.
Definition bfc_token.c:15
#define TOKEN_MAP
Single source of truth for Brainfuck characters and token kinds.
Definition bfc_token.h:17
bfc_token_type_t
Token kinds emitted by the lexer.
Definition bfc_token.h:31
Owning token sequence produced by the lexer.
Definition bfc_token.h:51
One Brainfuck token and its one-based source location.
Definition bfc_token.h:41