H. Peter Anvin | 9e6747c | 2009-06-28 17:13:04 -0700 | [diff] [blame] | 1 | /* ----------------------------------------------------------------------- * |
Cyrill Gorcunov | beaef4a | 2009-10-30 11:29:43 +0300 | [diff] [blame] | 2 | * |
H. Peter Anvin | 94adf7d | 2018-06-15 18:37:32 -0700 | [diff] [blame] | 3 | * Copyright 1996-2018 The NASM Authors - All Rights Reserved |
H. Peter Anvin | 9e6747c | 2009-06-28 17:13:04 -0700 | [diff] [blame] | 4 | * See the file AUTHORS included with the NASM distribution for |
| 5 | * the specific copyright holders. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following |
| 9 | * conditions are met: |
| 10 | * |
| 11 | * * Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * * Redistributions in binary form must reproduce the above |
| 14 | * copyright notice, this list of conditions and the following |
| 15 | * disclaimer in the documentation and/or other materials provided |
| 16 | * with the distribution. |
Cyrill Gorcunov | beaef4a | 2009-10-30 11:29:43 +0300 | [diff] [blame] | 17 | * |
H. Peter Anvin | 9e6747c | 2009-06-28 17:13:04 -0700 | [diff] [blame] | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
| 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
| 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 29 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 30 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | * ----------------------------------------------------------------------- */ |
| 33 | |
H. Peter Anvin | fe50195 | 2007-10-02 21:53:51 -0700 | [diff] [blame] | 34 | #include "compiler.h" |
| 35 | |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 36 | #include <stdio.h> |
| 37 | #include <stdlib.h> |
| 38 | #include <string.h> |
| 39 | #include <ctype.h> |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 40 | |
| 41 | #include "nasm.h" |
| 42 | #include "nasmlib.h" |
H. Peter Anvin | b20bc73 | 2017-03-07 19:23:03 -0800 | [diff] [blame] | 43 | #include "error.h" |
H. Peter Anvin | 6ecc159 | 2008-06-01 21:34:49 -0700 | [diff] [blame] | 44 | #include "quote.h" |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 45 | #include "stdscan.h" |
| 46 | #include "insns.h" |
| 47 | |
| 48 | /* |
| 49 | * Standard scanner routine used by parser.c and some output |
| 50 | * formats. It keeps a succession of temporary-storage strings in |
| 51 | * stdscan_tempstorage, which can be cleared using stdscan_reset. |
| 52 | */ |
Cyrill Gorcunov | 917117f | 2009-10-29 23:09:18 +0300 | [diff] [blame] | 53 | static char *stdscan_bufptr = NULL; |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 54 | static char **stdscan_tempstorage = NULL; |
| 55 | static int stdscan_tempsize = 0, stdscan_templen = 0; |
| 56 | #define STDSCAN_TEMP_DELTA 256 |
| 57 | |
Cyrill Gorcunov | 917117f | 2009-10-29 23:09:18 +0300 | [diff] [blame] | 58 | void stdscan_set(char *str) |
| 59 | { |
Cyrill Gorcunov | cfbcddf | 2009-10-31 20:05:32 +0300 | [diff] [blame] | 60 | stdscan_bufptr = str; |
Cyrill Gorcunov | 917117f | 2009-10-29 23:09:18 +0300 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | char *stdscan_get(void) |
| 64 | { |
Cyrill Gorcunov | cfbcddf | 2009-10-31 20:05:32 +0300 | [diff] [blame] | 65 | return stdscan_bufptr; |
Cyrill Gorcunov | 917117f | 2009-10-29 23:09:18 +0300 | [diff] [blame] | 66 | } |
| 67 | |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 68 | static void stdscan_pop(void) |
| 69 | { |
| 70 | nasm_free(stdscan_tempstorage[--stdscan_templen]); |
| 71 | } |
| 72 | |
| 73 | void stdscan_reset(void) |
| 74 | { |
| 75 | while (stdscan_templen > 0) |
| 76 | stdscan_pop(); |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Unimportant cleanup is done to avoid confusing people who are trying |
| 81 | * to debug real memory leaks |
| 82 | */ |
| 83 | void stdscan_cleanup(void) |
| 84 | { |
| 85 | stdscan_reset(); |
| 86 | nasm_free(stdscan_tempstorage); |
| 87 | } |
| 88 | |
| 89 | static char *stdscan_copy(char *p, int len) |
| 90 | { |
| 91 | char *text; |
| 92 | |
| 93 | text = nasm_malloc(len + 1); |
H. Peter Anvin | 88c9e1f | 2008-06-04 11:26:59 -0700 | [diff] [blame] | 94 | memcpy(text, p, len); |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 95 | text[len] = '\0'; |
| 96 | |
| 97 | if (stdscan_templen >= stdscan_tempsize) { |
| 98 | stdscan_tempsize += STDSCAN_TEMP_DELTA; |
| 99 | stdscan_tempstorage = nasm_realloc(stdscan_tempstorage, |
| 100 | stdscan_tempsize * |
| 101 | sizeof(char *)); |
| 102 | } |
| 103 | stdscan_tempstorage[stdscan_templen++] = text; |
| 104 | |
| 105 | return text; |
| 106 | } |
| 107 | |
Jin Kyu Song | 72018a2 | 2013-08-05 20:46:18 -0700 | [diff] [blame] | 108 | /* |
| 109 | * a token is enclosed with braces. proper token type will be assigned |
| 110 | * accordingly with the token flag. |
Jin Kyu Song | 72018a2 | 2013-08-05 20:46:18 -0700 | [diff] [blame] | 111 | */ |
| 112 | static int stdscan_handle_brace(struct tokenval *tv) |
| 113 | { |
| 114 | if (!(tv->t_flag & TFLAG_BRC_ANY)) { |
| 115 | /* invalid token is put inside braces */ |
Cyrill Gorcunov | b449ce4 | 2018-12-01 21:02:51 +0300 | [diff] [blame] | 116 | nasm_nonfatal("`%s' is not a valid decorator with braces", tv->t_charptr); |
Jin Kyu Song | 72018a2 | 2013-08-05 20:46:18 -0700 | [diff] [blame] | 117 | tv->t_type = TOKEN_INVALID; |
| 118 | } else if (tv->t_flag & TFLAG_BRC_OPT) { |
| 119 | if (is_reg_class(OPMASKREG, tv->t_integer)) { |
| 120 | /* within braces, opmask register is now used as a mask */ |
| 121 | tv->t_type = TOKEN_OPMASK; |
| 122 | } |
| 123 | } |
| 124 | |
Jin Kyu Song | 72018a2 | 2013-08-05 20:46:18 -0700 | [diff] [blame] | 125 | return tv->t_type; |
| 126 | } |
| 127 | |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 128 | int stdscan(void *private_data, struct tokenval *tv) |
| 129 | { |
| 130 | char ourcopy[MAX_KEYWORD + 1], *r, *s; |
| 131 | |
| 132 | (void)private_data; /* Don't warn that this parameter is unused */ |
| 133 | |
Cyrill Gorcunov | beaef4a | 2009-10-30 11:29:43 +0300 | [diff] [blame] | 134 | stdscan_bufptr = nasm_skip_spaces(stdscan_bufptr); |
Jin Kyu Song | 487f352 | 2013-11-27 14:10:40 -0800 | [diff] [blame] | 135 | if (!*stdscan_bufptr) |
Cyrill Gorcunov | beaef4a | 2009-10-30 11:29:43 +0300 | [diff] [blame] | 136 | return tv->t_type = TOKEN_EOS; |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 137 | |
| 138 | /* we have a token; either an id, a number or a char */ |
H. Peter Anvin | 1350620 | 2018-11-28 14:55:58 -0800 | [diff] [blame] | 139 | if (nasm_isidstart(*stdscan_bufptr) || |
| 140 | (*stdscan_bufptr == '$' && nasm_isidstart(stdscan_bufptr[1]))) { |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 141 | /* now we've got an identifier */ |
H. Peter Anvin | 6867acc | 2007-10-10 14:58:45 -0700 | [diff] [blame] | 142 | bool is_sym = false; |
Jin Kyu Song | 72018a2 | 2013-08-05 20:46:18 -0700 | [diff] [blame] | 143 | int token_type; |
| 144 | |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 145 | if (*stdscan_bufptr == '$') { |
H. Peter Anvin | 6867acc | 2007-10-10 14:58:45 -0700 | [diff] [blame] | 146 | is_sym = true; |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 147 | stdscan_bufptr++; |
| 148 | } |
| 149 | |
| 150 | r = stdscan_bufptr++; |
| 151 | /* read the entire buffer to advance the buffer pointer but... */ |
H. Peter Anvin | 1350620 | 2018-11-28 14:55:58 -0800 | [diff] [blame] | 152 | while (nasm_isidchar(*stdscan_bufptr)) |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 153 | stdscan_bufptr++; |
| 154 | |
| 155 | /* ... copy only up to IDLEN_MAX-1 characters */ |
| 156 | tv->t_charptr = stdscan_copy(r, stdscan_bufptr - r < IDLEN_MAX ? |
| 157 | stdscan_bufptr - r : IDLEN_MAX - 1); |
| 158 | |
| 159 | if (is_sym || stdscan_bufptr - r > MAX_KEYWORD) |
| 160 | return tv->t_type = TOKEN_ID; /* bypass all other checks */ |
| 161 | |
| 162 | for (s = tv->t_charptr, r = ourcopy; *s; s++) |
H. Peter Anvin | ac8f8fc | 2008-06-11 15:49:41 -0700 | [diff] [blame] | 163 | *r++ = nasm_tolower(*s); |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 164 | *r = '\0'; |
| 165 | /* right, so we have an identifier sitting in temp storage. now, |
| 166 | * is it actually a register or instruction name, or what? */ |
Jin Kyu Song | 72018a2 | 2013-08-05 20:46:18 -0700 | [diff] [blame] | 167 | token_type = nasm_token_hash(ourcopy, tv); |
| 168 | |
Cyrill Gorcunov | b449ce4 | 2018-12-01 21:02:51 +0300 | [diff] [blame] | 169 | if (unlikely(tv->t_flag & TFLAG_WARN)) { |
H. Peter Anvin (Intel) | 723ab48 | 2018-12-13 21:53:31 -0800 | [diff] [blame] | 170 | /*! |
| 171 | *!ptr [on] non-NASM keyword used in other assemblers |
| 172 | *! warns about keywords used in other assemblers that might |
| 173 | *! indicate a mistake in the source code. Currently only the MASM |
| 174 | *! \c{PTR} keyword is recognized. |
| 175 | */ |
H. Peter Anvin (Intel) | 5df6ca7 | 2018-12-18 12:25:11 -0800 | [diff] [blame^] | 176 | nasm_warn(WARN_PTR, "`%s' is not a NASM keyword", |
Cyrill Gorcunov | b449ce4 | 2018-12-01 21:02:51 +0300 | [diff] [blame] | 177 | tv->t_charptr); |
| 178 | } |
H. Peter Anvin | 69550ea | 2016-05-09 12:05:56 -0700 | [diff] [blame] | 179 | |
Jin Kyu Song | 487f352 | 2013-11-27 14:10:40 -0800 | [diff] [blame] | 180 | if (likely(!(tv->t_flag & TFLAG_BRC))) { |
| 181 | /* most of the tokens fall into this case */ |
| 182 | return token_type; |
Jin Kyu Song | 72018a2 | 2013-08-05 20:46:18 -0700 | [diff] [blame] | 183 | } else { |
Jin Kyu Song | 487f352 | 2013-11-27 14:10:40 -0800 | [diff] [blame] | 184 | return tv->t_type = TOKEN_ID; |
Jin Kyu Song | 72018a2 | 2013-08-05 20:46:18 -0700 | [diff] [blame] | 185 | } |
H. Peter Anvin | 1350620 | 2018-11-28 14:55:58 -0800 | [diff] [blame] | 186 | } else if (*stdscan_bufptr == '$' && !nasm_isnumchar(stdscan_bufptr[1])) { |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 187 | /* |
| 188 | * It's a $ sign with no following hex number; this must |
| 189 | * mean it's a Here token ($), evaluating to the current |
| 190 | * assembly location, or a Base token ($$), evaluating to |
| 191 | * the base of the current segment. |
| 192 | */ |
| 193 | stdscan_bufptr++; |
| 194 | if (*stdscan_bufptr == '$') { |
| 195 | stdscan_bufptr++; |
| 196 | return tv->t_type = TOKEN_BASE; |
| 197 | } |
| 198 | return tv->t_type = TOKEN_HERE; |
H. Peter Anvin | 1350620 | 2018-11-28 14:55:58 -0800 | [diff] [blame] | 199 | } else if (nasm_isnumstart(*stdscan_bufptr)) { /* now we've got a number */ |
H. Peter Anvin | 7005596 | 2007-10-11 00:05:31 -0700 | [diff] [blame] | 200 | bool rn_error; |
Cyrill Gorcunov | cfbcddf | 2009-10-31 20:05:32 +0300 | [diff] [blame] | 201 | bool is_hex = false; |
| 202 | bool is_float = false; |
| 203 | bool has_e = false; |
| 204 | char c; |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 205 | |
H. Peter Anvin | bea0bbb | 2007-10-22 16:53:48 -0700 | [diff] [blame] | 206 | r = stdscan_bufptr; |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 207 | |
Cyrill Gorcunov | cfbcddf | 2009-10-31 20:05:32 +0300 | [diff] [blame] | 208 | if (*stdscan_bufptr == '$') { |
| 209 | stdscan_bufptr++; |
| 210 | is_hex = true; |
| 211 | } |
H. Peter Anvin | 2ef4aac | 2007-10-19 13:10:46 -0700 | [diff] [blame] | 212 | |
Cyrill Gorcunov | cfbcddf | 2009-10-31 20:05:32 +0300 | [diff] [blame] | 213 | for (;;) { |
| 214 | c = *stdscan_bufptr++; |
H. Peter Anvin | 2ef4aac | 2007-10-19 13:10:46 -0700 | [diff] [blame] | 215 | |
Cyrill Gorcunov | cfbcddf | 2009-10-31 20:05:32 +0300 | [diff] [blame] | 216 | if (!is_hex && (c == 'e' || c == 'E')) { |
| 217 | has_e = true; |
| 218 | if (*stdscan_bufptr == '+' || *stdscan_bufptr == '-') { |
| 219 | /* |
| 220 | * e can only be followed by +/- if it is either a |
| 221 | * prefixed hex number or a floating-point number |
| 222 | */ |
| 223 | is_float = true; |
| 224 | stdscan_bufptr++; |
| 225 | } |
| 226 | } else if (c == 'H' || c == 'h' || c == 'X' || c == 'x') { |
| 227 | is_hex = true; |
| 228 | } else if (c == 'P' || c == 'p') { |
| 229 | is_float = true; |
| 230 | if (*stdscan_bufptr == '+' || *stdscan_bufptr == '-') |
| 231 | stdscan_bufptr++; |
H. Peter Anvin | 1350620 | 2018-11-28 14:55:58 -0800 | [diff] [blame] | 232 | } else if (nasm_isnumchar(c)) |
Cyrill Gorcunov | cfbcddf | 2009-10-31 20:05:32 +0300 | [diff] [blame] | 233 | ; /* just advance */ |
| 234 | else if (c == '.') |
| 235 | is_float = true; |
| 236 | else |
| 237 | break; |
| 238 | } |
| 239 | stdscan_bufptr--; /* Point to first character beyond number */ |
H. Peter Anvin | 2ef4aac | 2007-10-19 13:10:46 -0700 | [diff] [blame] | 240 | |
Cyrill Gorcunov | cfbcddf | 2009-10-31 20:05:32 +0300 | [diff] [blame] | 241 | if (has_e && !is_hex) { |
| 242 | /* 1e13 is floating-point, but 1e13h is not */ |
| 243 | is_float = true; |
| 244 | } |
H. Peter Anvin | 37d88e4 | 2007-10-19 14:10:35 -0700 | [diff] [blame] | 245 | |
Cyrill Gorcunov | cfbcddf | 2009-10-31 20:05:32 +0300 | [diff] [blame] | 246 | if (is_float) { |
| 247 | tv->t_charptr = stdscan_copy(r, stdscan_bufptr - r); |
| 248 | return tv->t_type = TOKEN_FLOAT; |
| 249 | } else { |
| 250 | r = stdscan_copy(r, stdscan_bufptr - r); |
| 251 | tv->t_integer = readnum(r, &rn_error); |
| 252 | stdscan_pop(); |
| 253 | if (rn_error) { |
| 254 | /* some malformation occurred */ |
| 255 | return tv->t_type = TOKEN_ERRNUM; |
| 256 | } |
| 257 | tv->t_charptr = NULL; |
| 258 | return tv->t_type = TOKEN_NUM; |
| 259 | } |
H. Peter Anvin | 6ecc159 | 2008-06-01 21:34:49 -0700 | [diff] [blame] | 260 | } else if (*stdscan_bufptr == '\'' || *stdscan_bufptr == '"' || |
Cyrill Gorcunov | cfbcddf | 2009-10-31 20:05:32 +0300 | [diff] [blame] | 261 | *stdscan_bufptr == '`') { |
| 262 | /* a quoted string */ |
| 263 | char start_quote = *stdscan_bufptr; |
| 264 | tv->t_charptr = stdscan_bufptr; |
| 265 | tv->t_inttwo = nasm_unquote(tv->t_charptr, &stdscan_bufptr); |
| 266 | if (*stdscan_bufptr != start_quote) |
| 267 | return tv->t_type = TOKEN_ERRSTR; |
| 268 | stdscan_bufptr++; /* Skip final quote */ |
H. Peter Anvin | 1162704 | 2008-06-09 20:45:19 -0700 | [diff] [blame] | 269 | return tv->t_type = TOKEN_STR; |
Jin Kyu Song | 487f352 | 2013-11-27 14:10:40 -0800 | [diff] [blame] | 270 | } else if (*stdscan_bufptr == '{') { |
| 271 | /* now we've got a decorator */ |
| 272 | int token_len; |
| 273 | |
| 274 | stdscan_bufptr = nasm_skip_spaces(stdscan_bufptr); |
| 275 | |
| 276 | r = ++stdscan_bufptr; |
| 277 | /* |
| 278 | * read the entire buffer to advance the buffer pointer |
| 279 | * {rn-sae}, {rd-sae}, {ru-sae}, {rz-sae} contain '-' in tokens. |
| 280 | */ |
H. Peter Anvin | 1350620 | 2018-11-28 14:55:58 -0800 | [diff] [blame] | 281 | while (nasm_isbrcchar(*stdscan_bufptr)) |
Jin Kyu Song | 487f352 | 2013-11-27 14:10:40 -0800 | [diff] [blame] | 282 | stdscan_bufptr++; |
| 283 | |
| 284 | token_len = stdscan_bufptr - r; |
| 285 | |
| 286 | /* ... copy only up to DECOLEN_MAX-1 characters */ |
| 287 | tv->t_charptr = stdscan_copy(r, token_len < DECOLEN_MAX ? |
| 288 | token_len : DECOLEN_MAX - 1); |
| 289 | |
| 290 | stdscan_bufptr = nasm_skip_spaces(stdscan_bufptr); |
| 291 | /* if brace is not closed properly or token is too long */ |
| 292 | if ((*stdscan_bufptr != '}') || (token_len > MAX_KEYWORD)) { |
Cyrill Gorcunov | b449ce4 | 2018-12-01 21:02:51 +0300 | [diff] [blame] | 293 | nasm_nonfatal("invalid decorator token inside braces"); |
Jin Kyu Song | 487f352 | 2013-11-27 14:10:40 -0800 | [diff] [blame] | 294 | return tv->t_type = TOKEN_INVALID; |
| 295 | } |
| 296 | |
| 297 | stdscan_bufptr++; /* skip closing brace */ |
| 298 | |
| 299 | for (s = tv->t_charptr, r = ourcopy; *s; s++) |
| 300 | *r++ = nasm_tolower(*s); |
| 301 | *r = '\0'; |
| 302 | |
| 303 | /* right, so we have a decorator sitting in temp storage. */ |
| 304 | nasm_token_hash(ourcopy, tv); |
| 305 | |
| 306 | /* handle tokens inside braces */ |
| 307 | return stdscan_handle_brace(tv); |
H. Peter Anvin | 6ecc159 | 2008-06-01 21:34:49 -0700 | [diff] [blame] | 308 | } else if (*stdscan_bufptr == ';') { |
| 309 | /* a comment has happened - stay */ |
Cyrill Gorcunov | beaef4a | 2009-10-30 11:29:43 +0300 | [diff] [blame] | 310 | return tv->t_type = TOKEN_EOS; |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 311 | } else if (stdscan_bufptr[0] == '>' && stdscan_bufptr[1] == '>') { |
H. Peter Anvin | 94adf7d | 2018-06-15 18:37:32 -0700 | [diff] [blame] | 312 | if (stdscan_bufptr[2] == '>') { |
| 313 | stdscan_bufptr += 3; |
| 314 | return tv->t_type = TOKEN_SAR; |
| 315 | } else { |
| 316 | stdscan_bufptr += 2; |
| 317 | return tv->t_type = TOKEN_SHR; |
| 318 | } |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 319 | } else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '<') { |
H. Peter Anvin | 94adf7d | 2018-06-15 18:37:32 -0700 | [diff] [blame] | 320 | stdscan_bufptr += stdscan_bufptr[2] == '<' ? 3 : 2; |
H. Peter Anvin | 74cc5e5 | 2007-08-30 22:35:34 +0000 | [diff] [blame] | 321 | return tv->t_type = TOKEN_SHL; |
| 322 | } else if (stdscan_bufptr[0] == '/' && stdscan_bufptr[1] == '/') { |
| 323 | stdscan_bufptr += 2; |
| 324 | return tv->t_type = TOKEN_SDIV; |
| 325 | } else if (stdscan_bufptr[0] == '%' && stdscan_bufptr[1] == '%') { |
| 326 | stdscan_bufptr += 2; |
| 327 | return tv->t_type = TOKEN_SMOD; |
| 328 | } else if (stdscan_bufptr[0] == '=' && stdscan_bufptr[1] == '=') { |
| 329 | stdscan_bufptr += 2; |
| 330 | return tv->t_type = TOKEN_EQ; |
| 331 | } else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '>') { |
| 332 | stdscan_bufptr += 2; |
| 333 | return tv->t_type = TOKEN_NE; |
| 334 | } else if (stdscan_bufptr[0] == '!' && stdscan_bufptr[1] == '=') { |
| 335 | stdscan_bufptr += 2; |
| 336 | return tv->t_type = TOKEN_NE; |
| 337 | } else if (stdscan_bufptr[0] == '<' && stdscan_bufptr[1] == '=') { |
| 338 | stdscan_bufptr += 2; |
| 339 | return tv->t_type = TOKEN_LE; |
| 340 | } else if (stdscan_bufptr[0] == '>' && stdscan_bufptr[1] == '=') { |
| 341 | stdscan_bufptr += 2; |
| 342 | return tv->t_type = TOKEN_GE; |
| 343 | } else if (stdscan_bufptr[0] == '&' && stdscan_bufptr[1] == '&') { |
| 344 | stdscan_bufptr += 2; |
| 345 | return tv->t_type = TOKEN_DBL_AND; |
| 346 | } else if (stdscan_bufptr[0] == '^' && stdscan_bufptr[1] == '^') { |
| 347 | stdscan_bufptr += 2; |
| 348 | return tv->t_type = TOKEN_DBL_XOR; |
| 349 | } else if (stdscan_bufptr[0] == '|' && stdscan_bufptr[1] == '|') { |
| 350 | stdscan_bufptr += 2; |
| 351 | return tv->t_type = TOKEN_DBL_OR; |
| 352 | } else /* just an ordinary char */ |
| 353 | return tv->t_type = (uint8_t)(*stdscan_bufptr++); |
| 354 | } |