Esempio n. 1
0
fa *mkdfa(const char *s, int anchor)	/* does the real work of making a dfa */
/* anchor = 1 for anchored matches, else 0 */
{
    Node *p, *p1;
    fa *f;

    p = reparse(s);
    p1 = op2(CAT, op2(STAR, op2(ALL, NIL, NIL), NIL), p);
    /* put ALL STAR in front of reg.  exp. */
    p1 = op2(CAT, p1, op2(FINAL, NIL, NIL));
    /* put FINAL after reg.  exp. */

    poscnt = 0;
    penter(p1);	/* enter parent pointers and leaf indices */
    if ((f = (fa *) calloc(1, sizeof(fa) + poscnt*sizeof(rrow))) == NULL)
        overflo("out of space for fa");
    f->accept = poscnt-1;	/* penter has computed number of positions in re */
    cfoll(f, p1);	/* set up follow sets */
    freetr(p1);
    if ((f->posns[0] = (int *) calloc(1, *(f->re[0].lfollow)*sizeof(int))) == NULL)
        overflo("out of space in makedfa");
    if ((f->posns[1] = (int *) calloc(1, sizeof(int))) == NULL)
        overflo("out of space in makedfa");
    *f->posns[1] = 0;
    f->initstat = makeinit(f, anchor);
    f->anchor = anchor;
    f->restr = (uschar *) tostring(s);
    return f;
}
Esempio n. 2
0
void freetr(Node *p)	/* free parse tree */
{
	switch (type(p)) {
	LEAF
		xfree(p);
		break;
	UNARY
		freetr(left(p));
		xfree(p);
		break;
	case CAT:
	case OR:
		freetr(left(p));
		freetr(right(p));
		xfree(p);
		break;
	default:	/* can't happen */
		ERROR "can't happen: unknown type %d in freetr", type(p) FATAL;
		break;
	}
}