1
2
3
4
5
6 using System;
7 using System.Collections;
8
9 namespace System.RegularExpressions
10 {
11 public class Context
12 {
13 public Context() : any(), epsilon(eps), count(0)
14 {
15 }
16 public ~Context()
17 {
18 for (NfaState* state : nfaStates)
19 {
20 delete state;
21 }
22 for (Symbol* symbol : symbols)
23 {
24 delete symbol;
25 }
26 }
27 public Symbol* MakeAny()
28 {
29 return &any;
30 }
31 public Symbol* MakeEpsilon()
32 {
33 return ε
34 }
35 public NfaState* MakeNfaState()
36 {
37 NfaState* state = new NfaState();
38 nfaStates.Add(state);
39 return state;
40 }
41 public Symbol* MakeChar(uchar c)
42 {
43 auto it = charSymbols.Find(c);
44 if (it != charSymbols.End())
45 {
46 return it->second;
47 }
48 else
49 {
50 Symbol* symbol = new Char(c);
51 symbols.Add(symbol);
52 charSymbols[c] = symbol;
53 return symbol;
54 }
55 }
56 public Symbol* MakeRange(uchar start, uchar end)
57 {
58 Range range(start, end);
59 auto it = rangeSymbols.Find(range);
60 if (it != rangeSymbols.End())
61 {
62 return it->second;
63 }
64 else
65 {
66 Symbol* symbol = new Range(start, end);
67 symbols.Add(symbol);
68 rangeSymbols[range] = symbol;
69 return symbol;
70 }
71 }
72 public Class* MakeClass()
73 {
74 Class* cls = new Class();
75 symbols.Add(cls);
76 return cls;
77 }
78 public int GetNextRegExCount()
79 {
80 return count++;
81 }
82 private List<NfaState*> nfaStates;
83 private List<Symbol*> symbols;
84 private Any any;
85 private Char epsilon;
86 private Map<uchar, Symbol*> charSymbols;
87 private Map<Range, Symbol*> rangeSymbols;
88 private int count;
89 }
90