expr_t parse_paren_expr(tokenizer_t t) { eat_it(t, TOK_LPAREN); expr_t expr = parse_expr(t); eat_it(t, TOK_RPAREN); return mk_expr_paren(t->filename, t->line, expr); }
expr_t parse_unary_expr(tokenizer_t t) { char * filename = cur_tok(t).filename; int line = cur_tok(t).line_num; char * f =(char *)safe_malloc(sizeof(char) * 50) ; if(cur_tok(t).kind == TOK_INT_LITERAL) { strcpy(f, cur_tok(t).num); f = (char *)realloc(f, sizeof(char) * strlen(f) + 1); eat_it(t, TOK_INT_LITERAL); return mk_expr_int_literal(filename, line, f); } else if(cur_tok(t).kind == TOK_ID) { strcpy(f, parse_identifier(t)); f = (char *)realloc(f, sizeof(char) * strlen(f) + 1); if(cur_tok(t).kind == TOK_LPAREN) { eat_it(t, TOK_LPAREN); expr_list_t args = parse_arg_expr_list(t); eat_it(t, TOK_RPAREN); return mk_expr_call(filename, line, f, args); } else { return mk_expr_id(filename, line, f); } } else if(cur_tok(t).kind == TOK_LPAREN) { eat_it(t, TOK_LPAREN); expr_t e = parse_expr(t); eat_it(t, TOK_RPAREN); return mk_expr_paren(filename, line, e); } else if((cur_tok(t).kind == TOK_PLUS)|(cur_tok(t).kind == TOK_MINUS)|(cur_tok(t).kind == TOK_BANG)) { op_kind_t op = parse_unary_oper(t); expr_t exp = parse_unary_expr(t); return mk_expr_un_op(filename, line, op, exp); } else { printf("exit_5\n"); exit(1); } }