-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlex.h
68 lines (49 loc) · 1.27 KB
/
lex.h
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
#ifndef LEX_H
#define LEX_H
#include "utils_string.h"
#include<stdint.h>
#define NUM_OF_TOKENS 5
#define ERROR(...) {fprintf(stderr, __VA_ARGS__); exit(-1);}
#define MAX_TOKENS 50000
#define MAX_LENGHT 20
#define MAX_NUM_OF_TOKENS_IN_A_WORD 1000
typedef enum TokenType_t {
TYPE_CONST = 0,
TYPE_VAR,
TYPE_KEYWORD,
TYPE_USER_DEFINE_KEYWORD,
TYPE_UNREGISTER,
TYPE_OPERATION,
TYPE_LOGICOPERATOR,
TYPE_EOF,
} TokenType;
static const char* TokenString[] = {
"CONST",
"VAR",
"KEYWORD",
"TYPE_USER_DEFINE_KEYWORD",
"UNREGISTER",
"OPERATION",
"LOGICOPERATOR",
"EOF",
};
//static_assert(NUM_OF_TOKENS==TYPE_EOF, "we have more tokens then max");
enum {I, F, U, CH, STR};
typedef struct {
TokenType type;
char* value; //IT EXIST TRUE ALL LIFTIME OF A PROGRAM
uint8_t valType;
} Token;
//DYNAMIC ARRAY FOR A TOKENS name dArr_Token
typedef struct {
//TBD arena_alloc alocation
Token tokens[MAX_NUM_OF_TOKENS_IN_A_WORD]; //TBD AS A DYNAMIC ARRAY
int numOfTokens;
char *name;
}Words;
static int numOfUserDefiendWords = 0;
//DYNAIC ARRAY FOR A WORD name dArr_Words
Token* Tokeniser(char* input, Words *words, Arena *mainArena);
void DestroyTokens(Token* tokens);
void PrintTokens(Token* tokens);
#endif