Ejemplo n.º 1
0
Archivo: parser2.c Proyecto: tungvx/FSE
static AST funcdecl() {
    Token *t = &tok;
    AST a=0;
    AST a1=0,a2=0,a3=0,a4=0;
    AST ftype;

    a2 = retdecl();
    a1 = name();
    ftype = func_type(gen(fLOCAL),a2);
    insert_SYM(get_text(a1), ftype, fLOCAL, 0/* dummy */);

    if (t->sym == '(') { /* must be func */
	gettoken();

	mark_args();
	a3 = argdecls();
	if (checkFuncExist(get_text(a1), a3)) parse_error("Duplicated function definition");
	set_argtypeofnode(ftype,a3);

	if (t->sym == ')') gettoken();
	else parse_error("expected )");

	a4 = block();
	unmark_args();
	a  = make_AST_funcdecl(a1,a2,a3,a4);

    } else {
	parse_error("expected (");
    }
    return a;
}
Ejemplo n.º 2
0
static node_t *func_or_array(bool abstract, int *params)
{
    node_t *ty = NULL;
    int follow[] = { '[', ID, IF, 0 };

    for (; token->id == '(' || token->id == '[';) {
        if (token->id == '[') {
            node_t *atype;
            expect('[');
            atype = arrays(abstract);
            match(']', follow);
            attach_type(&ty, atype);
        } else {
            node_t *ftype = func_type();
            expect('(');
            TYPE_PARAMS(ftype) = parameters(ftype, params);
            match(')', follow);
            attach_type(&ty, ftype);
        }
    }

    return ty;
}
Ejemplo n.º 3
0
Archivo: parser2.c Proyecto: tungvx/FSE
static AST vardecl() { /* TODO: allow vars */
    Token *t = &tok;
    AST a=0;
    AST a1=0,a2=0,a3=0,a4=0;
    AST ft;
    int idx;

    a2 = typedecl();
    a1 = var();		

    if (t->sym == '(') { /* oops, it was func */
	gettoken();
	set_nodetype(a1, nNAME); /* change to NAME */
	insert_SYM(get_text(a1), ft=func_type(gen(fLOCAL),a2), fLOCAL,0 /* dummy */ );

	a3 = argdecls();
	set_argtypeofnode(ft,a3);

	if (t->sym == ')') gettoken();
	else parse_error("expected )");

	a4 = block();
	a  = make_AST_funcdecl(a1, a2, a3, a4);
    } else if (t->sym == ';') { /* vardecl */
	a = make_AST_vardecl(a1, a2, 0, 0);
	idx = insert_SYM(get_text(a1), a2, vLOCAL, a1); 
	set_ival(a1,idx);
	/*
	   } else if (t->sym == ',') {  // multiple vars 
	 *     contents must be made
	 *
	 */
    } else {
	parse_error("expected ; or (");
    }
    return a;
}