Exemple #1
0
fun_def_t parse_fun_def(tokenizer_t t)
{
    // 型宣言を食べる (int 以外に増やすなら変える)
    eat_it(t, TOK_INT);

    struct token tok = cur_tok(t);
    char *f = strdup(tok.name);
    eat_it(t, TOK_ID);


    // {
    eat_it(t, TOK_LPAREN);
    var_decl_list_t params = mk_var_decl_list(t);

    while(1){
        if(cur_tok(t).kind == TOK_RPAREN){
            break;
        }else{
            var_decl_list_add(params, parse_param(t));
            if(cur_tok(t).kind == TOK_COMMA){
                eat_it(t, TOK_COMMA);
                continue;
            }else{
                break;
            }
        }
    }
    eat_it(t, TOK_RPAREN);
    // }

    stmt_t body = parse_stmt_compound(t);
    return mk_fun_def(t->filename, t->line, f, params, body);
}
Exemple #2
0
fun_def_t parse_fun_difinition(tokenizer_t t) {
    char * filename = cur_tok(t).filename;
    int line = cur_tok(t).line_num;
    parse_type_expr(t);
    char *f0;
    char *f;
    f0 = parse_identifier(t);
    f = (char *)malloc(sizeof(char) * strlen(f0) + 1);
    strcpy(f, f0);
    eat_it(t, TOK_LPAREN);
    var_decl_list_t param = parse_para_list(t);
    eat_it(t, TOK_RPAREN);
    stmt_t body = parse_comp_stmt(t);
    return mk_fun_def(filename, line, f, param, body);
}