blob: 1d3acdb999835ef29e4a5b3155852b5a843e03cd (
plain) (
blame)
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
|
#ifndef __TOKENIZER_H
#define __TOKENIZER_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "darray.h"
#define TOK_NONE 0
#define TOK_HEX 1
#define TOK_INT 2
#define TOK_NL 3
#define TOK_IF 4
#define TOK_LBR 5
#define TOK_RBR 6
#define TOK_STR 7
#define TOK_EAND 8
#define TOK_RANGE 9
#define TOK2STR(X) TOK_#X
/*not best way how to define*/
#define TOK_IN_RANGE(TOK) ((TOK_HEX>=0)&&(TOK_RANGE<=TOK_RANGE))
typedef struct token
{
int token;
char *s, *e;
} token;
typedef struct token_list
{
darray *list;
} token_list;
token* token_create();
int token_set( token **tok, int val, char *s, char *e );
token_list* tl_create();
int tl_add_tok( token_list *tl, int t, char *s, char *e );
char* tl_str( token_list *tl );
void tl_destroy( token_list *tl );
int tl_size( token_list *tl );
#define tl_tok_type(TL,IDX) (((token *)(darr_get((TL)->list,IDX)))->token)
#define tl_get_tok(TL,IDX) ((token *)(darr_get((TL)->list,IDX)))
int tok2int( token *tok );
char *tok2str( token *tok );
#endif
|