Ejemplo n.º 1
0
static void init_dfas(struct nfa *sstate, struct set *accept)
{
	struct accept *acp;
	struct set *first;
	int i;
	/* alloc dfa buffer */
	dfastates = xmalloc(MAX_DFAS * sizeof(struct dfa));
	/* init dfas */
	for (i = 0; i < MAX_DFAS; i++) {
		dfastates[i].group = -1;
		dfastates[i].states = NULL;
		dfastates[i].accept = NULL;
	}
	/* init first dfa state */
	first = newset();
	addset(first, nfastate(sstate));
	epsilon_closure(first, &acp, 0);
	/* NOTE: first dfa can be accepted, such as regexp: `.*` */
	if (acp) {
		dfastates[ndfas].accept = getaccept(acp);
		addset(accept, 0);
	}
	dfastates[0].states = first;
	/* some internal parmaters */
	ndfas = 1;
	currentdfa = 0;
}
Ejemplo n.º 2
0
Archivo: dfa.c Proyecto: cleardo/lex
PRIVATE void make_tran(int sstate)
{
	SET *NFA_set;
	
	DFA_STATE *current;

	int nextstate;

	char *isaccept;

	int anchor;

	int c;

	NFA_set = newset();

	put('\n', stderr);

	free_sets();
}
Ejemplo n.º 3
0
SET *init()
{
	 SET *s;
	 int e;
	 char ch;
	 s=newset();
	 printf("Doriti initializarea? ");
	 fflush(stdin);
	 scanf("%c",&ch);
	 while((ch=='D')||(ch=='d'))
		{
		 printf("Introduceti elem de inserat :  ");
		 fflush(stdin);
		 scanf("%d",&e);
		 if (!in(e,s))s=insert(e,s);
			 printf("Continuati ? ");
		 fflush(stdin);
		 scanf("%c",&ch);
		}

	 return(s);
}
Ejemplo n.º 4
0
/*
 * subset construction:
 * convert NFA directed graph to DFA table
 *
 * RETURN:
 * 	@table        dfa state transtion table
 * 	@acceptset    dfa acceptable state set
 * 	return value  dfa state transtion table size
 */
int construct_dfa(struct nfa *sstate, int (**table)[], struct set **acceptset)
{
	/* dfatable[STATES][CHARS] */
	int (*dfatable)[MAX_CHARS];
	struct set *accept;
	int i;

	/* init dfa table */
	dfatable = xmalloc(MAX_TABLESIZE * sizeof(int));

	/* alloc accept set */
	accept = newset();

	/*
	 * init internal dfa auxiliary method,
	 *  which is used in subsetconstruct()
	 */
	init_dfas(sstate, accept);

	/* subset construction */
	subsetconstruct(dfatable, accept);

	/* adjust dfatable real size */
	dfatable = realloc(dfatable, ndfas * MAX_CHARS * sizeof(int));

	/* return value */
	if (table)
		*table = dfatable;
	else
		free(dfatable);
	if (acceptset)
		*acceptset = accept;
	else
		freeset(accept);

	return ndfas;
}