Example #1
0
/*
 * given a char, return a bool
 * set to true iff the char is between '0' & '9' inclusive
 */
wycc_obj* wycc__isDigit(wycc_obj* itm) {
    WY_OBJ_SANE(itm, "wycc__isDigit");
    long val;
    int ans;

    val = -1;
    if (itm->typ == Wy_Int) {
	val = (long) itm->ptr;
    } else if (itm->typ == Wy_Char) {
	val = (long) itm->ptr;
    } else if (itm->typ == Wy_Byte) {
	val = (long) itm->ptr;
    } else {
	WY_PANIC("Help needed in wycc__isLetter for type %d\n"
		, itm->typ);
	exit(-3);
    };
    if (val < 0) {
	return wycc_box_bool(0);
    };
    ans = 1;
    if (val < '0') {
	ans = 0;
    } else if (val > '9') {
	ans = 0;
    };
    return wycc_box_bool(ans);
}
/*
 * given a char, return a bool
 * set to true iff the char is space, tab, newline, return
 * fails to check for formfeed (\f), vertical tab (\v)
 */
wycc_obj* wycc__isWhiteSpace(wycc_obj* itm) {
    WY_OBJ_SANE(itm, "wycc__isWhiteSpace");
    int ans;
    long val;

    val = -1;
    if (itm->typ == Wy_Int) {
	val = (long) itm->ptr;
    } else if (itm->typ == Wy_Char) {
	val = (long) itm->ptr;
    } else if (itm->typ == Wy_Byte) {
	val = (long) itm->ptr;
    } else {
	WY_PANIC("Help needed in wycc__isWhiteSpace for type %d\n"
		, itm->typ);
	exit(-3);
    };
    ans = 0;
    if (val == ' ') {
	ans = 1;
    } else if (val == '\t') {
	ans = 1;
    } else if (val == '\n') {
	ans = 1;
    } else if (val == '\r') {
	ans = 1;
    };
    return wycc_box_bool(ans);
}
/*
 * given a int, byte, or char, return a bool.
 * true if the code is for lower case ASCII letter.
 */
wycc_obj* wycc__isLowerCase(wycc_obj* itm) {
    WY_OBJ_SANE(itm, "wycc__isLowerCase");
    long val;
    int ans;

    val = -1;
    if (itm->typ == Wy_Int) {
	val = (long) itm->ptr;
    } else if (itm->typ == Wy_Char) {
	val = (long) itm->ptr;
    } else if (itm->typ == Wy_Byte) {
	val = (long) itm->ptr;
    } else {
	WY_PANIC("Help needed in wycc__isLowerCase for type %d\n"
		, itm->typ);
	exit(-3);
    };
    ans = 0;
    if ((val >= 'a') && (val <= 'z')) {
	ans = 1;
    };
    return wycc_box_bool(ans);
}