static funcdef_t* parse_funcdef(parser_t* p, bool is_inline) { funcdef_t* funcdef = (funcdef_t*)malloc(sizeof(funcdef_t)); funcdef->line_number = p->t->line_number; match(p, TT_DEF); if (!is_inline) { match(p, TT_IDENT); strcpy(funcdef->name, ((char*)(p->t->token_value))); } funcdef->parameters = create_list(); token_type_t tok = get_token(p->t); if (TT_OP_POPEN == tok) { tok = get_token(p->t); if (TT_OP_PCLOSE != tok) { unget_token(p->t); do { list_insert(funcdef->parameters, parse_vardecl(p)); get_token(p->t); } while (TT_OP_COMMA == p->t->token_type); } expect(p, TT_OP_PCLOSE); } else { unget_token(p->t); } funcdef->block = parse_block(p); match(p, TT_END); return funcdef; }
vardecllist_t parse_vardecls() { vardecllist_t vardecllist = empty_vardecllist(); while (lookahead[0]->type != BEGIN && lookahead[0]->type != TYPES && lookahead[0]->type != CONST && lookahead[0]->type != VARIABLES && lookahead[0]->type != PARAM && lookahead[0]->type != END && lookahead[0]->type != LOCAL && lookahead[0]->type != GLOBAL) list_push_back(vardecllist, parse_vardecl()); return vardecllist; }