Changeset 074444f in mainline for uspace/app/sbi/src/lex.c


Ignore:
Timestamp:
2010-04-10T11:15:33Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1ef0fc3, 38aaacc2
Parents:
23de644
Message:

Update SBI to rev. 184.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sbi/src/lex.c

    r23de644 r074444f  
    5353static bool_t is_digit(char c);
    5454static void lex_word(lex_t *lex);
     55static void lex_char(lex_t *lex);
    5556static void lex_number(lex_t *lex);
    5657static void lex_string(lex_t *lex);
     
    7475static struct lc_name keywords[] = {
    7576        { lc_as,        "as" },
     77        { lc_bool,      "bool" },
     78        { lc_char,      "char" },
    7679        { lc_builtin,   "builtin" },
    7780        { lc_class,     "class" },
     
    8184        { lc_end,       "end" },
    8285        { lc_except,    "except" },
     86        { lc_false,     "false" },
    8387        { lc_finally,   "finally" },
    8488        { lc_for,       "for" },
     
    108112        { lc_then,      "then" },
    109113        { lc_this,      "this" },
     114        { lc_true,      "true" },
    110115        { lc_var,       "var" },
    111116        { lc_with,      "with" },
     
    338343        }
    339344
     345        if (bp[0] == '\'') {
     346                lex_char(lex);
     347                return b_true;
     348        }
     349
    340350        if (is_digit(bp[0])) {
    341351                lex_number(lex);
     
    460470        lex->current.lclass = lc_ident;
    461471        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 */
     480static 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);
    462518}
    463519
Note: See TracChangeset for help on using the changeset viewer.