|
| 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