struct expression *parse_fcall(FILE *fp) { enum token_class t; struct expression *ex; ex = malloc(sizeof(struct expression)); if (!ex) { fputs("Memory error\n", stderr); exit(1); } ex->id = strdup(id); t = token(fp); if (t == TOKEN_RP || t == TOKEN_COMMA || t == TOKEN_EOF) { token_undo(fp, t); ex->subex = NULL; ex->subex_count = 0; } else { parse_lp(fp, t); ex->subex = parse_fcalls(fp); ex->subex_count = count; } return ex; }
struct declarations *parse_decls(void) { struct declarations *declarations = calloc(1, sizeof(struct declarations)); vardecllist_t lp; vardecllist_t gp; int local_first = 1; if (current_lang == LANG_FR && lookahead[0]->type == PARAM) { eat(PARAM); if (lookahead[0]->type == LOCAL) { lp = parse_lp(); if (lookahead[0]->type == PARAM) { eat(PARAM); gp = parse_gp(); } else list_init(gp); } else if (lookahead[0]->type == GLOBAL) { local_first = 0; gp = parse_gp(); if (lookahead[0]->type == PARAM) { eat(PARAM); lp = parse_lp(); } else list_init(lp); } else syntaxerror("Expected \"local\" or \"global\""); } else if (current_lang == LANG_EN && lookahead[1]->type == PARAM) { if (lookahead[0]->type == LOCAL) { eat(LOCAL); lp = parse_lp(); if (lookahead[1]->type == PARAM) { eat(GLOBAL); gp = parse_gp(); } else list_init(gp); } else if(lookahead[0]->type == GLOBAL) { eat(GLOBAL); gp = parse_gp(); if (lookahead[1]->type == PARAM) { eat(LOCAL); lp = parse_lp(); } else list_init(lp); } else syntaxerror("Expected \"local\" or \"global\""); } else { list_init(lp); list_init(gp); } if (lookahead[0]->type == VARIABLES) { eat(VARIABLES); eat(EOL); declarations->var_decl = parse_vardecls(); if (lookahead[0]->type == CONST) { declarations->const_decls = parse_constdecls(); if (lookahead[0]->type == TYPES) declarations->type_decls = parse_typedecls(); } else if (lookahead[0]->type == TYPES) { declarations->type_decls = parse_typedecls(); if (lookahead[0]->type == CONST) declarations->const_decls = parse_constdecls(); } } else if (lookahead[0]->type == CONST) { declarations->const_decls = parse_constdecls(); if (lookahead[0]->type == VARIABLES) { eat(VARIABLES); eat(EOL); declarations->var_decl = parse_vardecls(); if (lookahead[0]->type == TYPES) declarations->type_decls = parse_typedecls(); } else if (lookahead[0]->type == TYPES) { declarations->type_decls = parse_typedecls(); if (lookahead[0]->type == VARIABLES) { eat(VARIABLES); eat(EOL); declarations->var_decl = parse_vardecls(); } } } else if (lookahead[0]->type == TYPES) { declarations->type_decls = parse_typedecls(); if (lookahead[0]->type == CONST) { declarations->const_decls = parse_constdecls(); if (lookahead[0]->type == VARIABLES) { eat(VARIABLES); eat(EOL); declarations->var_decl = parse_vardecls(); } } else if (lookahead[0]->type == VARIABLES) { eat(VARIABLES); eat(EOL); declarations->var_decl = parse_vardecls(); if (lookahead[0]->type == CONST) declarations->const_decls = parse_constdecls(); } } declarations->param_decl = make_param_decl(local_first, lp, gp); return declarations; }