Skip to content

Commit b7edc84

Browse files
committed
Add int FSA
1 parent c8fd153 commit b7edc84

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Rain.Compiler.Models.Tokenization.Constants.Fsa;
2+
3+
4+
internal class IntFsaStateNames
5+
{
6+
internal const string Zero = nameof(Zero);
7+
internal const string Digit = nameof(Digit);
8+
internal const string HexPrefix = nameof(HexPrefix);
9+
internal const string Hex = nameof(Hex);
10+
internal const string Octat = nameof(Octat);
11+
internal const string Long = nameof(Long);
12+
internal const string Unsigned = nameof(Unsigned);
13+
internal const string UnsignedLong = nameof(UnsignedLong);
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Rain.Compiler.Models.Tokenization.Constants.Fsa;
2+
using Rain.Compiler.Models.Tokenization;
3+
using Rain.Compiler.Tokenization.DfaGraphs.Interface;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Rain.Compiler.Tokenization.DfaGraphs;
11+
12+
internal class IntFsa : Fsa, IFsa
13+
{
14+
private readonly FsaGraphNode _zero;
15+
private readonly FsaGraphNode _digit;
16+
private readonly FsaGraphNode _hexPrefix;
17+
private readonly FsaGraphNode _hex;
18+
private readonly FsaGraphNode _octat;
19+
private readonly FsaGraphNode _long;
20+
private readonly FsaGraphNode _unsigned;
21+
private readonly FsaGraphNode _unsignedLong;
22+
23+
internal IntFsa() : base()
24+
{
25+
_zero = new FsaGraphNode(IntFsaStateNames.Zero);
26+
_digit = new FsaGraphNode(IntFsaStateNames.Digit);
27+
_hexPrefix = new FsaGraphNode(IntFsaStateNames.HexPrefix);
28+
_hex = new FsaGraphNode(IntFsaStateNames.Hex);
29+
_octat = new FsaGraphNode(IntFsaStateNames.Octat);
30+
_long = new FsaGraphNode(IntFsaStateNames.Long);
31+
_unsigned = new FsaGraphNode(IntFsaStateNames.Unsigned);
32+
_unsignedLong = new FsaGraphNode(IntFsaStateNames.UnsignedLong);
33+
34+
AddVertex(_start);
35+
36+
AddEdge(_start, _zero, new("0"));
37+
38+
AddEdge(_zero, _long, new("[Ll]"));
39+
AddEdge(_long, _unsignedLong, new("[Uu]"));
40+
41+
AddEdge(_zero, _unsigned, new("[Uu]"));
42+
AddEdge(_unsigned, _unsignedLong, new("[Ll]"));
43+
44+
AddEdge(_zero, _hexPrefix, new("[Xx]"));
45+
AddEdge(_hexPrefix, _hex, new("[a-fA-F0-9]"));
46+
AddEdge(_hex, _hex, new("[a-fA-F0-9]"));
47+
AddEdge(_hex, _long, new("[Ll]"));
48+
AddEdge(_hex, _unsigned, new("[Uu]"));
49+
50+
AddEdge(_zero, _octat, new("[0-7]"));
51+
AddEdge(_zero, _unsigned, new("[Uu]"));
52+
53+
AddEdge(_start, _digit, new("[1-9]"));
54+
}
55+
}

0 commit comments

Comments
 (0)