BFC-Compiler
A C23 Brainfuck compiler
Toggle main menu visibility
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
30
typedef
enum
31
{
32
#define X(tok_type, ...) tok_type,
33
TOKEN_MAP
34
#undef X
35
}
bfc_token_type_t
;
36
40
typedef
struct
41
{
42
bfc_token_type_t
type;
43
uint32_t line;
44
uint32_t col;
45
}
bfc_token_t
;
46
50
typedef
struct
51
{
52
bfc_token_t
* tokens;
53
size_t
length;
54
}
bfc_token_stream_t
;
55
59
[[nodiscard, gnu::const]]
60
bfc_token_t
61
bfc_make_token
(
bfc_token_type_t
const
tok_type, uint32_t
const
line, uint32_t
const
col);
62
66
void
bfc_token_stream_destroy
(
bfc_token_stream_t
** ptok_stream);
67
68
#endif
// BFC_TOKEN_H
bfc_token_stream_destroy
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_make_token
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
TOKEN_MAP
#define TOKEN_MAP
Single source of truth for Brainfuck characters and token kinds.
Definition
bfc_token.h:17
bfc_token_type_t
bfc_token_type_t
Token kinds emitted by the lexer.
Definition
bfc_token.h:31
bfc_token_stream_t
Owning token sequence produced by the lexer.
Definition
bfc_token.h:51
bfc_token_t
One Brainfuck token and its one-based source location.
Definition
bfc_token.h:41
include
bfc_token.h
Generated by
1.17.0