Changeset 640ffe6 in mainline for uspace/app/sbi/src/lex.c
- Timestamp:
- 2010-05-08T08:15:57Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4039c77
- Parents:
- 1317380 (diff), 051bc69a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/lex.c
r1317380 r640ffe6 35 35 #include <stdlib.h> 36 36 #include "bigint.h" 37 #include "cspan.h" 37 38 #include "mytypes.h" 38 39 #include "input.h" … … 74 75 /** Keyword names. Used both for printing and recognition. */ 75 76 static struct lc_name keywords[] = { 77 { lc_and, "and" }, 76 78 { lc_as, "as" }, 77 79 { lc_bool, "bool" }, 80 { lc_break, "break" }, 81 { lc_builtin, "builtin" }, 78 82 { lc_char, "char" }, 79 { lc_builtin, "builtin" },80 83 { lc_class, "class" }, 81 { lc_constructor, "constructor" },82 84 { lc_deleg, "deleg" }, 83 85 { lc_do, "do" }, 86 { lc_elif, "elif" }, 84 87 { lc_else, "else" }, 85 88 { lc_end, "end" }, 89 { lc_enum, "enum" }, 86 90 { lc_except, "except" }, 87 91 { lc_false, "false" }, … … 96 100 { lc_is, "is" }, 97 101 { lc_new, "new" }, 102 { lc_not, "not" }, 98 103 { lc_nil, "nil" }, 104 { lc_or, "or" }, 99 105 { lc_override, "override" }, 100 106 { lc_packed, "packed" }, … … 233 239 void lem_print_coords(lem_t *lem) 234 240 { 235 printf("%d:%d", lem->line_no, lem->col_0);241 cspan_print(lem->cspan); 236 242 } 237 243 … … 255 261 lex->ibp = lex->inbuf; 256 262 lex->col_adj = 0; 263 lex->prev_valid = b_false; 257 264 lex->current_valid = b_true; 258 265 } … … 279 286 * @param lex Lexer object. 280 287 * @return Pointer to current lem. Owned by @a lex and only valid 281 * until next call to lex_ next().288 * until next call to lex_xxx(). 282 289 */ 283 290 lem_t *lex_get_current(lex_t *lex) … … 287 294 } 288 295 296 /** Get previous lem if valid. 297 * 298 * The returned pointer is invalidated by next call to lex_next() 299 * 300 * @param lex Lexer object. 301 * @return Pointer to previous lem. Owned by @a lex and only valid 302 * until next call to lex_xxx(). 303 */ 304 lem_t *lex_peek_prev(lex_t *lex) 305 { 306 if (lex->current_valid == b_false) { 307 /* 308 * This means the head is advanced but next lem was not read. 309 * Thus the previous lem is still in @a current. 310 */ 311 return &lex->current; 312 } 313 314 if (lex->prev_valid != b_true) { 315 /* Looks like we are still at the first lem. */ 316 return NULL; 317 } 318 319 /* 320 * Current lem has been read in. Thus the previous lem was moved to 321 * @a previous. 322 */ 323 return &lex->prev; 324 } 325 289 326 /** Read in the current lexical element (unless already read in). 290 327 * … … 297 334 if (lex->current_valid == b_true) 298 335 return; 336 337 /* Copy previous lem */ 338 lex->prev = lex->current; 339 lex->prev_valid = b_true; 299 340 300 341 do { … … 318 359 static bool_t lex_read_try(lex_t *lex) 319 360 { 320 char *bp; 361 char *bp, *lsp; 362 int line0, col0; 321 363 322 364 lex_skip_ws(lex); … … 328 370 * separately using col_adj. 329 371 */ 330 lex->current.line_no = input_get_line_no(lex->input); 331 lex->current.col_0 = 1 + lex->col_adj + (lex->ibp - lex->inbuf); 332 372 line0 = input_get_line_no(lex->input); 373 col0 = 1 + lex->col_adj + (lex->ibp - lex->inbuf); 374 375 lex->current.cspan = cspan_new(lex->input, line0, col0, line0, col0); 376 377 lsp = lex->ibp; 333 378 bp = lex->ibp; 334 379 … … 336 381 /* End of input */ 337 382 lex->current.lclass = lc_eof; 338 return b_true;383 goto finish; 339 384 } 340 385 341 386 if (is_wstart(bp[0])) { 342 387 lex_word(lex); 343 return b_true;388 goto finish; 344 389 } 345 390 346 391 if (bp[0] == '\'') { 347 392 lex_char(lex); 348 return b_true;393 goto finish; 349 394 } 350 395 351 396 if (is_digit(bp[0])) { 352 397 lex_number(lex); 353 return b_true;398 goto finish; 354 399 } 355 400 356 401 if (bp[0] == '"') { 357 402 lex_string(lex); 358 return b_true;403 goto finish; 359 404 } 360 405 361 406 if (bp[0] == '-' && bp[1] == '-') { 362 407 lex_skip_comment(lex); 408 409 /* Compute ending column number */ 410 lex->current.cspan->col1 = col0 + (lex->ibp - lsp) - 1; 411 412 /* Try again */ 363 413 return b_false; 364 414 } … … 417 467 418 468 lex->ibp = bp; 469 470 finish: 471 /* Compute ending column number */ 472 lex->current.cspan->col1 = col0 + (lex->ibp - lsp) - 1; 419 473 return b_true; 420 474
Note:
See TracChangeset
for help on using the changeset viewer.