summaryrefslogtreecommitdiff
path: root/javascripts/uifunc.js
blob: 007305a7db66637eed57abd59a9bdb4517c1d33a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 
function checkLength(el, bId) {
	if(el.value.length > 0) {
		enable(bId);
	} else {
		disable(bId);
	};
};

// 
function enable(id) {
		 $(id).removeAttr("disabled");
};

// 
function disable(id) {
	 $(id).attr("disabled","disabled");
};

// 
function uiParse() {
	var parser = new RegexParser();
	nfa = parser.parse($('#regex').attr('value'));
	$('#parseMessage').html('Parse: '+parser.getErrorMessage());
	if (parser.getErrorMessage() != 'Ok') {
		$('#parseMessage').removeClass('success');	
		$('#parseMessage').addClass('failure');	
		$('#regex').addClass('failure');
	} else {
		$('#parseMessage').removeClass('failure');
		$('#regex').removeClass('failure');
		$('#parseMessage').addClass('success');
		$('#regex').addClass('success');
		enable('#word');
		var dfa = new Nfa2Dfa(nfa);
		var ttable = dfa.do();
		graph();
		disable('#regex');
		disable('#parseButton');
	};
	$('#parseMessage').effect("highlight", {}, 1000);
};

// 
function uiSimulate() {
	var simulator = new NfaSimulator(nfa);
	var check = simulator.simulate($('#word').attr('value'));
	if (!check) {
		$('#checkMessage').html('Word not accepted');
		$('#checkMessage').removeClass('success');
		$('#word').removeClass('success');	
		$('#checkMessage').addClass('failure');
		$('#word').addClass('failure');	
	} else {
		$('#checkMessage').html('Word accepted');
		$('#checkMessage').removeClass('failure');	
		$('#word').removeClass('failure');	
		$('#checkMessage').addClass('success');
		$('#word').addClass('success');
	};
	$('#checkMessage').effect("highlight", {}, 1000);	
};