annotate Implab/Automaton/DummyAlphabet.cs @ 176:0c3c69fe225b ref20160224

rewritten the text scanner
author cin
date Tue, 22 Mar 2016 18:58:40 +0300
parents 0f70905b4652
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
163
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
1 using System;
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
2 using System.Collections.Generic;
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
3 using System.Linq;
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
4
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
5 namespace Implab.Automaton {
164
ec35731ae299 Almost complete DFA refactoring
cin
parents: 163
diff changeset
6 /// <summary>
ec35731ae299 Almost complete DFA refactoring
cin
parents: 163
diff changeset
7 /// Dummy alphabet consists of integer numbers which are identical to their classes.
ec35731ae299 Almost complete DFA refactoring
cin
parents: 163
diff changeset
8 /// </summary>
163
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
9 public class DummyAlphabet : IAlphabet<int> {
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
10 readonly int m_size;
164
ec35731ae299 Almost complete DFA refactoring
cin
parents: 163
diff changeset
11
ec35731ae299 Almost complete DFA refactoring
cin
parents: 163
diff changeset
12 /// <summary>
ec35731ae299 Almost complete DFA refactoring
cin
parents: 163
diff changeset
13 /// Creates a new dummy alphabet with given size.
ec35731ae299 Almost complete DFA refactoring
cin
parents: 163
diff changeset
14 /// </summary>
ec35731ae299 Almost complete DFA refactoring
cin
parents: 163
diff changeset
15 /// <param name="size">The size of the alphabet, must be greater then zero.</param>
163
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
16 public DummyAlphabet(int size) {
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
17 Safe.ArgumentAssert(size > 0);
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
18 m_size = 0;
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
19 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
20
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
21 #region IAlphabet implementation
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
22
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
23 public List<int>[] CreateReverseMap() {
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
24 Enumerable.Range(0, m_size).ToArray();
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
25 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
26
171
0f70905b4652 Working on regular DFA
cin
parents: 164
diff changeset
27 public int Translate(int symbol) {
0f70905b4652 Working on regular DFA
cin
parents: 164
diff changeset
28 Safe.ArgumentInRange(symbol, 0, m_size, "symbol");
0f70905b4652 Working on regular DFA
cin
parents: 164
diff changeset
29 return symbol;
163
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
30 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
31
171
0f70905b4652 Working on regular DFA
cin
parents: 164
diff changeset
32 public bool Contains(int symbol) {
0f70905b4652 Working on regular DFA
cin
parents: 164
diff changeset
33 Safe.ArgumentInRange(symbol, 0, m_size, "symbol");
0f70905b4652 Working on regular DFA
cin
parents: 164
diff changeset
34 return true;
163
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
35 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
36
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
37 public int Count {
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
38 get {
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
39 return m_size;
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
40 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
41 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
42
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
43 #endregion
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
44 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
45 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
46