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
|
#pragma once
#include <stddef.h>
#include <utils/memory/memory.h>
#include <utils/types.h>
typedef enum Token {
TOKEN_NONE = 0,
TOKEN_IDENTIFIER,
TOKEN_KEYWORD_PRINT,
TOKEN_NUMBER,
TOKEN_STRING,
TOKEN_OPERATOR,
TOKEN_OPERATOR_PARENTHESES_OPEN,
TOKEN_OPERATOR_PARENTHESES_CLOSE,
TOKEN_OPERATOR_CURLY_BRACKET_OPEN,
TOKEN_OPERATOR_CURLY_BRACKET_CLOSE,
TOKEN_OPERATOR_ASSIGN,
TOKEN_OPERATOR_EQUAL,
TOKEN_OPERATOR_COLON,
TOKEN_OPERATOR_EOL,
TOKEN_SYMBOL,
TOKEN_PARSED,
} Token;
extern const char *TOKEN_STRINGS[];
typedef struct Node {
char const *strBegin;
char const *strEnd;
Token token;
void *parsedNode;
} Node;
typedef struct Nodes {
Node *nodes;
size_t size;
} Nodes;
extern void printNodes(Nodes nodes);
extern void deleteNodes(Nodes nodes);
extern Nodes lexer(char const *restrict str);
extern void push_if_not_empty(Node **restrict nodes,
size_t *restrict nodes_size,
size_t *restrict nodes_inserted,
Node *restrict node, char const *restrict str,
int i, Token token);
extern void push_clear_without_check(Node **restrict nodes,
size_t *restrict nodes_size,
size_t *restrict nodes_inserted,
Node *node, char const *restrict str,
int i, Token token);
extern bool isSpace(char c);
extern bool isIdentifier(char c);
extern bool isIdentifierSymbol(char c);
extern bool isNumber(char c);
extern bool isString(char c);
extern bool isOperator(char c);
extern bool isSymbol(char c);
extern Token getKeyword(char const *strBegin, char const *strEnd);
extern Token getOperator(char const *strBegin, char const *strEnd);
|