public override LAD Reify(NFA pad) { Frame of = pad.outer_stack[pad.outer_stack.Count - 1]; SubInfo si = pad.info_stack[pad.info_stack.Count - 1]; while ((si == null || si.param == null) && of != null) { si = of.info; of = of.outer; } if (si == null || si.param == null || !(si.param[0] is P6any[])) throw new NieczaException("Cannot resolve dispatch operator"); P6any[] cands = si.param[0] as P6any[]; LAD[] opts = new LAD[cands.Length]; for (int i = 0; i < opts.Length; i++) { pad.outer_stack.Add(Kernel.GetOuter(cands[i])); pad.info_stack.Add(Kernel.GetInfo(cands[i])); opts[i] = Kernel.GetInfo(cands[i]).ltm.Reify(pad); pad.outer_stack.RemoveAt(pad.outer_stack.Count - 1); pad.info_stack.RemoveAt(pad.info_stack.Count - 1); } return new LADAny(opts); }
public LADAny(LAD[] zyg) { this.zyg = zyg; }
public override LAD Reify(NFA pad) { LAD[] nc = new LAD[zyg.Length]; for (int i = 0; i < zyg.Length; i++) nc[i] = zyg[i].Reify(pad); return new LADAny(nc); }
public static Lexer GetLexer(Frame fromf, STable kl, LAD[] lads, string title) { LexerCache lc = kl.GetLexerCache(); Lexer ret; if (lc.nfas.TryGetValue(lads, out ret)) return ret; if (lc.parent != null && lc.parent.mo.name != "Cursor" && lc.parent.mo.name != "Any") { ret = GetLexer(fromf, lc.parent.mo, lads, title); foreach (string u in ret.pad.used_methods) { if (lc.repl_methods.Contains(u)) goto anew; } if (LtmTrace) Console.WriteLine("Reused {0} alternation lexer for {1} in {2}", title, lc.parent.mo.name, kl.name); return lc.nfas[lads] = ret; } anew: if (LtmTrace) { Console.WriteLine("Need new alternation lexer for {0} in {1}", title, kl.name); } NFA pad = new NFA(); pad.cursor_class = kl; LAD[] lads_p = new LAD[lads.Length]; pad.outer_stack.Add(fromf); pad.info_stack.Add(fromf.info); for (int i = 0; i < lads_p.Length; i++) lads_p[i] = lads[i].Reify(pad); ret = new Lexer(pad, title, lads_p); lc.nfas[lads] = ret; return ret; }
//public readonly STable in_class; public AltInfo(LAD[] prefixes, string dba, int[] labels) { this.labels = labels; this.prefixes = prefixes; this.dba = dba; }
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 static Lexer GetDispatchLexer(STable kl, SubInfo disp) { LexerCache lc = kl.GetLexerCache(); Lexer ret; if (lc.dispatch_nfas.TryGetValue(disp, out ret)) return ret; if (lc.parent != null && lc.parent.mo.name != "Cursor" && lc.parent.mo.name != "Any") { ret = GetDispatchLexer(lc.parent.mo, disp); foreach (string u in ret.pad.used_methods) { if (lc.repl_methods.Contains(u)) goto anew; } if (LtmTrace) Console.WriteLine("Reused {0} dispatch lexer for {1} in {2}", disp.name, lc.parent.mo.name, kl.name); return lc.dispatch_nfas[disp] = ret; } anew: if (LtmTrace) { Console.WriteLine("Need new dispatch lexer for {0} in {1}", disp.name, kl.name); } NFA pad = new NFA(); pad.cursor_class = kl; P6any[] cands = (P6any[])disp.param[0]; LAD[] lads_p = new LAD[cands.Length]; for (int i = 0; i < lads_p.Length; i++) { pad.outer_stack.Add(Kernel.GetOuter(cands[i])); pad.info_stack.Add(Kernel.GetInfo(cands[i])); lads_p[i] = pad.info_stack[0].ltm.Reify(pad); pad.outer_stack.RemoveAt(pad.outer_stack.Count - 1); pad.info_stack.RemoveAt(pad.info_stack.Count - 1); } ret = new Lexer(pad, disp.name, lads_p); lc.dispatch_nfas[disp] = ret; return ret; }
public LADSequence(LAD[] args) { this.args = args; }
public override LAD Reify(NFA pad) { LAD[] nc = new LAD[args.Length]; for (int i = 0; i < args.Length; i++) nc[i] = args[i].Reify(pad); return new LADSequence(nc); }
public LADOpt(LAD child) { this.child = child; }
public LADQuant(int type, LAD z0, LAD z1) { this.type = type; this.z0 = z0; this.z1 = z1; }
public LADStar(LAD child) { this.child = child; }
public LADPlus(LAD child) { this.child = child; }
public override LAD Reify(NFA pad) { DynObject[] cands = Lexer.ResolveProtoregex(pad.cursor_class.GetLexerCache(), name); LAD[] opts = new LAD[cands.Length]; pad.used_methods.Add(name); for (int i = 0; i < opts.Length; i++) { pad.outer_stack.Add((Frame)cands[i].GetSlot("outer")); opts[i] = ((SubInfo)cands[i].GetSlot("info")).ltm.Reify(pad); pad.outer_stack.RemoveAt(pad.outer_stack.Count - 1); } return new LADAny(opts); }
public static Lexer GetProtoregexLexer(DynMetaObject kl, string name) { LexerCache lc = kl.GetLexerCache(); DynObject[] candidates = ResolveProtoregex(lc, name); Lexer l; if (lc.protorx_nfa.TryGetValue(name, out l)) { if (LtmTrace) Console.WriteLine("+ Protoregex lexer HIT on {0}.{1}", kl.name, name); return l; } if (LtmTrace) Console.WriteLine("+ Protoregex lexer MISS on {0}.{1}", kl.name, name); if (lc.parent != null && !lc.repl_methods.Contains(name)) { if (LtmTrace) Console.WriteLine("+ Trying to delegate to {0}", lc.parent.mo.name); Lexer pl = GetProtoregexLexer(lc.parent.mo, name); foreach (string used in pl.pad.used_methods) { if (lc.repl_methods.Contains(used)) { if (LtmTrace) Console.WriteLine("+ Can't; {0} is overridden", used); goto anew; } } if (LtmTrace) Console.WriteLine("+ Success!"); return lc.protorx_nfa[name] = pl; } anew: LAD[] branches = new LAD[candidates.Length]; NFA pad = new NFA(); pad.used_methods.Add(name); pad.cursor_class = kl; for (int i = 0; i < candidates.Length; i++) { pad.outer_stack.Add((Frame) candidates[i].GetSlot("outer")); branches[i] = (((SubInfo) candidates[i].GetSlot("info")).ltm). Reify(pad); pad.outer_stack.RemoveAt(pad.outer_stack.Count - 1); } return lc.protorx_nfa[name] = new Lexer(pad, name, branches); }
public LadingInfo(LAD lad = null) { Item = lad ?? new LAD(); }