BFC-Compiler
A C23 Brainfuck compiler
Loading...
Searching...
No Matches
bfc_lexer.c File Reference

Brainfuck lexer implementation. More...

#include "bfc_lexer.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include "bfc_memory.h"

Macros

#define EMIT_TOKEN(toktype)
#define X(tok_type, tok_char)

Functions

bfc_error_t bfc_lex (bfc_token_stream_t **token_stream, bfc_program_t const *const program, bfc_args_t const cmd_args)
 Scans the source buffer and builds a compact, location-aware token stream.

Detailed Description

Brainfuck lexer implementation.

Scans source bytes, tracks one-based positions, applies the optional semicolon-comment extension, and emits tokens.

Macro Definition Documentation

◆ EMIT_TOKEN

#define EMIT_TOKEN ( toktype)
Value:
if (!in_comment) tok_stream->tokens[token_list_size++] = bfc_make_token((toktype), line, col);
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

◆ X

#define X ( tok_type,
tok_char )
Value:
case tok_char: { \
EMIT_TOKEN(tok_type); \
} \
break;

Function Documentation

◆ bfc_lex()

bfc_error_t bfc_lex ( bfc_token_stream_t ** token_stream,
bfc_program_t const *const program,
bfc_args_t const cmd_args )

Scans the source buffer and builds a compact, location-aware token stream.

Tokenizes a loaded Brainfuck source program.

Scans the source buffer and builds a compact, location-aware token stream.

Parameters
[out]token_streamReceives the allocated token stream.
[in]programLoaded source program.
[in]cmd_argsLexer-affecting command-line options.
Returns
BFC_ERR_OK on success; otherwise an allocation error.
Note
Release the result with bfc_token_stream_destroy().