亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? dfa.cpp

?? Full support for extended regular expressions (those with intersection and complement); Support for
?? CPP
字號:

#include "dolphin.h"
#include "dfa.h"
using namespace std;
using namespace Whale;

#include <fstream>
#include <stdio.h>
#include "stl.h"
#include "time.h"
#include "process.h"

//#define DEBUG_STATE_GROUP_CREATION
//#define PRINT_SETS_OF_NFA_STATES_CORRESPONDING_TO_DFA_STATES
//#define PRINT_DFA_PARTITION
//#define PRINT_TRANSITION_TABLE

bool analyze_accepting_states_and_report_conflicts()
{
	for(int scn=0; scn<data.start_conditions.size(); scn++)
	{
		StartConditionData &sc=data.start_conditions[scn];
		
		if(find(sc.dfa.state_is_live.begin(), sc.dfa.state_is_live.end(), true)==sc.dfa.state_is_live.end())
		{
			if(data.variables.start_conditions_enabled)
			{
				cout << "Nothing is recognized in start condition " << sc.name << ": all states in the corresponding DFA are dead.\n";
			}
			else
				cout << "All states in the DFA are dead.\n";
			
			continue;
		}
		
		// a set of actions is in conflicts_found if in some state of local
		// dfa there was a conflict between all actions contained in s1.
		set<set<int> > conflicts_found;
		
		for(int i=0; i<sc.dfa.states.size(); i++)
		{
			DFA::State &state=sc.dfa.states[i];
			
			if(sc.dfa.state_is_live[i])
			{
				// this is the only case where conflicts can arise
				
				set<int> expressions_recognized_here;
				set<int> expressions_that_need_lookahead_here;
				for(int ren=0; ren<data.recognized_expressions.size(); ren++)
				{
					RecognizedExpressionData &re=data.recognized_expressions[ren];
					if(re.is_special) continue;
					if(re.offset_of_our_nfa_states_in_nfa_for_start_conditions[scn]<0)
						continue; // if this expression has nothing to do with this sc.
					
					// re.nfa has been incorporated in sc.dfa starting from
					// offset re.offset_of_our_nfa_states_in_nfa_for_start_conditions[scn]
					
					int intermediate_state_number_in_nfa_for_sc=re.offset_of_our_nfa_states_in_nfa_for_start_conditions[scn]+re.intermediate_local_nfa_state;
					int accepting_state_number_in_nfa_for_sc=re.offset_of_our_nfa_states_in_nfa_for_start_conditions[scn]+re.accepting_local_nfa_state;
//					cout << "sc " << scn << ", state " << i << ": re " << ren << " is recognized in nfa-for-sc state " << re.offset_of_our_nfa_states_in_nfa_for_start_conditions[scn] << "+" << re.accepting_local_nfa_state << "=" << accepting_state_number_in_nfa_for_sc << "\n";
					
					if(find(state.nfa_states.begin(), state.nfa_states.end(), accepting_state_number_in_nfa_for_sc)!=state.nfa_states.end())
						expressions_recognized_here.insert(ren);
					
					if(re.intermediate_local_nfa_state>=0 && find(state.nfa_states.begin(), state.nfa_states.end(), intermediate_state_number_in_nfa_for_sc)!=state.nfa_states.end())
						expressions_that_need_lookahead_here.insert(ren);
				}
				
				if(state.is_accepting)
					assert(expressions_recognized_here.size()>0);
				
				if(expressions_recognized_here.size()>=2)
				{
					cout << "Ambiguity between ";
					
					print_a_number_of_expressions(cout, expressions_recognized_here);
					
					if(data.variables.start_conditions_enabled)
						cout << " in start condition " << data.start_conditions[scn].name;
					
					cout << "; conflicting actions defined ";
					vector<Terminal *> action_locations;
					for(set<int>::iterator p=expressions_recognized_here.begin(); p!=expressions_recognized_here.end(); p++)
						action_locations.push_back(data.actions[data.recognized_expressions[*p].start_condition_to_action_number[scn]].declaration->arrow);
					print_a_number_of_terminal_locations(cout, action_locations, "at");
					cout << ".\n";
				}
				if(expressions_recognized_here.size()>0)
					sc.expressions_accepted_in_local_dfa_states.push_back(*expressions_recognized_here.begin());
				else
					sc.expressions_accepted_in_local_dfa_states.push_back(-1);
//				cout << "sc " << scn << ", state " << i << ": we accept " << *expressions_recognized_here.begin() << "\n";
				
				sc.expressions_that_need_lookahead_in_local_dfa_states.push_back(expressions_that_need_lookahead_here);
			}
			else
			{
				sc.expressions_accepted_in_local_dfa_states.push_back(-1);
				sc.expressions_that_need_lookahead_in_local_dfa_states.push_back(set<int>());
			}
		}
	}
	
	return true;
}

void build_final_automaton()
{
	// determining the number of states in the big DFA and the mapping between
	// the states of the big DFA and the states of the DFAs for individual start
	// conditions.
	for(int i=0; i<data.start_conditions.size(); i++)
	{
		StartConditionData &sc=data.start_conditions[i];
		
		sc.offset_of_local_states_in_main_dfa=data.dfa.states.size();
		for(int k=0; k<sc.dfa.states.size(); k++)
		{
			DolphinData::DataOnAutomatonState new_state_data;
			
			new_state_data.number_of_start_condition=i;
			new_state_data.number_of_state_in_dfa_for_sc=k;
			
			int what_is_accepted_in_local_dfa_state=sc.expressions_accepted_in_local_dfa_states[k];
			if(what_is_accepted_in_local_dfa_state>=0)
			{
				RecognizedExpressionData &re=data.recognized_expressions[sc.expressions_accepted_in_local_dfa_states[k]];
//				cout << "accepting state: looking up re " << sc.expressions_accepted_in_local_dfa_states[k] << " in sc " << i << "\n";
				
				new_state_data.action_accepted_here=re.start_condition_to_action_number[i];
			}
			else
				new_state_data.action_accepted_here=-1;
			
			set<int> &what_needs_lookahead_in_local_dfa_state=sc.expressions_that_need_lookahead_in_local_dfa_states[k];
			for(set<int>::iterator p=what_needs_lookahead_in_local_dfa_state.begin(); p!=what_needs_lookahead_in_local_dfa_state.end(); p++)
			{
				RecognizedExpressionData &re=data.recognized_expressions[*p];
//				cout << "lookahead state: looking up re " << *p << " in sc " << i << "\n";
				new_state_data.actions_that_need_lookahead_here.insert(re.start_condition_to_action_number[i]);
			}
			
//			cout << "(sc " << i << ", dfa state " << k << ") -> " << data.final_automaton.size() << "; we accept " << new_state.action_accepted_here << "\n";
			
			data.data_on_dfa_states.push_back(new_state_data);
			data.dfa.add_state();
		}
		
		for(int j=0; j<sc.dfa.states.size(); j++)
			data.dfa.state_is_live.push_back(sc.dfa.state_is_live[j]);
	}
	
	// building the big dfa.
	data.dfa.number_of_symbols=data.variables.alphabet_cardinality;
	data.dfa.align_transition_table();
	for(int i=0; i<data.dfa.states.size(); i++)
	{
		DolphinData::DataOnAutomatonState &state_data=data.data_on_dfa_states[i];
		
		data.dfa.states[i].is_accepting=(state_data.action_accepted_here!=-1);
		
		int local_number_of_state=state_data.number_of_state_in_dfa_for_sc;
		StartConditionData &sc=data.start_conditions[state_data.number_of_start_condition];
		vector<int> &transitions_from_old_state=sc.dfa.states[local_number_of_state].transitions;
		
		for(int j=0; j<data.variables.alphabet_cardinality; j++)
			if(transitions_from_old_state[j]>=0)
			{
				int target_state=sc.offset_of_local_states_in_main_dfa+transitions_from_old_state[j];
				data.dfa.add_transition(i, target_state, j);
			}
	}
	cout << data.dfa.states.size() << " DFA states.\n";
	
	// creating the initial partition.
	int number_of_types_of_states=0;
	map<pair<int, set<int> >, int> types_of_states;
	int number_of_dead_states=0;
	for(int i=0; i<data.dfa.states.size(); i++)
		if(!data.dfa.state_is_live[i])
		{
			data.dfa_partition.state_to_group.push_back(-1);
			number_of_dead_states++;
		}
		else
		{
			DolphinData::DataOnAutomatonState &state_data=data.data_on_dfa_states[i];
			pair<int, set<int> > type_of_this_state=make_pair(state_data.action_accepted_here, state_data.actions_that_need_lookahead_here);
			
			if(types_of_states.count(type_of_this_state))
				data.dfa_partition.state_to_group.push_back(types_of_states[type_of_this_state]);
			else
			{
				int number_of_type_of_this_state=number_of_types_of_states++;
				types_of_states[type_of_this_state]=number_of_type_of_this_state;
				data.dfa_partition.state_to_group.push_back(number_of_type_of_this_state);
			}
		}
	cout << (data.dfa.states.size()-number_of_dead_states) << " live states.\n";
	
	// getting the final partition
	minimize_dfa(data.dfa, data.dfa_partition);
	cout << data.dfa_partition.groups.size() << " states in the minimal DFA.\n";
	
	data.number_of_symbol_classes=0;
	assert(!data.symbol_to_symbol_class.size());
	for(int j=0; j<data.variables.alphabet_cardinality; j++)
		data.symbol_to_symbol_class.push_back(-1);
	vector<int> symbol_class_to_symbol;
	
	for(int j=0; j<data.variables.alphabet_cardinality; j++)
		if(data.symbol_to_symbol_class[j]==-1)
		{
			data.symbol_to_symbol_class[j]=data.number_of_symbol_classes;
			
			for(int k=j+1; k<data.variables.alphabet_cardinality; k++)
			{
				bool flag=true;
				for(int i=0; i<data.dfa.states.size(); i++)
					if(data.dfa.states[i].transitions[k]!=data.dfa.states[i].transitions[j])
					{
						flag=false;
						break;
					}
				
				if(flag)
					data.symbol_to_symbol_class[k]=data.number_of_symbol_classes;
			}
			
			symbol_class_to_symbol.push_back(j);
			data.number_of_symbol_classes++;
		}
	cout << data.number_of_symbol_classes << " symbol classes.\n";
	
	// writing the final transition table to the appropriate place.
	for(int i=0; i<data.dfa_partition.groups.size(); i++)
	{
		int representative_state=*data.dfa_partition.groups[i].begin();
		DolphinData::DataOnAutomatonState &state_data=data.data_on_dfa_states[representative_state];
		
		DolphinData::StateOfFinalAutomaton new_state;
		new_state.action_accepted_here=state_data.action_accepted_here;
		new_state.actions_that_need_lookahead_here=state_data.actions_that_need_lookahead_here;
		
		for(int j=0; j<data.number_of_symbol_classes; j++)
		{
			int target_state_in_old_dfa=data.dfa.states[representative_state].transitions[symbol_class_to_symbol[j]];
			if(target_state_in_old_dfa>=0)
				new_state.transitions.push_back(data.dfa_partition.state_to_group[target_state_in_old_dfa]);
			else
				new_state.transitions.push_back(-1);
		}
		data.final_automaton.push_back(new_state);
	}
}

// checking the final transition table for obvious errors, such as
// i. transitions to non-existent states.
// ii. states that no transition leads to (those besides the initial state).
void dfa_sanity_check()
{
	int number_of_states=data.final_automaton.size();
	int number_of_symbol_classes=data.number_of_symbol_classes;
	
	vector<bool> used_somewhere(number_of_states, false);
	for(int i=0; i<data.start_conditions.size(); i++)
	{
		// the initial state of each local dfa has internal number 0.
		used_somewhere[data.start_conditions[i].offset_of_local_states_in_main_dfa+0]=true;
	}
	for(int i=0; i<number_of_states; i++)
		for(int j=0; j<number_of_symbol_classes; j++)
		{
			if(data.final_automaton[i].transitions[j]<-1 || data.final_automaton[i].transitions[j]>=number_of_states)
			{
				cout << "\n\n\tdfa_sanity_check():\n";
				cout << "Something went while constructing the DFA.\n";
				cout << "State " << i << " has a transition upon symbol class " << j << " to a\n";
				cout << "non-existent state " << data.final_automaton[i].transitions[j] << "\n\n";
				assert(false);
			}
			if(data.final_automaton[i].transitions[j]!=-1)
				used_somewhere[data.final_automaton[i].transitions[j]]=true;
		}
	
	set<int> unused_states;
	for(int i=0; i<number_of_states; i++)
		if(!used_somewhere[i])
			unused_states.insert(i);
	if(unused_states.size())
	{
		cout << "\n\n\tdfa_sanity_check():\n";
		cout << "Something went wrong while constructing the DFA.\n";
		cout << "State group" << (unused_states.size()==1 ? " " : "s ");
		cout << unused_states << " cannot be reached at all.\n\n";
		assert(false);
	}
}

bool construct_dfa()
{
//	cout << "construct_dfa()\n";
	
	// making a separate minimal dfa for each start condition.
	for(int i=0; i<data.start_conditions.size(); i++)
	{
		StartConditionData &sc=data.start_conditions[i];
		
		NFA &nfa=sc.nfa;
		DFA &dfa=sc.dfa;
		
		convert_nfa_to_dfa(nfa, dfa);
		assert(dfa.states.size());
		
		dfa.determine_dead_states();
		
		if(data.variables.dump_dfas_for_start_conditions)
		{
			ofstream log;
			char log_file_name_without_extension[100];
			sprintf(log_file_name_without_extension, "%s.%s.dfa", data.file_name.c_str(), sc.name);

			char log_file_name[100];
			sprintf(log_file_name, "%s.dot", log_file_name_without_extension);
			log.open(log_file_name);

		//	log << "DFA for start condition " << sc.name << "\n\n";
		//	dfa.print(log);

			log << "\n";
			log << "/* A DFA created by Dolphin. */\n\n";
			print_dot_message(log_file_name_without_extension, log);
			log << "\n// DFA for start condition " << sc.name << "\n\n";
			dfa.print_in_dot_format(log);
		}
	}
	
	if(!analyze_accepting_states_and_report_conflicts())
		return false;
	
	build_final_automaton();
	
	if(data.variables.dump_dfa_to_file)
	{
		ofstream log;
		char log_file_name_without_extension[100];
		sprintf(log_file_name_without_extension, "%s.dfa", data.file_name.c_str());
		
		char log_file_name[100];
		sprintf(log_file_name, "%s.dot", log_file_name_without_extension);
		log.open(log_file_name);
		
		log << "\n";
		log << "/* A DFA created by Dolphin. */\n\n";
		print_dot_message(log_file_name_without_extension, log);
		data.dfa.print_in_dot_format(log);
	}
	
//	dfa_sanity_check(); // a postcondition
	
	return true;
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产清纯美女被跳蛋高潮一区二区久久w| 91丝袜国产在线播放| 日韩无一区二区| 美国一区二区三区在线播放| 制服丝袜日韩国产| 日本不卡一二三区黄网| 欧美va在线播放| 成人性生交大片| 一区二区三区不卡视频| 欧美乱妇一区二区三区不卡视频| 日韩精品乱码av一区二区| 日韩网站在线看片你懂的| 国产精品一区二区无线| 亚洲日本一区二区三区| 欧美美女喷水视频| 狠狠色2019综合网| 中文字幕中文字幕一区| 欧美视频完全免费看| 蜜臀av一区二区| 欧美国产日韩a欧美在线观看| 99re6这里只有精品视频在线观看| 亚洲综合在线视频| 欧美成人激情免费网| a在线播放不卡| 日韩在线一区二区三区| 国产亚洲欧美中文| 欧美色偷偷大香| 国产精品中文字幕日韩精品| 伊人色综合久久天天人手人婷| 日韩欧美区一区二| 99久久国产免费看| 蜜桃在线一区二区三区| 日本一区二区成人在线| 欧美精品在线视频| 成人免费看视频| 免费观看日韩电影| 亚洲六月丁香色婷婷综合久久 | 99国产一区二区三精品乱码| 天天操天天综合网| 国产精品国产三级国产专播品爱网| 欧美三级日本三级少妇99| 国产精品一区二区91| 爽爽淫人综合网网站| 亚洲视频免费在线观看| 精品福利av导航| 欧美精品高清视频| 色偷偷一区二区三区| 国产精品 日产精品 欧美精品| 亚洲福利一区二区| 亚洲欧美日韩成人高清在线一区| 久久久久久99精品| 精品福利视频一区二区三区| 7777精品伊人久久久大香线蕉最新版 | 91香蕉视频在线| 国产精品主播直播| 极品少妇xxxx偷拍精品少妇| 亚洲h精品动漫在线观看| 亚洲国产激情av| 久久精品一区二区三区av| 欧美精品一二三区| 欧美日韩国产三级| 欧美午夜免费电影| 91黄色小视频| 91福利在线播放| 色狠狠色噜噜噜综合网| 99国产精品久| www.亚洲免费av| 成人av免费在线| 北条麻妃一区二区三区| 大陆成人av片| 成人午夜电影小说| 粉嫩久久99精品久久久久久夜| 国产在线视频精品一区| 久久成人18免费观看| 久久国产视频网| 国产尤物一区二区在线| 极品少妇一区二区三区精品视频| 久久电影网站中文字幕| 六月丁香婷婷色狠狠久久| 另类欧美日韩国产在线| 看电影不卡的网站| 国产一区二三区| 国产成人亚洲综合a∨婷婷图片| 国产一区二区在线看| 激情综合网最新| 国产精品99久久久久| 国产黄人亚洲片| 94-欧美-setu| 91成人在线精品| 69久久99精品久久久久婷婷| 欧美一区二区三区的| 欧美xxxxxxxx| 日本一区二区久久| 亚洲精品国久久99热| 亚洲最大的成人av| 久久国产精品第一页| 国产在线精品一区二区三区不卡| 丁香婷婷综合网| 色视频一区二区| 日韩一区二区麻豆国产| 精品国产伦一区二区三区观看体验| 久久久久免费观看| 最新成人av在线| 午夜精品免费在线| 国产在线精品一区二区| 99视频精品免费视频| 欧美日韩在线播放三区四区| 日韩三级.com| 国产精品毛片a∨一区二区三区| 亚洲一区在线观看视频| 久久99热狠狠色一区二区| 99久久亚洲一区二区三区青草| 欧美色国产精品| 久久精品亚洲一区二区三区浴池| 亚洲欧美日韩电影| 九色|91porny| 在线视频欧美区| 久久精品夜色噜噜亚洲a∨| 亚洲人成小说网站色在线 | 国产精品99久久久久久宅男| 色国产精品一区在线观看| 日韩欧美色电影| 亚洲一区二区欧美日韩| 久久国产福利国产秒拍| 欧美自拍偷拍一区| 国产午夜久久久久| 日韩精品一级二级 | 亚洲第一狼人社区| 丁香婷婷综合色啪| 日韩欧美在线123| 亚洲男人都懂的| 国产精品性做久久久久久| 欧美日韩大陆在线| 中文字幕欧美一区| 国产真实乱对白精彩久久| 99riav久久精品riav| 精品国产凹凸成av人导航| 亚洲成人av中文| 色爱区综合激月婷婷| 日本一区二区视频在线观看| 久久99国产精品久久99| 欧美日本在线一区| 最新热久久免费视频| 精品亚洲免费视频| 欧美一三区三区四区免费在线看| 一区二区三区四区不卡视频| 国产最新精品精品你懂的| 欧美一区二区三区免费观看视频| 亚洲男人电影天堂| 不卡视频在线观看| 亚洲国产高清在线观看视频| 国精产品一区一区三区mba桃花| 69堂国产成人免费视频| 夜夜精品视频一区二区| 一本一道久久a久久精品| 成人免费在线视频观看| 成人黄页毛片网站| 国产精品美女久久久久av爽李琼| 国产一区二区三区美女| 精品免费一区二区三区| 久久成人免费日本黄色| 精品国精品自拍自在线| 喷水一区二区三区| 日韩一区二区精品| 日本成人中文字幕在线视频| 欧美日韩欧美一区二区| 婷婷夜色潮精品综合在线| 欧美日韩在线播| 午夜久久福利影院| 制服丝袜亚洲播放| 麻豆国产欧美日韩综合精品二区 | 精品国产一区久久| 麻豆成人在线观看| 精品奇米国产一区二区三区| 国内精品视频一区二区三区八戒| 久久综合中文字幕| 福利电影一区二区| 亚洲乱码国产乱码精品精小说| 色综合久久久久久久| 亚洲国产成人高清精品| 欧美一区二区三区婷婷月色| 久久精品国产一区二区| 久久精品一区二区三区四区| 北岛玲一区二区三区四区| 亚洲精品免费在线观看| 欧美午夜免费电影| 蜜桃av一区二区三区电影| 亚洲精品一区二区三区蜜桃下载 | 精品成人私密视频| 丰满少妇在线播放bd日韩电影| 国产精品久久久久一区二区三区| 一本色道久久综合精品竹菊| 天天爽夜夜爽夜夜爽精品视频| 精品福利一二区| 色香蕉久久蜜桃| 麻豆精品精品国产自在97香蕉| 国产精品视频一区二区三区不卡| 在线视频国内一区二区| 日韩不卡一区二区三区| 久久精品夜夜夜夜久久|