1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/*
* Copyright (c) 2026, Chloe M.
* Provided under the BSD-3 clause
*/
#include <stdint.h>
#include <errno.h>
#include "cescal/log.h"
#include "cescal/parser.h"
#include "cescal/state.h"
#include "cescal/lexer.h"
/* Symbolic token */
#define symtok(tok) \
"[" tok "]"
/* Quoted token */
#define qtok(tok) \
"'" tok "'"
/* Convert token to string */
#define tokstr1(tt) \
toktab[(tt)]
/* Convert token to string */
#define tokstr(tok) \
toktab[(tok)->type]
/*
* Converts numeric tokens into human readable strings
*/
static const char *toktab[] = {
[TT_NONE] = symtok("none"),
[TT_IDENT] = symtok("ident"),
[TT_COMMENT] = symtok("comment"),
[TT_INTLIT] = symtok("number"),
[TT_LPAREN] = qtok("("),
[TT_RPAREN] = qtok(")"),
[TT_COMMA] = qtok(","),
[TT_COLON] = qtok(":"),
[TT_ARROW] = qtok("->"),
[TT_DEFINE] = qtok("#define"),
[TT_IFNDEF] = qtok("#ifndef"),
[TT_IFDEF] = qtok("#ifdef"),
[TT_RETURN] = qtok("return"),
[TT_PUB] = qtok("pub"),
[TT_PROC] = qtok("proc"),
[TT_BEGIN] = qtok("begin"),
[TT_END] = qtok("end"),
[TT_U8] = qtok("u8"),
[TT_U16] = qtok("u16"),
[TT_U32] = qtok("u32"),
[TT_U64] = qtok("u64")
};
int
parser_parse(struct cescal_state *state)
{
struct token tok;
if (state == NULL) {
errno = EINVAL;
return -1;
}
while (lexer_nom(state, &tok) == 0) {
cc_trace("got token %s\n", tokstr(&tok));
}
return 0;
}
|