Mercurial > hg > index.cgi
annotate lwcc/token.h @ 304:d85d173ba120 ccdev
Checkpoint lwcc development - preprocessor is runnable but nonfunctional
The preprocessor is currently runnable but doesn't actually do anything
useful. This is just a checkpoint.
author | William Astle <lost@l-w.ca> |
---|---|
date | Tue, 17 Sep 2013 19:33:41 -0600 |
parents | 856caf91ffaa |
children | 54f213c8fb81 |
rev | line source |
---|---|
295 | 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 enum | |
35 { | |
36 TOK_NONE = 0, | |
37 TOK_EOF, | |
38 TOK_EOL, | |
39 TOK_WSPACE, | |
40 TOK_IDENT, | |
41 TOK_NUMBER, | |
42 TOK_STRING, | |
43 TOK_CHAR, | |
44 TOK_DIV, | |
45 TOK_ADD, | |
46 TOK_SUB, | |
47 TOK_OPAREN, | |
48 TOK_CPAREN, | |
49 TOK_NE, | |
50 TOK_EQ, | |
51 TOK_LE, | |
52 TOK_LT, | |
53 TOK_GE, | |
54 TOK_GT, | |
55 TOK_BAND, | |
56 TOK_BOR, | |
57 TOK_BNOT, | |
58 TOK_MOD, | |
59 TOK_COMMA, | |
60 TOK_ELLIPSIS, | |
61 TOK_QMARK, | |
62 TOK_COLON, | |
63 TOK_OBRACE, | |
64 TOK_CBRACE, | |
65 TOK_OSQUARE, | |
66 TOK_CSQUARE, | |
67 TOK_COM, | |
68 TOK_EOS, | |
69 TOK_HASH, | |
70 TOK_DBLHASH, | |
71 TOK_XOR, | |
72 TOK_XORASS, | |
73 TOK_STAR, | |
74 TOK_MULASS, | |
75 TOK_DIVASS, | |
76 TOK_ASS, | |
77 TOK_MODASS, | |
78 TOK_SUBASS, | |
79 TOK_DBLSUB, | |
80 TOK_ADDASS, | |
81 TOK_DBLADD, | |
82 TOK_BWAND, | |
83 TOK_BWANDASS, | |
84 TOK_BWOR, | |
85 TOK_BWORASS, | |
86 TOK_LSH, | |
87 TOK_LSHASS, | |
88 TOK_RSH, | |
89 TOK_RSHASS, | |
90 TOK_DOT, | |
91 TOK_CHR_LIT, | |
92 TOK_STR_LIT, | |
93 TOK_ARROW, | |
296 | 94 TOK_ENDEXPAND, |
95 TOK_STARTEXPAND, | |
299
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
96 TOK_ERROR, |
295 | 97 TOK_MAX |
98 }; | |
99 | |
100 struct token | |
101 { | |
102 int ttype; // token type | |
103 char *strval; // the token value if relevant | |
104 struct token *prev; // previous token in a list | |
105 struct token *next; // next token in a list | |
299
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
106 struct token_list *list;// pointer to head of list descriptor this token is on |
295 | 107 int lineno; // line number token came from |
108 int column; // character column token came from | |
109 const char *fn; // file name token came from | |
110 }; | |
111 | |
299
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
112 struct token_list |
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
113 { |
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
114 struct token *head; // the head of the list |
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
115 struct token *tail; // the tail of the list |
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
116 }; |
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
117 |
295 | 118 extern void token_free(struct token *); |
119 extern struct token *token_create(int, char *strval, int, int, const char *); | |
120 extern struct token *token_dup(struct token *); | |
121 /* add a token to the end of a list */ | |
299
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
122 extern void token_list_append(struct token_list *, struct token *); |
295 | 123 /* add a token to the start of a list */ |
299
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
124 extern void token_list_prepend(struct token_list *, struct token *); |
295 | 125 /* remove individual token from whatever list it is on */ |
299
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
126 extern void token_list_remove(struct token *); |
295 | 127 /* replace token with list of tokens specified */ |
299
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
128 extern void token_list_insert(struct token_list *, struct token *, struct token *); |
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
129 /* duplicate a list to a new list pointer */ |
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
130 extern struct token_list *token_list_dup(struct token_list *); |
295 | 131 /* print a token out */ |
299
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
132 extern struct token_list *token_list_create(void); |
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
133 extern void token_list_destroy(struct token_list *); |
856caf91ffaa
Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents:
296
diff
changeset
|
134 |
295 | 135 extern void token_print(struct token *, FILE *); |
136 | |
137 #endif // token_h_seen___ |