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 override void ToNFA(NFA pad, int from, int to) { int knot = pad.AddNode(); pad.nodes_l[knot].final = true; pad.AddEdge(from, knot, null); }
public override void ToNFA(NFA pad, int from, int to) { for (int i = 0; i < args.Length; i++) { int knot = (i == args.Length - 1) ? to : pad.AddNode(); args[i].ToNFA(pad, from, knot); from = knot; } if (from != to) pad.AddEdge(from, to, null); }
public override void ToNFA(NFA pad, int from, int to) { if (text.Length == 0) { pad.AddEdge(from, to, null); } else { int len = text.Length; for (int c = 0; c < len; c++) { int fromp = (c == len - 1) ? to : pad.AddNode(); pad.AddEdge(from, fromp, new CC(text[c], true)); from = fromp; } } }
public override bool ToNFA(NFA pad, int from, int to) { int knot = pad.AddNode(); pad.SetFinal(knot); pad.AddEdge(from, knot, null); return false; }
public override void ToNFA(NFA pad, int from, int to) { int knot1 = pad.AddNode(); int knot2 = pad.AddNode(); int knot3 = pad.AddNode(); pad.AddEdge(from, knot1, null); z0.ToNFA(pad, knot1, knot2); if (z1 != null) z1.ToNFA(pad, knot2, knot3); else pad.AddEdge(knot2, knot3, null); pad.AddEdge(knot2, to, null); if ((type & 1) != 0) pad.AddEdge(from, to, null); if ((type & 4) != 0) pad.AddEdge(knot3, to, null); if ((type & 2) != 0) pad.AddEdge(knot3, knot1, null); }
public override bool ToNFA(NFA pad, int from, int to) { if (text.Length == 0) { pad.AddEdge(from, to, null); } else { int len = text.Length; for (int c = 0; c < len; c++) { int fromp = (c == len - 1) ? to : pad.AddNode(); pad.AddEdge(from, fromp, (int)text[c]); // XXX supplementaries from = fromp; } } return true; }
public override bool ToNFA(NFA pad, int from, int to) { for (int i = 0; i < args.Length; i++) { int knot = (i == args.Length - 1) ? to : pad.AddNode(); if (!args[i].ToNFA(pad, from, knot)) return false; from = knot; } if (from != to) pad.AddEdge(from, to, null); return true; }
public override bool ToNFA(NFA pad, int from, int to) { int knot1 = pad.AddNode(); int knot2 = pad.AddNode(); int knot3 = pad.AddNode(); pad.AddEdge(from, knot1, null); z0.ToNFA(pad, knot1, knot2); if (z1 != null) z1.ToNFA(pad, knot2, knot3); else pad.AddEdge(knot2, knot3, null); pad.AddEdge(knot2, to, null); if ((type & 1) != 0) pad.AddEdge(from, to, null); if ((type & 4) != 0) pad.AddEdge(knot3, to, null); if ((type & 2) != 0) pad.AddEdge(knot3, knot1, null); return true; // conservative }
public override void ToNFA(NFA pad, int from, int to) { int knot = pad.AddNode(); pad.AddEdge(from, knot, null); pad.AddEdge(knot, to, null); child.ToNFA(pad, knot, knot); }
public override void ToNFA(NFA pad, int from, int to) { int knot1 = pad.AddNode(); int knot2 = pad.AddNode(); pad.AddEdge(from, knot1, null); pad.AddEdge(knot2, to, null); pad.AddEdge(knot2, knot1, null); child.ToNFA(pad, knot1, knot2); }