summaryrefslogtreecommitdiff
path: root/javascripts/RegexVis.js
blob: c14f52f5b76c93b63ac91136fe2b7b0714600416 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * RegexParser
 *
 */
function RegexParser(str) {
    this.str = str;
}

RegexParser.prototype.parse = function() {
    for (var i = 0; i < this.str.length; i++) {
        switch(this.str[i]) {
            case '(':
                break;
            case '|':
                break;
            case ')':
                break
            case '*':
                break
            
            default:
                //alert(this.str[i]);
        }
    };
}


/*
 * State
 *
 */
function State(symbol) {
    if(!symbol) {
        symbol = '#';
    }
    this.symbol    = symbol;
    this.followUps = [];
    this.marked    = false;
}

State.prototype.mark = function(b) {
    this.marked = b;
}

State.prototype.setFollowUp = function(index, state) {
    if (!((index == 0) || (index==1)) ) return;
    this.followUps[index] = state;
}


/*
 * Nfa
 *
 */
function Nfa(symbol) {
    this.startState;
    this.endState;
    if (symbol) {
        this.startState = new State(symbol);
        this.endState   = new State(false);
        this.startState.setFollowUp(0, this.endState);
    }
}

Nfa.prototype.concatination = function(nfa) {
    this.endState.setFollowUp(0, nfa);
    this.endState = nfa.endState;
}

Nfa.prototype.union = function(nfa) {
    var s0 = new State();
    var s1 = new State();

    s0.setFollowUp(0, );
    s1.setFollowUp(1, );
}