コード例 #1
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
    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);
    }
コード例 #2
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
 public LADAny(LAD[] zyg)
 {
     this.zyg = zyg;
 }
コード例 #3
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
 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);
 }
コード例 #4
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
    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;
    }
コード例 #5
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
 //public readonly STable in_class;
 public AltInfo(LAD[] prefixes, string dba, int[] labels)
 {
     this.labels = labels;
     this.prefixes = prefixes;
     this.dba = dba;
 }
コード例 #6
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
 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;
 }
コード例 #7
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
    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;
    }
コード例 #8
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
 public LADSequence(LAD[] args)
 {
     this.args = args;
 }
コード例 #9
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
 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);
 }
コード例 #10
0
ファイル: Cursor.cs プロジェクト: Util/niecza
 public LADOpt(LAD child)
 {
     this.child = child;
 }
コード例 #11
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
 public LADQuant(int type, LAD z0, LAD z1)
 {
     this.type = type; this.z0 = z0; this.z1 = z1;
 }
コード例 #12
0
ファイル: Cursor.cs プロジェクト: Util/niecza
 public LADStar(LAD child)
 {
     this.child = child;
 }
コード例 #13
0
ファイル: Cursor.cs プロジェクト: Util/niecza
 public LADPlus(LAD child)
 {
     this.child = child;
 }
コード例 #14
0
ファイル: Cursor.cs プロジェクト: pmurias/niecza
    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);
    }
コード例 #15
0
ファイル: Cursor.cs プロジェクト: pmurias/niecza
    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);
    }
コード例 #16
0
 public LadingInfo(LAD lad = null)
 {
     Item = lad ?? new LAD();
 }