refactored lexer code
[cparser] / token_t.h
1 #ifndef TOKEN_T_H
2 #define TOKEN_T_H
3
4 #include <stdio.h>
5 #include "symbol.h"
6 #include "symbol_table.h"
7
8 typedef enum {
9 #define T(x,str,val) T_##x val,
10 #define TS(x,str,val) T_##x val,
11 #include "tokens.inc"
12 #undef TS
13 #undef T
14
15         T_EOF   = -1,
16         T_ERROR = -2
17 } token_type_t;
18
19 typedef enum {
20 #define T(x,str,val) TP_##x val,
21 #define TS(x,str,val) TP_##x val,
22 #include "tokens_preprocessor.inc"
23 #undef TS
24 #undef T
25 } preprocessor_token_type_t;
26
27 typedef struct source_position_t source_position_t;
28 struct source_position_t {
29         const char *input_name;
30         unsigned    linenr;
31 };
32
33 typedef struct {
34         int type;
35         union {
36                 symbol_t   *symbol;
37                 int         intvalue;
38                 const char *string;
39         } v;
40         source_position_t  source_position;
41 } token_t;
42
43 void init_tokens(void);
44 void exit_tokens(void);
45 void print_token_type(FILE *out, token_type_t token_type);
46 void print_token(FILE *out, const token_t *token);
47
48 #endif