コード例 #1
0
ファイル: interpret.c プロジェクト: chobits/tinylex
/*  real recursion computation function */
void e_closure(struct nfa *nfa, struct set *stateset, struct accept **acp)
{
	int state;
	if (!nfa)
		return;

	state = nfastate(nfa);
	/* greedy algorithm: accept as much states as possible */
	if (!nfa->next[0]) {
		if (!nfa->accept)
			errexit("no accept action string");
		if (acp)
			*acp = nfa->accept;
	}

	if (nfa->edge == EG_EPSILON) {
		/* next 0 */
		if (nfa->next[0] &&
			!test_add_set(stateset, nfastate(nfa->next[0])))
			e_closure(nfa->next[0], stateset, acp);
		/* next 1 */
		if (nfa->next[1] &&
			!test_add_set(stateset, nfastate(nfa->next[1])))
			e_closure(nfa->next[1], stateset, acp);
	}
}
コード例 #2
0
/*
 * Run tests: for s1 and s2
 * - call test_remove, test_add, test_copy
 * - s is used to make copies of s1 and s2
 */
static void run_tests(cset_t *c1, cset_t *c2, bset_t *s1, bset_t *s2, bset_t *s) {
  printf("\ns1: ");
  show_bset(s1);
  printf("\ns2: ");
  show_bset(s2);
  printf("\n");

  test_copy(c1, s1);
  test_copy(c2, s2);

  bset_empty(s);
  bset_add_set(s, s1);
  test_add_set(c1, c2, s, s2);

  bset_empty(s);
  bset_add_set(s, s2);
  test_add_set(c1, c2, s, s1);

  bset_empty(s);
  bset_add_set(s, s1);
  test_remove_set(c1, c2, s, s2);

  bset_empty(s);
  bset_add_set(s, s2);
  test_remove_set(c1, c2, s, s1);

  test_subset(c1, c2, s1, s2);
  test_disjoint(c1, c2, s1, s2);
}