Esempio n. 1
0
static struct FSAState *RecurSeqCreateNFA(LPXMLDTDVALIDATOR vp, XMLCP *cp, struct FSAState *next) 
{ /* ugly recursive solution to traverse singly linked list backwards :( BUT consider:
	 for example docbook longest seq is 8 items - using prev pointer would take about 60kB...*/
	struct FSAState *s = (cp->next) ? RecurSeqCreateNFA(vp, cp->next, next) : next;
	CHKMEM(s);
	return CreateNFA(vp, cp, s);
}
Esempio n. 2
0
static int InitValidator(LPXMLDTDVALIDATOR v) 
{
	struct ElementDecl *e, *ee;
	struct FSAState *s;
	LPXMLVECTOR *declAtts;
	void **d;

	ee = (struct ElementDecl *)_XMLVector_GetIterP(v->ElementDecls, e);
	for (; e!=ee; e++) {
		/* important: every 1. content particle contains a pointer to
		hastablebucket in its name, we MUST assign hashtable data here,
		we cannot alter the cpNames table when DTD parsing is in progress! */
		
		d = (void**)XMLHTable_GetData(v->parser->prt->cpNames, (XMLHTABLEBUCKET*)e->cp->name);
		if (*d != EMPTYSTR) continue; /* duplicate declaration */
		*d = e;
	
		switch (e->type) {
			case XMLCTYPE_ANY: 
			case XMLCTYPE_EMPTY: break;
			case XMLCTYPE_MIXED: if (!e->cp->children) /* simple #PCDATA */
									 break; 
				/* note that we can't easily simplify the (e) type
				content models (which is actually XMLCTYPE_CHOICE) 
				- since we must allow (e)* or ((e))? etc. */
			default:
			v->fsa = XMLVector_Create(&e->fsa, 4, sizeof(struct FSAState*));
			if (!e->fsa) return 0;
			s = AddState(v);
			if (!s) return 0;
			SET_SMARK(s, SMARK_FINAL, 1);
			e->startState = CreateNFA(v, e->cp, s);
			if (!e->startState) return 0;

#ifdef PRINT_FSA
			PrintFSA(e, "NFA");
			if (!NFAtoDFA(v, e)) return 0;
			PrintFSA(e, "DFA");		
#else	
			if (!NFAtoDFA(v, e)) return 0;
#endif
		}
		if (v->parser->prt->declAttTable) {
			declAtts = XMLHTable_Lookup(v->parser->prt->declAttTable, e->name);
			if (declAtts) {
				e->declAtts = *(declAtts+1);
				if (e->declAtts->length > 1) 
					qsort((void*)e->declAtts->array, e->declAtts->length, 
						sizeof(XMLATTDECL), attcmp);
			}
		}
	}

	v->ElementTable = v->parser->prt->cpNames;
	v->cpNodesPool = v->parser->prt->cpNodesPool; 
	return 1;
}
BOOL CAG_RegEx::SetRegEx(string strRegEx)
{
	// 1. Clean up old regular expression
	CleanUp();

	// 2. Create NFA
	if(!CreateNFA(strRegEx))
		return FALSE;
	
	// 3. Convert to DFA
	ConvertNFAtoDFA();

	// 4. Reduce DFA
	ReduceDFA();

	return TRUE;
}
Esempio n. 4
0
bool CAG_RegEx::SetRegEx(string strRegEx)
{
	// 1. Clean up old regular expression
	CleanUp();

	// 2. Create NFA
	if(!CreateNFA(strRegEx))
		return false;
	
	// 3. Convert to DFA
	ConvertNFAtoDFA();

	// 4. Reduce DFA
	ReduceDFA();

	return true;
}
Esempio n. 5
0
static struct FSAState *CreateNFA2(LPXMLDTDVALIDATOR vp, XMLCP *cp, struct FSAState *next)
{
	struct FSAState *ns;
	CHKMEM(ns = AddState(vp));
	
	if (cp->type == XMLCTYPE_NAME) {
		CHKMEM(AddTran(ns, next, cp));
	}
	else {
		struct FSAState *s;
		if (cp->type == XMLCTYPE_SEQ) {
			CHKMEM(s = RecurSeqCreateNFA(vp, cp->children, next));
			CHKMEM(AddTran(ns, s, (void*)epsilon));
		}
		else {
			for(cp = cp->children; cp; cp = cp->next) {
				CHKMEM(s = CreateNFA(vp, cp, next));
				CHKMEM(AddTran(ns, s, (void*)epsilon));
			}
		}
	}
	return ns;
}
Esempio n. 6
0
void InitLexical(string infile,string outfile,string outfile2)		//词法分析器初始化
{
	state** s=new state*[5];
	s[0]=CreateNFA("input_keywords.txt");
	s[1]=CreateNFA("input_identifier.txt");
	s[2]=CreateNFA("input_const.txt");
	s[3]=CreateNFA("input_limiter.txt");
	s[4]=CreateNFA("input_operator.txt");
	result* H=new result,*hr=NULL;
	H->a="";
	H->type=5;
	H->next=NULL;

	getResult(s,H,infile,outfile);

	result* H2=new result,*hr2=NULL;
	H2->a="";
	H2->type=5;
	H2->next=NULL;

	hr=H->next;
	hr2=H2;
	while(hr)
	{
		result* re=new result;
		if(hr->type==0&&(hr->a=="int"||hr->a=="double"))
			re->a="p";
		else if(hr->type==0&&hr->a=="return")
			re->a="s";
		else if(hr->type==0&&hr->a=="else")
			re->a="u";
		else if(hr->type==0&&hr->a=="void")
			re->a="v";
		else if(hr->type==0)
			re->a="t";
		else if(hr->type==1)
			re->a="q";
		else if(hr->type==2)
			re->a="r";
		else
			re->a=hr->a;
		re->next=NULL;
		re->type=hr->type;
		hr2->next=re;
		hr2=hr2->next;
		hr=hr->next;
	}
	printf("\n词法结构1:	\n");		//输出状态至控制台,可注释
	sss.str("");
	hr=H->next;
	while(hr)
	{
		printf("( %s	:	%s )\n",hr->a.c_str(),types[hr->type].c_str());
		hr=hr->next;
	}
	printf("\n转换词法结构2:	\n");	//输出状态至控制台,可注释
	sss.str("");
	hr=H2->next;
	while(hr)
	{
		sss<<hr->a;
		printf("( %s	:	%s )\n",hr->a.c_str(),types[hr->type].c_str());
		hr=hr->next;
	}
	string ssd=sss.str();
	sss.str("");

	ofstream fout(outfile2,std::ios::out);
	fout.open(outfile2,std::ios::out);
	if (fout.is_open())   
	{
		fout <<"";  
		fout.clear();  
		fout.close(); 
	}
	fout.open(outfile2,std::ios::out|std::ios::app);
	if (fout.is_open())   
	{
		fout <<ssd+"#";  
		fout.clear();  
		fout.close(); 
	}
}