Changes in uspace/app/sbi/src/lex.c [051b3db8:051bc69a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/lex.c
r051b3db8 r051bc69a 1 1 /* 2 * Copyright (c) 201 1Jiri Svoboda2 * Copyright (c) 2010 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 45 45 #define TAB_WIDTH 8 46 46 47 typedef enum {48 cs_chr,49 cs_str50 } chr_str_t;51 52 47 static void lex_touch(lex_t *lex); 53 48 static bool_t lex_read_try(lex_t *lex); … … 62 57 static void lex_number(lex_t *lex); 63 58 static void lex_string(lex_t *lex); 64 static void lex_char_string_core(lex_t *lex, chr_str_t cs);65 59 static int digit_value(char c); 66 60 … … 123 117 { lc_string, "string" }, 124 118 { lc_struct, "struct" }, 125 { lc_switch, "switch" },126 119 { lc_then, "then" }, 127 120 { lc_this, "this" }, … … 129 122 { lc_var, "var" }, 130 123 { lc_with, "with" }, 131 { lc_when, "when" },132 124 { lc_while, "while" }, 133 125 { lc_yield, "yield" }, … … 543 535 static void lex_char(lex_t *lex) 544 536 { 537 char *bp; 538 int idx; 545 539 size_t len; 546 540 int char_val; 547 541 548 lex_char_string_core(lex, cs_chr); 549 542 bp = lex->ibp + 1; 543 idx = 0; 544 545 while (bp[idx] != '\'') { 546 if (idx >= SLBUF_SIZE) { 547 printf("Error: Character literal too long.\n"); 548 exit(1); 549 } 550 551 if (bp[idx] == '\0') { 552 printf("Error: Unterminated character literal.\n"); 553 exit(1); 554 } 555 556 strlit_buf[idx] = bp[idx]; 557 ++idx; 558 } 559 560 lex->ibp = bp + idx + 1; 561 562 strlit_buf[idx] = '\0'; 550 563 len = os_str_length(strlit_buf); 551 564 if (len != 1) { … … 607 620 static void lex_string(lex_t *lex) 608 621 { 609 lex_char_string_core(lex, cs_str); 622 char *bp; 623 int idx; 624 625 bp = lex->ibp + 1; 626 idx = 0; 627 628 while (bp[idx] != '"') { 629 if (idx >= SLBUF_SIZE) { 630 printf("Error: String literal too long.\n"); 631 exit(1); 632 } 633 634 if (bp[idx] == '\0') { 635 printf("Error: Unterminated string literal.\n"); 636 exit(1); 637 } 638 639 strlit_buf[idx] = bp[idx]; 640 ++idx; 641 } 642 643 lex->ibp = bp + idx + 1; 644 645 strlit_buf[idx] = '\0'; 610 646 611 647 lex->current.lclass = lc_lit_string; 612 648 lex->current.u.lit_string.value = os_str_dup(strlit_buf); 613 }614 615 static void lex_char_string_core(lex_t *lex, chr_str_t cs)616 {617 char *bp;618 int sidx, didx;619 char term;620 const char *descr, *cap_descr;621 char spchar;622 623 /* Make compiler happy */624 term = '\0';625 descr = NULL;626 cap_descr = NULL;627 628 switch (cs) {629 case cs_chr:630 term = '\'';631 descr = "character";632 cap_descr = "Character";633 break;634 case cs_str:635 term = '"';636 descr = "string";637 cap_descr = "String";638 break;639 }640 641 bp = lex->ibp + 1;642 sidx = didx = 0;643 644 while (bp[sidx] != term) {645 if (didx >= SLBUF_SIZE) {646 printf("Error: %s literal too long.\n", cap_descr);647 exit(1);648 }649 650 if (bp[sidx] == '\0') {651 printf("Error: Unterminated %s literal.\n", descr);652 exit(1);653 }654 655 if (bp[sidx] == '\\') {656 switch (bp[sidx + 1]) {657 case '\\':658 spchar = '\\';659 break;660 case '\'':661 spchar = '\'';662 break;663 case '"':664 spchar = '"';665 break;666 case 'n':667 spchar = '\n';668 break;669 case 't':670 spchar = '\t';671 break;672 default:673 printf("Error: Unknown character escape sequence.\n");674 exit(1);675 }676 677 strlit_buf[didx] = spchar;678 ++didx;679 sidx += 2;680 } else {681 strlit_buf[didx] = bp[sidx];682 ++sidx; ++didx;683 }684 }685 686 lex->ibp = bp + sidx + 1;687 688 strlit_buf[didx] = '\0';689 649 } 690 650
Note:
See TracChangeset
for help on using the changeset viewer.