output.c

来自「SRI international 发布的OAA框架软件」· C语言 代码 · 共 851 行 · 第 1/2 页

C
851
字号
		fprintf(OUT, ", ");
		if (!(--items_on_line)){
			fprintf(OUT, "\n  ");
			items_on_line = MAX_ON_LINE;
		}
	}
#if 1
	/* put in jump to error state */
	fprintf(OUT, "%d\n};\n\n", dfa_allocated);
#else
	fprintf(OUT, "\n};\n\n");
#endif
}


#ifdef __USE_PROTOS
void p_dfa_table(void)
#else
void p_dfa_table()
#endif
{
	register int	i;

	fprintf(OUT, "\n%sDfaState *%sdfa[%d] = {\n",
		gen_cpp?ClassName("::"):"",gen_cpp?ClassName("::"):"", dfa_allocated);
	for (i=0; i<(dfa_allocated-1); ++i){
		fprintf(OUT, "\tst%d,\n", i);
	}
	fprintf(OUT, "\tst%d\n", i);
	fprintf(OUT, "};\n\n");
}


#ifdef __USE_PROTOS
void p_accept_table(void)
#else
void p_accept_table()
#endif
{
	register int	i = 1;
	register int	items_on_line = 0;
	int		true_interactive = TRUE;

	/* make sure element for one past (zzerraction) -WEC 12/16/92 */
	fprintf(OUT,"\n%sDfaState %saccepts[%d] = {\n  ",
			gen_cpp?ClassName("::"):"",
			gen_cpp?ClassName("::"):"",
			dfa_allocated+1);
	/* don't do anything if no dfa nodes */
	if (i>dfa_allocated) goto skip_accepts;
	for (;;) {
		int accept=0;   /* MR14a - Manuel Kessler (mlkessle@cip.physik.uni-wuerzburg.de) */
		set accept_set;
		set nfa_states;
		unsigned int *t, *nfa_i;
		unsigned int *q, *regular_expr;

		accept_set = empty;
		nfa_states = DFA(i)->nfa_states;
		t = nfa_i = set_pdq(nfa_states);
		/* NOTE: picks lowest accept because accepts monotonic	*/
		/*	with respect to nfa node numbers and set_pdq	*/
		/*	returns in that order				*/
		while((*nfa_i != nil) && (!(accept = NFA(*nfa_i)->accept))){
			nfa_i++;
		}

		/* figure out if more than one accept state there */
		if (warn_ambig ){
			set_orel(accept, &accept_set);
			while(*nfa_i != nil){
				set_orel(NFA(*nfa_i)->accept, &accept_set);
				nfa_i++;
			}
			/* remove error action from consideration */
			set_rm(0, accept_set);

			if( set_deg(accept_set)>1){
				fprintf(stderr, "dlg warning: ambiguous regular expression ");
				q = regular_expr = set_pdq(accept_set);
				while(*regular_expr != nil){
					fprintf(stderr," %d ", *regular_expr);
					++regular_expr;
				}
				fprintf(stderr, "\n");
				free(q);
			}
		}

		if ((DFA(i)->alternatives) && (accept != 0)){
			true_interactive = FALSE;
		}
		fprintf(OUT, "%d, ", accept);

		/* free up memory before we "break" below -ATG 4/6/95 */
		free(t);
		set_free(accept_set);

		if ((++i)>dfa_allocated)
			break;
		if ((++items_on_line)>=MAX_ON_LINE){
			fprintf(OUT,"\n  ");
			items_on_line = 0;
		}
/*
		free(t);
		set_free(accept_set);
*/
	}
	/* make sure element for one past (zzerraction) -WEC 12/16/92 */
skip_accepts:
	fprintf(OUT, "0\n};\n\n");
}


#ifdef __USE_PROTOS
void p_action_table(void)
#else
void p_action_table()
#endif
{
	register int	i;
	char* theClassName = ClassName("");

	if ( gen_cpp )
		fprintf(OUT, "Ptr%sMemberFunc %s::actions[%d] = {\n", theClassName,
					theClassName, action_no+1);
	else
		fprintf(OUT, "void (*actions[%d])() = {\n", action_no+1);
	if ( gen_cpp )
/*		fprintf(OUT, "\t(Ptr%sMemberFunc)&%s::erraction,\n", theClassName, theClassName);*/
		fprintf(OUT, "\t&%s::erraction,\n", theClassName);
	else
		fprintf(OUT, "\tzzerraction,\n");
	for (i=1; i<action_no; ++i) {
		if ( gen_cpp )
/*			fprintf(OUT,"\t(Ptr%sMemberFunc)&%s::act%d,\n", theClassName, theClassName, i);*/
			fprintf(OUT,"\t&%s::act%d,\n", theClassName, i);
		else
			fprintf(OUT,"\tact%d,\n", i);
		DAWDLE;
	}
	if ( gen_cpp )
/*		fprintf(OUT,"\t(Ptr%sMemberFunc)&%s::act%d\n", theClassName, theClassName, i);*/
		fprintf(OUT,"\t&%s::act%d\n", theClassName, i);
	else
		fprintf(OUT,"\tact%d\n", i);
	fprintf(OUT, "};\n\n");
}


#ifdef __USE_PROTOS
void p_shift_table(int m)  				    /* MR1 */
#else
void p_shift_table(m)						/* MR1 */
int m;
#endif
{
	register int	i = 0, j;
	register int	items_on_line = 0;

	fprintf(OUT, "%s unsigned char %sshift%d[%d] = {\n  ",
		gen_cpp?"":"static",
		gen_cpp?ClassName("::"):"", m, CHAR_RANGE);
	for (;;) {
		/* find which partition character i is in */
		for (j=0; j<dfa_class_nop[mode_counter]; ++j){
			if (set_el(i,class_sets[j]))
				break;
			}
		fprintf(OUT,"%d",j);
		if ((++i)>=CHAR_RANGE)
			break;
		fprintf(OUT,", ");
		if ((++items_on_line)>=MAX_ON_LINE){
			fprintf(OUT,"\n  ");
			items_on_line = 0;
			}
		}
	fprintf(OUT, "\n};\n\n");
}


#ifdef __USE_PROTOS
void p_base_table(void)
#else
void p_base_table()
#endif
{
	register int m;

	fprintf(OUT, "%sDfaState %sdfa_base[] = {\n",
			gen_cpp?ClassName("::"):"static ",
			gen_cpp?ClassName("::"):"");
	for(m=0; m<(mode_counter-1); ++m)
		fprintf(OUT, "\t%d,\n", dfa_basep[m]-1);
	fprintf(OUT, "\t%d\n};\n\n", dfa_basep[m]-1);
}


#ifdef __USE_PROTOS
void p_class_table(void)    				/* MR1 */
#else
void p_class_table()						/* MR1 */
#endif
{
#if 0
	register int m;

	fprintf(OUT,"%s int %sdfa_class_no[] = {\n",
			gen_cpp?"":"static",
			gen_cpp?ClassName("::"):"");
	for(m=0; m<(mode_counter-1); ++m)
		fprintf(OUT,"\t%d,\n", dfa_class_nop[m]);
	fprintf(OUT,"\t%d\n};\n\n", dfa_class_nop[m]);
#endif
}


#ifdef __USE_PROTOS
void p_bshift_table(void)					/* MR1 */
#else
void p_bshift_table()						/* MR1 */
#endif
{
	register int m;

	fprintf(OUT,"%s unsigned char *%sb_class_no[] = {\n",
		gen_cpp?"":"static",
		gen_cpp?ClassName("::"):"");
	for(m=0; m<(mode_counter-1); ++m)
		fprintf(OUT, "\tshift%d,\n", m);
	fprintf(OUT, "\tshift%d\n};\n\n", m);
}


#ifdef __USE_PROTOS
void p_alternative_table(void)				/* MR1 */
#else
void p_alternative_table()					/* MR1 */
#endif
{
	register int i;

	if ( !gen_cpp ) fprintf(OUT, "#define ZZINTERACTIVE\n\n");
	if ( gen_cpp )
		fprintf(OUT, "DLGChar %salternatives[%d] = {\n",  /* mr23 vhs %sDfaStates+1 */
				ClassName("::"),
				dfa_allocated+1); /* vhs ClassName("::")); */
	else
		fprintf(OUT, "static %s zzalternatives[DfaStates+1] = {\n",
				minsize(dfa_allocated));

	for(i=1; i<=dfa_allocated; ++i)
		fprintf(OUT, "\t%d,\n", DFA(i)->alternatives);
	fprintf(OUT, "/* must have 0 for zzalternatives[DfaStates] */\n");
	fprintf(OUT, "\t0\n};\n\n");
}


#ifdef __USE_PROTOS
void p_mode_def(char *s,int m)			/* MR1 */
#else
void p_mode_def(s,m)					/* MR1 */
char *s;
int m;
#endif
{
	if ( gen_cpp )
	{
		mode_name[cur_mode] = mystrdup(s);
		mode_number[cur_mode] = m;
		cur_mode++;
	}
	else
		fprintf(mode_stream, "#define %s %d\n", s, m);
}

#ifdef __USE_PROTOS
char * ClassName(char *suffix)
#else
char * ClassName(suffix)
char *suffix;
#endif
{
	static char buf[200];
	extern char *class_name;

	sprintf(buf, "%s%s", class_name, suffix);
	return buf;
}

#ifdef DEBUG

/* print out a particular nfa node that is pointed to by p */

#ifdef __USE_PROTOS
void p_nfa_node(nfa_node *p)
#else
void p_nfa_node(p)
nfa_node *p;
#endif
{
	 register nfa_node *t;

	if (p != NIL_INDEX){
		printf("NFA state : %d\naccept state : %d\n",
			NFA_NO(p),p->accept);
		if (p->trans[0] != NIL_INDEX){
			printf("trans[0] => %d on ", NFA_NO(p->trans[0]));
			p_set(p->label);
			printf("\n");
			}
		else
			printf("trans[0] => nil\n");
		if (p->trans[1] != NIL_INDEX)
			printf("trans[1] => %d on epsilon\n",
				NFA_NO(p->trans[1]));
		else
			printf("trans[1] => nil\n");
		printf("\n");
		}
}
#endif

#ifdef  DEBUG

/* code to print out special structures when using a debugger */

#ifdef __USE_PROTOS
void p_nfa(p)
#else
void p_nfa(nfa_node *p)
nfa_node *p;	/* state number also index into array */
#endif
{
/* each node has a marker on it so it only gets printed once */

	operation_no++; /* get new number */
	s_p_nfa(p);
}

#ifdef __USE_PROTOS
void s_p_nfa(nfa_node *p)
#else
void s_p_nfa(p)
nfa_node *p;	/* state number also index into array */
#endif
{
	if ((p != NIL_INDEX) && (p->nfa_set != operation_no)){
		/* so it is only printed once */
		p->nfa_set = operation_no;
		p_nfa_node(p);
		s_p_nfa(p->trans[0]);
		s_p_nfa(p->trans[1]);
		}
}

#ifdef __USE_PROTOS
void p_dfa_node(dfa_node *p)
#else
void p_dfa_node(p)
dfa_node *p;
#endif
{
	int i;

	if (p != NIL_INDEX){
		printf("DFA state :%d\n",NFA_NO(p));
		if (p->done)
			printf("done\n");
		else
			printf("undone\n");
		printf("from nfa states : ");
		p_set(p->nfa_states);
		printf("\n");
		/* NOTE: trans arcs stored as ints rather than pointer*/
		for (i=0; i<class_no; i++){
			printf("%d ",p->trans[i]);
			}
		printf("\n\n");
		}
}

#ifdef __USE_PROTOS
void p_dfa(void)
#else
void p_dfa()
#endif
{
/* prints out all the dfa nodes actually allocated */

	int i;

	for (i = 1; i<=dfa_allocated; i++)
		p_dfa_node(NFA(i));
}


/* print out numbers in the set label */

#ifdef __USE_PROTOS
void p_set(set label)
#else
void p_set(label)
set label;
#endif
{
	unsigned *t, *e;

	if (set_nil(label)){
		printf("epsilon\n");
	}else{
		t = e = set_pdq(label);
		while(*e != nil){
			printf("%d ", (*e+MIN_CHAR));
			e++;
		}
		printf("\n");
		free(t);
	}
	
}
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?