Mercurial > hg > index.cgi
comparison lwcc/token.h @ 495:5b8871fd7503
Merged previous lwcc development branch into mainline.
author | William Astle <lost@l-w.ca> |
---|---|
date | Mon, 05 Aug 2019 21:27:09 -0600 |
parents | b08787e5b9f3 |
children |
comparison
equal
deleted
inserted
replaced
493:6073f4a33475 | 495:5b8871fd7503 |
---|---|
1 /* | |
2 lwcc/token.h | |
3 | |
4 Copyright © 2013 William Astle | |
5 | |
6 This file is part of LWTOOLS. | |
7 | |
8 LWTOOLS is free software: you can redistribute it and/or modify it under the | |
9 terms of the GNU General Public License as published by the Free Software | |
10 Foundation, either version 3 of the License, or (at your option) any later | |
11 version. | |
12 | |
13 This program is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 more details. | |
17 | |
18 You should have received a copy of the GNU General Public License along with | |
19 this program. If not, see <http://www.gnu.org/licenses/>. | |
20 */ | |
21 | |
22 #ifndef token_h_seen___ | |
23 #define token_h_seen___ | |
24 | |
25 #include <stdio.h> | |
26 | |
27 enum | |
28 { | |
29 CPP_NOUNG = -3, | |
30 CPP_EOL = -2, | |
31 CPP_EOF = -1, | |
32 }; | |
33 | |
34 #define TOK_NONE 0 | |
35 #define TOK_EOF 1 | |
36 #define TOK_EOL 2 | |
37 #define TOK_WSPACE 3 | |
38 #define TOK_IDENT 4 | |
39 #define TOK_NUMBER 5 | |
40 #define TOK_CHAR 6 | |
41 #define TOK_ADD 8 | |
42 #define TOK_SUB 9 | |
43 #define TOK_OPAREN 10 | |
44 #define TOK_CPAREN 11 | |
45 #define TOK_NE 12 | |
46 #define TOK_EQ 13 | |
47 #define TOK_LE 14 | |
48 #define TOK_LT 15 | |
49 #define TOK_GE 16 | |
50 #define TOK_GT 17 | |
51 #define TOK_BAND 18 | |
52 #define TOK_BOR 19 | |
53 #define TOK_BNOT 20 | |
54 #define TOK_MOD 21 | |
55 #define TOK_COMMA 22 | |
56 #define TOK_ELLIPSIS 23 | |
57 #define TOK_QMARK 24 | |
58 #define TOK_COLON 25 | |
59 #define TOK_OBRACE 26 | |
60 #define TOK_CBRACE 27 | |
61 #define TOK_OSQUARE 28 | |
62 #define TOK_CSQUARE 29 | |
63 #define TOK_COM 30 | |
64 #define TOK_EOS 31 | |
65 #define TOK_HASH 32 | |
66 #define TOK_DBLHASH 33 | |
67 #define TOK_XOR 34 | |
68 #define TOK_XORASS 35 | |
69 #define TOK_STAR 36 | |
70 #define TOK_MULASS 37 | |
71 #define TOK_DIV 38 | |
72 #define TOK_DIVASS 39 | |
73 #define TOK_ASS 40 | |
74 #define TOK_MODASS 41 | |
75 #define TOK_SUBASS 42 | |
76 #define TOK_DBLSUB 43 | |
77 #define TOK_ADDASS 44 | |
78 #define TOK_DBLADD 45 | |
79 #define TOK_BWAND 46 | |
80 #define TOK_BWANDASS 47 | |
81 #define TOK_BWOR 48 | |
82 #define TOK_BWORASS 49 | |
83 #define TOK_LSH 50 | |
84 #define TOK_LSHASS 51 | |
85 #define TOK_RSH 52 | |
86 #define TOK_RSHASS 53 | |
87 #define TOK_DOT 54 | |
88 #define TOK_CHR_LIT 55 | |
89 #define TOK_STR_LIT 56 | |
90 #define TOK_ARROW 57 | |
91 #define TOK_ENDEXPAND 58 | |
92 #define TOK_ERROR 59 | |
93 #define TOK_MAX 60 | |
94 | |
95 struct token | |
96 { | |
97 int ttype; // token type | |
98 char *strval; // the token value if relevant | |
99 struct token *prev; // previous token in a list | |
100 struct token *next; // next token in a list | |
101 struct token_list *list;// pointer to head of list descriptor this token is on | |
102 int lineno; // line number token came from | |
103 int column; // character column token came from | |
104 const char *fn; // file name token came from | |
105 }; | |
106 | |
107 struct token_list | |
108 { | |
109 struct token *head; // the head of the list | |
110 struct token *tail; // the tail of the list | |
111 }; | |
112 | |
113 extern void token_free(struct token *); | |
114 extern struct token *token_create(int, char *strval, int, int, const char *); | |
115 extern struct token *token_dup(struct token *); | |
116 /* add a token to the end of a list */ | |
117 extern void token_list_append(struct token_list *, struct token *); | |
118 /* add a token to the start of a list */ | |
119 extern void token_list_prepend(struct token_list *, struct token *); | |
120 /* remove individual token from whatever list it is on */ | |
121 extern void token_list_remove(struct token *); | |
122 /* replace token with list of tokens specified */ | |
123 extern void token_list_insert(struct token_list *, struct token *, struct token *); | |
124 /* duplicate a list to a new list pointer */ | |
125 extern struct token_list *token_list_dup(struct token_list *); | |
126 /* print a token out */ | |
127 extern struct token_list *token_list_create(void); | |
128 extern void token_list_destroy(struct token_list *); | |
129 | |
130 extern void token_print(struct token *, FILE *); | |
131 | |
132 #endif // token_h_seen___ |