cs152coin/cs152coin.c
// This function is already implemented as an example of how to use the parser
This function is already implemented as an example of how to use the parser
This function is already implemented as an example of how to use the parser
dep_wd_t* parse_dep_wd()
{
    char* s = NULL;
    double d = 0;
    if (!read_string(&s)) return NULL;
    dep_wd_type type;
    if (!strcmp(s, "DEPOSIT")) {
        type = DEPOSIT;
    } else if (!strcmp(s, "WITHDRAWAL")) {
        type = WITHDRAWAL;
    } else {
        return NULL;
    }
    next_token();
    dep_wd_t* dw = calloc(1, sizeof(dep_wd_t));
    if (dw == NULL) {
        return NULL;
    }
    dw->type = type;
    if (!read_string(&s)) {
        dep_wd_free(dw);
        return NULL;
    }
    dw->addr = strdup(s);
    next_token();
    if (!read_double(&d)) {
        dep_wd_free(dw);
        return NULL;
    }
    dw->amount = d;
    next_token();
    return dw;
}
dep_wd_t * parse_dep_wd ( ) { char * s = NULL ; double d = 0 ; if ( ! read_string ( & s ) ) return NULL ; dep_wd_type type ; if ( ! strcmp ( s , " " ) ) { type = DEPOSIT ; } else if ( ! strcmp ( s , " " ) ) { type = WITHDRAWAL ; } else { return NULL ; } next_token ( ) ; dep_wd_t * dw = calloc ( 1 , sizeof ( dep_wd_t ) ) ; if ( dw == NULL ) { return NULL ; } dw -> type = type ; if ( ! read_string ( & s ) ) { dep_wd_free ( dw ) ; return NULL ; } dw -> addr = strdup ( s ) ; next_token ( ) ; if ( ! read_double ( & d ) ) { dep_wd_free ( dw ) ; return NULL ; } dw -> amount = d ; next_token ( ) ; return dw ; }
This function is already implemented as an example of how to use the parser
This function is already implemented as an example of how to use the parser