Example #1
0
/**
 * evaluate one initializer, add data to table
 * @param symbol_name
 * @param type
 * @param identity
 * @param dim
 * @param tag
 * @return
 *	returns size of initializer, or 0 for none (a null string is size 1)
 *
 */
int init(char *symbol_name, int type, int identity, int *dim, TAG_SYMBOL *tag) {
    int value, n;

    /* A pointer is initialized as a word holding the address of the struct
       or string etc that directly follows */
    if(identity == POINTER) {
        int x = getlabel();
        gen_def_word();
        print_label(x);
        newline();
        print_label(x);
        output_label_terminator();
        newline();
    }
    /* FIXME: may need to distinguish const string v data in future */
    if(quoted_string(&n, NULL)) {
        if((identity == VARIABLE) || !(type & CCHAR))
            error("found string: must assign to char pointer or array");
        *dim = *dim - n; /* ??? FIXME arrays of char only */
        return n;
    }

    if (type & CCHAR)
        gen_def_byte();
    else
        gen_def_word();
    if (!number(&value) && !quoted_char(&value))
        return 0;
    *dim = *dim - 1;
    output_number(value);
    newline();
    return (type & CCHAR) ? 1 : 2;
}
Example #2
0
/**
 * "case" label
 */
void docase(void) {
        int     val;

        val = 0;
        if (readswitch ()) {
                if (!number (&val))
                        if (!quoted_char (&val))
                                error ("bad case label");
                addcase (val);
                if (!match (":"))
                        error ("missing colon");
        } else
                error ("no active switch");
}
Example #3
0
int constant(int val[]) {
    if (number (val))
        gen_immediate ();
    else if (quoted_char (val))
        gen_immediate ();
    else if (quoted_string (val)) {
        gen_immediate ();
        print_label (litlab);
        output_byte ('+');
    } else
        return (0);
    output_number (val[0]);
    newline ();
    return (1);
}