annotate lwcc/lex.c @ 301:6f7fe78bb868 ccdev

Add string -> number conversion for preproc expression evaluator Q&D conversion from string to signed number. It should be noted that this really should be done during tokenization and the type of number be set by the tokenizer, including parsing floating point values. Then the preprocessor can decide what to do with non-integer numbers.
author William Astle <lost@l-w.ca>
date Sun, 15 Sep 2013 14:22:10 -0600
parents 8d6c47395653
children d85d173ba120
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
1 /*
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
2 lwcc/lex.c
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
3
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
4 Copyright © 2013 William Astle
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
5
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
6 This file is part of LWTOOLS.
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
7
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
11 version.
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
12
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
16 more details.
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
17
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
20 */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
21
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
22 #include <ctype.h>
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
23 #include <stdio.h>
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
24
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
25 #include <lw_alloc.h>
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
26
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
27 #include "cpp.h"
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
28 #include "strbuf.h"
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
29 #include "token.h"
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
30
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
31 /* fetch a raw input byte from the current file. Will return CPP_EOF if
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
32 EOF is encountered and CPP_EOL if an end of line sequence is encountered.
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
33 End of line is defined as either CR, CRLF, LF, or LFCR. CPP_EOL is
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
34 returned on the first CR or LF encountered. The complementary CR or LF
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
35 is munched, if present, when the *next* character is read. This always
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
36 operates on file_stack.
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
37
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
38 This function also accounts for line numbers in input files and also
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
39 character columns.
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
40 */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
41 static int fetch_byte_ll(struct preproc_info *pp)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
42 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
43 int c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
44
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
45 if (pp -> eolstate != 0)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
46 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
47 pp -> lineno++;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
48 pp -> column = 0;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
49 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
50 c = getc(pp -> fp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
51 pp -> column++;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
52 if (pp -> eolstate == 1)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
53 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
54 // just saw CR, munch LF
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
55 if (c == 10)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
56 c = getc(pp -> fp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
57 pp -> eolstate = 0;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
58 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
59 else if (pp -> eolstate == 2)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
60 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
61 // just saw LF, much CR
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
62 if (c == 13)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
63 c = getc(pp -> fp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
64 pp -> eolstate = 0;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
65 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
66
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
67 if (c == 10)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
68 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
69 // we have LF - end of line, flag to munch CR
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
70 pp -> eolstate = 2;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
71 c = CPP_EOL;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
72 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
73 else if (c == 13)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
74 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
75 // we have CR - end of line, flag to munch LF
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
76 pp -> eolstate = 1;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
77 c = CPP_EOL;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
78 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
79 else if (c == EOF)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
80 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
81 c = CPP_EOF;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
82 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
83 return c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
84 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
85
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
86 /* This function takes a sequence of bytes from the _ll function above
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
87 and does trigraph interpretation on it, but only if the global
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
88 trigraphs is nonzero. */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
89 static int fetch_byte_tg(struct preproc_info *pp)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
90 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
91 int c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
92
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
93 if (!pp -> trigraphs)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
94 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
95 c = fetch_byte_ll(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
96 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
97 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
98 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
99 /* we have to do the trigraph shit here */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
100 if (pp -> ra != CPP_NOUNG)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
101 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
102 if (pp -> qseen > 0)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
103 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
104 c = '?';
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
105 pp -> qseen -= 1;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
106 return c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
107 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
108 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
109 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
110 c = pp -> ra;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
111 pp -> ra = CPP_NOUNG;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
112 return c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
113 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
114 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
115
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
116 c = fetch_byte_ll(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
117 while (c == '?')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
118 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
119 pp -> qseen++;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
120 c = fetch_byte_ll(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
121 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
122
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
123 if (pp -> qseen >= 2)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
124 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
125 // we have a trigraph
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
126 switch (c)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
127 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
128 case '=':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
129 c = '#';
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
130 pp -> qseen -= 2;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
131 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
132
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
133 case '/':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
134 c = '\\';
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
135 pp -> qseen -= 2;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
136 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
137
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
138 case '\'':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
139 c = '^';
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
140 pp -> qseen -= 2;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
141 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
142
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
143 case '(':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
144 c = '[';
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
145 pp -> qseen -= 2;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
146 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
147
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
148 case ')':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
149 c = ']';
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
150 pp -> qseen -= 2;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
151 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
152
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
153 case '!':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
154 c = '|';
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
155 pp -> qseen -= 2;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
156 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
157
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
158 case '<':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
159 c = '{';
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
160 pp -> qseen -= 2;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
161 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
162
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
163 case '>':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
164 c = '}';
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
165 pp -> qseen -= 2;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
166 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
167
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
168 case '-':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
169 c = '~';
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
170 pp -> qseen -= 2;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
171 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
172 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
173 if (pp -> qseen > 0)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
174 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
175 pp -> ra = c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
176 c = '?';
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
177 pp -> qseen--;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
178 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
179 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
180 else if (pp -> qseen > 0)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
181 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
182 pp -> ra = c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
183 c = '?';
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
184 pp -> qseen--;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
185 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
186 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
187 return c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
188 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
189
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
190 /* This function puts a byte back onto the front of the input stream used
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
191 by fetch_byte(). Theoretically, an unlimited number of characters can
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
192 be unfetched. Line and column counting may be incorrect if unfetched
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
193 characters cross a token boundary. */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
194 static void preproc_lex_unfetch_byte(struct preproc_info *pp, int c)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
195 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
196 if (pp -> ungetbufl >= pp -> ungetbufs)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
197 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
198 pp -> ungetbufs += 100;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
199 pp -> ungetbuf = lw_realloc(pp -> ungetbuf, pp -> ungetbufs);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
200 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
201 pp -> ungetbuf[pp -> ungetbufl++] = c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
202 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
203
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
204 /* This function retrieves a byte from the input stream. It performs
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
205 backslash-newline splicing on the returned bytes. Any character
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
206 retrieved from the unfetch buffer is presumed to have already passed
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
207 the backslash-newline filter. */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
208 static int fetch_byte(struct preproc_info *pp)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
209 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
210 int c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
211
298
6112c67728ba Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents: 296
diff changeset
212 if (pp -> lexstr)
6112c67728ba Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents: 296
diff changeset
213 {
6112c67728ba Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents: 296
diff changeset
214 if (pp -> lexstr[pp -> lexstrloc])
6112c67728ba Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents: 296
diff changeset
215 return pp -> lexstr[pp -> lexstrloc++];
6112c67728ba Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents: 296
diff changeset
216 else
6112c67728ba Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents: 296
diff changeset
217 return CPP_EOL;
6112c67728ba Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents: 296
diff changeset
218 }
6112c67728ba Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents: 296
diff changeset
219
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
220 if (pp -> ungetbufl > 0)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
221 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
222 pp -> ungetbufl--;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
223 c = pp -> ungetbuf[pp -> ungetbufl];
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
224 if (pp -> ungetbufl == 0)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
225 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
226 lw_free(pp -> ungetbuf);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
227 pp -> ungetbuf = NULL;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
228 pp -> ungetbufs = 0;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
229 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
230 return c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
231 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
232
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
233 again:
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
234 if (pp -> unget != CPP_NOUNG)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
235 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
236 c = pp -> unget;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
237 pp -> unget = CPP_NOUNG;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
238 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
239 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
240 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
241 c = fetch_byte_tg(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
242 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
243 if (c == '\\')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
244 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
245 int c2;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
246 c2 = fetch_byte_tg(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
247 if (c2 == CPP_EOL)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
248 goto again;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
249 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
250 pp -> unget = c2;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
251 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
252 return c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
253 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
254
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
255
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
256
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
257 /*
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
258 Lex a token off the current input file.
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
259
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
260 Returned tokens are as follows:
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
261
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
262 * all words starting with [a-zA-Z_] are returned as TOK_IDENT
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
263 * numbers are returned as their appropriate type
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
264 * all whitespace in a sequence, including comments, is returned as
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
265 a single instance of TOK_WSPACE
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
266 * TOK_EOL is returned in the case of the end of a line
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
267 * TOK_EOF is returned when the end of the file is reached
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
268 * If no TOK_EOL appears before TOK_EOF, a TOK_EOL will be synthesised
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
269 * Any symbolic operator, etc., recognized by C will be returned as such
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
270 a token
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
271 * TOK_HASH will be returned for a #
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
272 * trigraphs will be interpreted
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
273 * backslash-newline will be interpreted
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
274 * any instance of CR, LF, CRLF, or LFCR will be interpreted as TOK_EOL
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
275 */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
276
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
277
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
278 static int preproc_lex_fetch_byte(struct preproc_info *pp)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
279 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
280 int c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
281 c = fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
282 if (c == CPP_EOF && pp -> eolseen == 0)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
283 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
284 preproc_throw_warning(pp, "No newline at end of file");
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
285 pp -> eolseen = 1;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
286 return CPP_EOL;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
287 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
288
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
289 if (c == CPP_EOL)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
290 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
291 pp -> eolseen = 1;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
292 return c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
293 }
300
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
294
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
295 pp -> eolseen = 0;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
296
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
297 /* convert comments to a single space here */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
298 if (c == '/')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
299 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
300 int c2;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
301 c2 = fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
302 if (c2 == '/')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
303 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
304 /* single line comment */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
305 c = ' ';
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
306 for (;;)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
307 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
308 c2 = fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
309 if (c2 == CPP_EOF || c2 == CPP_EOL)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
310 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
311 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
312 preproc_lex_unfetch_byte(pp, c2);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
313 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
314 else if (c2 == '*')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
315 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
316 /* block comment */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
317 c = ' ';
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
318 for (;;)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
319 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
320 c2 = fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
321 if (c2 == CPP_EOL || c2 == CPP_EOF)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
322 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
323 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
324 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
325 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
326 if (c2 == '*')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
327 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
328 /* maybe end of comment */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
329 c2 = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
330 if (c2 == '/')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
331 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
332 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
333 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
334 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
335 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
336 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
337 /* not a comment - restore lookahead character */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
338 preproc_lex_unfetch_byte(pp, c2);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
339 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
340 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
341 return c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
342 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
343
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
344 struct token *preproc_lex_next_token(struct preproc_info *pp)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
345 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
346 int sline = pp -> lineno;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
347 int scol = pp -> column;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
348 char *strval = NULL;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
349 int ttype = TOK_NONE;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
350 int c, c2;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
351 int cl;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
352 struct strbuf *strbuf;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
353 struct token *t;
300
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
354 struct preproc_info *fs;
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
355
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
356 fileagain:
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
357 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
358 if (c == CPP_EOF)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
359 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
360 if (pp -> nlseen == 0)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
361 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
362 c = CPP_EOL;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
363 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
364 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
365
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
366 if (c == CPP_EOF)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
367 {
300
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
368 /* check if we fell off the end of an include file */
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
369 if (pp -> filestack)
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
370 {
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
371 if (pp -> skip_level || pp -> found_level)
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
372 {
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
373 preproc_throw_error(pp, "Unbalanced conditionals in include file");
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
374 }
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
375 fclose(pp -> fp);
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
376 fs = pp -> filestack;
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
377 *pp = *fs;
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
378 pp -> filestack = fs -> n;
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
379 goto fileagain;
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
380 }
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
381 else
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
382 {
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
383 ttype = TOK_EOF;
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
384 goto out;
8d6c47395653 Implemented #include and #line
William Astle <lost@l-w.ca>
parents: 299
diff changeset
385 }
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
386 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
387 if (c == CPP_EOL)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
388 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
389 pp -> nlseen = 1;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
390 ttype = TOK_EOL;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
391 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
392 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
393
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
394 pp -> nlseen = 0;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
395 if (isspace(c))
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
396 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
397 while (isspace(c))
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
398 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
399 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
400 ttype = TOK_WSPACE;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
401 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
402 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
403
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
404 switch (c)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
405 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
406 case '?':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
407 ttype = TOK_QMARK;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
408 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
409
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
410 case ':':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
411 ttype = TOK_COLON;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
412 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
413
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
414 case ',':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
415 ttype = TOK_COMMA;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
416 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
417
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
418 case '(':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
419 ttype = TOK_OPAREN;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
420 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
421
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
422 case ')':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
423 ttype = TOK_CPAREN;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
424 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
425
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
426 case '{':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
427 ttype = TOK_OBRACE;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
428 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
429
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
430 case '}':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
431 ttype = TOK_CBRACE;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
432 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
433
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
434 case '[':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
435 ttype = TOK_OSQUARE;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
436 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
437
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
438 case ']':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
439 ttype = TOK_CSQUARE;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
440 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
441
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
442 case '~':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
443 ttype = TOK_COM;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
444 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
445
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
446 case ';':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
447 ttype = TOK_EOS;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
448 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
449
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
450 /* and now for the possible multi character tokens */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
451 case '#':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
452 ttype = TOK_HASH;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
453 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
454 if (c == '#')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
455 ttype = TOK_DBLHASH;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
456 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
457 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
458 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
459
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
460 case '^':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
461 ttype = TOK_XOR;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
462 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
463 if (c == '=')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
464 ttype = TOK_XORASS;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
465 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
466 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
467 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
468
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
469 case '!':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
470 ttype = TOK_BNOT;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
471 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
472 if (c == '=')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
473 ttype = TOK_NE;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
474 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
475 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
476 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
477
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
478 case '*':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
479 ttype = TOK_STAR;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
480 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
481 if (c == '=')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
482 ttype = TOK_MULASS;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
483 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
484 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
485 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
486
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
487 case '/':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
488 ttype = TOK_DIV;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
489 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
490 if (c == '=')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
491 ttype = TOK_DIVASS;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
492 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
493 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
494 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
495
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
496 case '=':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
497 ttype = TOK_ASS;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
498 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
499 if (c == '=')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
500 ttype = TOK_EQ;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
501 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
502 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
503 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
504
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
505 case '%':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
506 ttype = TOK_MOD;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
507 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
508 if (c == '=')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
509 ttype = TOK_MODASS;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
510 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
511 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
512 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
513
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
514 case '-':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
515 ttype = TOK_SUB;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
516 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
517 if (c == '=')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
518 ttype = TOK_SUBASS;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
519 else if (c == '-')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
520 ttype = TOK_DBLSUB;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
521 else if (c == '>')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
522 ttype = TOK_ARROW;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
523 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
524 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
525 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
526
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
527 case '+':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
528 ttype = TOK_ADD;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
529 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
530 if (c == '=')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
531 ttype = TOK_ADDASS;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
532 else if (c == '+')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
533 ttype = TOK_DBLADD;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
534 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
535 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
536 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
537
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
538
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
539 case '&':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
540 ttype = TOK_BWAND;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
541 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
542 if (c == '=')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
543 ttype = TOK_BWANDASS;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
544 else if (c == '&')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
545 ttype = TOK_BAND;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
546 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
547 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
548 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
549
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
550 case '|':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
551 ttype = TOK_BWOR;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
552 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
553 if (c == '=')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
554 ttype = TOK_BWORASS;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
555 else if (c == '|')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
556 ttype = TOK_BOR;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
557 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
558 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
559 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
560
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
561 case '<':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
562 ttype = TOK_LT;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
563 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
564 if (c == '=')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
565 ttype = TOK_LE;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
566 else if (c == '<')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
567 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
568 ttype = TOK_LSH;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
569 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
570 if (c == '=')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
571 ttype = TOK_LSHASS;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
572 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
573 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
574 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
575 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
576 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
577 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
578
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
579
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
580 case '>':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
581 ttype = TOK_GT;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
582 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
583 if (c == '=')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
584 ttype = TOK_GE;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
585 else if (c == '>')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
586 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
587 ttype = TOK_RSH;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
588 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
589 if (c == '=')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
590 ttype = TOK_RSHASS;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
591 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
592 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
593 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
594 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
595 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
596 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
597
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
598 case '\'':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
599 /* character constant - turns into a uint */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
600 chrlit:
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
601 cl = 0;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
602 strbuf = strbuf_new();
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
603 for (;;)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
604 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
605 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
606 if (c == CPP_EOF || c == CPP_EOL || c == '\'')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
607 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
608 cl++;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
609 if (c == '\\')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
610 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
611 strbuf_add(strbuf, '\\');
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
612 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
613 if (c == CPP_EOF || c == CPP_EOL)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
614 {
298
6112c67728ba Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents: 296
diff changeset
615 if (!pp -> lexstr)
6112c67728ba Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents: 296
diff changeset
616 preproc_throw_error(pp, "Invalid character constant");
299
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
617 ttype = TOK_ERROR;
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
618 strval = strbuf_end(strbuf);
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
619 goto out;
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
620 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
621 cl++;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
622 strbuf_add(strbuf, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
623 continue;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
624 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
625 strbuf_add(strbuf, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
626 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
627 strval = strbuf_end(strbuf);
299
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
628 if (cl == 0)
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
629 {
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
630 ttype = TOK_ERROR;
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
631 if (!pp -> lexstr)
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
632 preproc_throw_error(pp, "Invalid character constant");
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
633 }
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
634 else
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
635 ttype = TOK_CHR_LIT;
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
636 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
637
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
638 case '"':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
639 strlit:
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
640 /* string literal */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
641 strbuf = strbuf_new();
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
642 for (;;)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
643 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
644 c = preproc_lex_fetch_byte(pp);
299
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
645 if (c == CPP_EOF || c == CPP_EOL)
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
646 {
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
647 ttype = TOK_ERROR;
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
648 strval = strbuf_end(strbuf);
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
649 if (!pp -> lexstr)
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
650 preproc_throw_error(pp, "Invalid string constant");
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
651 goto out;
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
652 }
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
653 if (c == '"')
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
654 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
655 if (c == '\\')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
656 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
657 strbuf_add(strbuf, '\\');
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
658 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
659 if (c == CPP_EOF || c == CPP_EOL)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
660 {
299
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
661 ttype = TOK_ERROR;
298
6112c67728ba Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents: 296
diff changeset
662 if (!pp -> lexstr)
6112c67728ba Add stringification and token concatenation
William Astle <lost@l-w.ca>
parents: 296
diff changeset
663 preproc_throw_error(pp, "Invalid string constant");
299
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
664 strval = strbuf_end(strbuf);
856caf91ffaa Added token list structure and switched some stuff to use it
William Astle <lost@l-w.ca>
parents: 298
diff changeset
665 goto out;
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
666 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
667 cl++;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
668 strbuf_add(strbuf, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
669 continue;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
670 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
671 strbuf_add(strbuf, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
672 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
673 strval = strbuf_end(strbuf);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
674 ttype = TOK_STR_LIT;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
675 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
676
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
677 case 'L':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
678 /* check for wide string or wide char const */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
679 c2 = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
680 if (c2 == '\'')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
681 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
682 goto chrlit;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
683 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
684 else if (c2 == '"')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
685 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
686 goto strlit;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
687 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
688 preproc_lex_unfetch_byte(pp, c2);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
689 /* fall through for identifier */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
690 case '_':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
691 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
692 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
693 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
694 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
695 case 'y': case 'z':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
696 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
697 case 'G': case 'H': case 'I': case 'J': case 'K':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
698 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
699 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
700 case 'Y': case 'Z':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
701 /* we have an identifier here */
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
702 strbuf = strbuf_new();
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
703 strbuf_add(strbuf, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
704 for (;;)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
705 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
706 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
707 if ((c == '_') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
708 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
709 strbuf_add(strbuf, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
710 continue;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
711 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
712 else
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
713 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
714 strbuf_add(strbuf, 0);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
715 strval = strbuf_end(strbuf);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
716 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
717 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
718 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
719 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
720 ttype = TOK_IDENT;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
721 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
722
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
723 case '.':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
724 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
725 if (c >= '0' && c <= '9')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
726 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
727 strbuf = strbuf_new();
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
728 strbuf_add(strbuf, '.');
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
729 goto numlit;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
730 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
731 else if (c == '.')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
732 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
733 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
734 if (c == '.')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
735 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
736 ttype = TOK_ELLIPSIS;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
737 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
738 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
739 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
740 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
741 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
742 ttype = TOK_DOT;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
743 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
744
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
745 case '0': case '1': case '2': case '3': case '4':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
746 case '5': case '6': case '7': case '8': case '9':
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
747 strbuf = strbuf_new();
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
748 numlit:
296
83fcc1ed6ad6 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents: 295
diff changeset
749 ttype = TOK_NUMBER;
295
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
750 strbuf_add(strbuf, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
751 for (;;)
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
752 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
753 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
754 if (!((c == '_') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')))
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
755 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
756 strbuf_add(strbuf, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
757 if (c == 'e' || c == 'E' || c == 'p' || c == 'P')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
758 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
759 c = preproc_lex_fetch_byte(pp);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
760 if (c == '+' || c == '-')
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
761 {
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
762 strbuf_add(strbuf, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
763 continue;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
764 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
765 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
766 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
767 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
768 strval = strbuf_end(strbuf);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
769 preproc_lex_unfetch_byte(pp, c);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
770 goto out;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
771
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
772 default:
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
773 ttype = TOK_CHAR;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
774 strval = lw_alloc(2);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
775 strval[0] = c;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
776 strval[1] = 0;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
777 break;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
778 }
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
779 out:
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
780 t = token_create(ttype, strval, sline, scol, pp -> fn);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
781 lw_free(strval);
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
782 return t;
4b17780f2777 Checkpoint lwcc development
William Astle <lost@l-w.ca>
parents:
diff changeset
783 }