Changeset 1ef0fc3 in mainline for uspace/app/sbi/src/lex.c
- Timestamp:
- 2010-04-10T11:19:18Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d7e45c8
- Parents:
- 2721a75 (diff), 074444f (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
r2721a75 r1ef0fc3 53 53 static bool_t is_digit(char c); 54 54 static void lex_word(lex_t *lex); 55 static void lex_char(lex_t *lex); 55 56 static void lex_number(lex_t *lex); 56 57 static void lex_string(lex_t *lex); … … 74 75 static struct lc_name keywords[] = { 75 76 { lc_as, "as" }, 77 { lc_bool, "bool" }, 78 { lc_char, "char" }, 76 79 { lc_builtin, "builtin" }, 77 80 { lc_class, "class" }, … … 81 84 { lc_end, "end" }, 82 85 { lc_except, "except" }, 86 { lc_false, "false" }, 83 87 { lc_finally, "finally" }, 84 88 { lc_for, "for" }, … … 108 112 { lc_then, "then" }, 109 113 { lc_this, "this" }, 114 { lc_true, "true" }, 110 115 { lc_var, "var" }, 111 116 { lc_with, "with" }, … … 338 343 } 339 344 345 if (bp[0] == '\'') { 346 lex_char(lex); 347 return b_true; 348 } 349 340 350 if (is_digit(bp[0])) { 341 351 lex_number(lex); … … 460 470 lex->current.lclass = lc_ident; 461 471 lex->current.u.ident.sid = strtab_get_sid(ident_buf); 472 } 473 474 /** Lex a character literal. 475 * 476 * Reads in a character literal and stores it in the current lem in @a lex. 477 * 478 * @param lex Lexer object. 479 */ 480 static void lex_char(lex_t *lex) 481 { 482 char *bp; 483 int idx; 484 size_t len; 485 int char_val; 486 487 bp = lex->ibp + 1; 488 idx = 0; 489 490 while (bp[idx] != '\'') { 491 if (idx >= SLBUF_SIZE) { 492 printf("Error: Character literal too long.\n"); 493 exit(1); 494 } 495 496 if (bp[idx] == '\0') { 497 printf("Error: Unterminated character literal.\n"); 498 exit(1); 499 } 500 501 strlit_buf[idx] = bp[idx]; 502 ++idx; 503 } 504 505 lex->ibp = bp + idx + 1; 506 507 strlit_buf[idx] = '\0'; 508 len = os_str_length(strlit_buf); 509 if (len != 1) { 510 printf("Character literal should contain one character, " 511 "but contains %u characters instead.\n", (unsigned) len); 512 exit(1); 513 } 514 515 os_str_get_char(strlit_buf, 0, &char_val); 516 lex->current.lclass = lc_lit_char; 517 bigint_init(&lex->current.u.lit_char.value, char_val); 462 518 } 463 519
Note:
See TracChangeset
for help on using the changeset viewer.