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