-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dfa.cs
99 lines (90 loc) · 2.28 KB
/
Dfa.cs
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
namespace Lex
{
/*
* Class: Dfa
*/
using System;
using System.Collections;
using BitSet;
public class Dfa
{
/*
* Member Variables
*/
bool mark;
Accept accept;
int anchor;
ArrayList nfa_set;
BitSet nfa_bit;
int label;
public ArrayList GetNFASet() { return nfa_set; }
public void SetNFASet(ArrayList a) { nfa_set = a; }
public BitSet GetNFABit() { return nfa_bit; }
public void SetNFABit(BitSet b) { nfa_bit = b; }
public int GetLabel() { return label; }
public void SetLabel(int i) { label = i; }
public Accept GetAccept() { return accept; }
public void SetAccept(Accept a) { accept = a; }
public int GetAnchor() { return anchor; }
public void SetAnchor(int a) { anchor = a; }
/*
* Function: Dfa
*/
public Dfa(int l)
{
mark = false;
accept = null;
anchor = Spec.NONE;
nfa_set = null;
nfa_bit = null;
label = l;
}
public void dump()
{
#if DUMMY
Console.WriteLine("[Dfa begin dump]");
Console.WriteLine("group="+Int32.ToString(group));
Console.WriteLine("mark="+Boolean.ToString(mark));
if (accept == null)
Console.WriteLine("accept=null");
else
accept.dump();
Console.WriteLine("anchor="+Int32.ToString(anchor));
if (nfa_set == null)
Console.WriteLine("nfa_set=null");
else
{
int n1 = nfa_set.Count;
for (int i = 0; i < n1; i++)
{
Object o2 = nfa_set[i];
Console.Write("i="+Int32.ToString(i)+" elem=");
if (o2 == null)
Console.WriteLine("null");
else
{
Nfa elem = (CNfa) o2;
elem.dump();
}
}
}
if (nfa_bit == null)
Console.WriteLine("nfa_bit=null");
else
{
Console.Write("nfa_bit("+Int32.ToString(nfa_bit.GetLength())+")=");
for (int i = 0; i < nfa_bit.GetLength(); i++)
if (nfa_bit.Get(i))
Console.Write("1");
else
Console.Write("0");
Console.WriteLine("");
}
Console.WriteLine("[Dfa end dump]");
#endif
}
public bool IsMarked() { return mark; }
public void SetMarked() { mark = true; }
public void ClearMarked() { mark = false; }
}
}