public Lexer(NFA pad, string tag, LAD[] alts) { this.pad = pad; this.alts = alts; this.tag = tag; int root = pad.AddNode(); int[] alt_shuffle = new int[alts.Length]; for (int i = 0; i < alts.Length; i++) alt_shuffle[i] = i; Array.Sort(alt_shuffle, delegate (int i1, int i2) { int j1, j2; bool c1, c2; alts[i1].QueryLiteral(pad, out j1, out c1); alts[i2].QueryLiteral(pad, out j2, out c2); return (j1 != j2) ? (j2 - j1) : (i1 - i2); }); for (int ix = 0; ix < alts.Length; ix++) { pad.curfate = alt_shuffle[ix]; int target = pad.AddNode(); pad.nodes_l[target].final = true; alts[alt_shuffle[ix]].ToNFA(pad, root, target); } nfates = alts.Length; fatebuffer = new int[nfates*2+2]; for (int i = 0; i < nfates*2+2; i++) fatebuffer[i] = -1; fatebuffer[0] = fatebuffer[1] = 0; pad.Complete(); // now the NFA nodes are all in tiebreak order by lowest index if (LtmTrace) { Dump(); } start = new LexerState(pad); start.Add(0); pad.Close(start); nil = new LexerState(pad); pad.dfashare[nil] = nil; pad.dfashare[start] = start; }
public LexerState Next(NFA nf, int ch) { LexerState l; if (dfc.TryGetValue(ch, out l)) return l; l = new LexerState(nf); for (int i = 0; i < nstates.Length; i++) { int bm = nstates[i]; for (int j = 0; j < 32; j++) { if ((bm & (1 << j)) == 0) continue; foreach (NFA.Edge e in nf.nodes[32*i + j].edges) { if (e.when != null && e.when.Accepts(ch)) l.Add(e.to); } } } nf.Close(l); LexerState cl; if (!nf.dfashare.TryGetValue(l, out cl)) { nf.dfashare[l] = cl = l; } dfc[ch] = cl; return cl; }
public LexerState Next(NFA nf, int ch) { LexerState l; if (dfc.TryGetValue(ch, out l)) return l; l = new LexerState(nf); for (int i = 0; i < nstates.Length; i++) { int bm = nstates[i]; for (int j = 0; j < 32; j++) { if ((bm & (1 << j)) == 0) continue; int ei = 0, eimax = 0; var es = nf.EdgesOf(32*i + j, ref ei, ref eimax); while (ei != eimax) { var e = es[ei++]; if (e.when == ch || e.when == -1 && e.when_cc.Accepts(ch)) l.Add(e.to); } } } nf.Close(l); LexerState cl; if (!nf.dfashare.TryGetValue(l, out cl)) { nf.dfashare[l] = cl = l; } dfc[ch] = cl; return cl; }