Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="options"></param>
        public EM300LRHub(ILogger <EM300LRHub> logger, IOptions <AppSettings> options)
            : base(logger, new HubSettings() { Uri = options.Value.EM300LR })
        {
            _logger.LogDebug("EM300LRHub()");

            _hub.On <TotalData>("UpdateTotal", async(data) =>
            {
                _logger.LogDebug("On<TotalData>()");

                await CoreApplication.MainView
                .Dispatcher
                .RunAsync(CoreDispatcherPriority.Normal,
                          () => TotalData = data);
            });

            _hub.On <Phase1Data>("UpdatePhase1", async(data) =>
            {
                _logger.LogDebug("On<Phase1Data>()");

                await CoreApplication.MainView
                .Dispatcher
                .RunAsync(CoreDispatcherPriority.Normal,
                          () => Phase1Data = data);
            });

            _hub.On <Phase2Data>("UpdatePhase2", async(data) =>
            {
                _logger.LogDebug("On<Phase2Data>()");

                await CoreApplication.MainView
                .Dispatcher
                .RunAsync(CoreDispatcherPriority.Normal,
                          () => Phase2Data = data);
            });

            _hub.On <Phase3Data>("UpdatePhase3", async(data) =>
            {
                _logger.LogDebug("On<Phase3Data>()");

                await CoreApplication.MainView
                .Dispatcher
                .RunAsync(CoreDispatcherPriority.Normal,
                          () => Phase3Data = data);
            });
        }
Пример #2
0
        private static void generate3R(Expansion e, Phase3Data inf)
        {
            Expansion seq = e;
            if (e.InternalName.Equals("")) {
                while (true) {
                    if (seq is Sequence && ((Sequence) seq).Units.Count == 2) {
                        seq = ((Sequence) seq).Units[1];
                    } else if (seq is NonTerminal) {
                        NonTerminal e_nrw = (NonTerminal) seq;
                        NormalProduction ntprod = productionTable[e_nrw.Name];
                        if (ntprod is CodeProduction) {
                            break; // nothing to do here
                        } else {
                            seq = ntprod.Expansion;
                        }
                    } else
                        break;
                }

                if (seq is RegularExpression) {
                    e.InternalName = "cc_scan_token(" + seq.Ordinal + ")";
                    return;
                }

                gensymindex++;
                e.InternalName = "R_" + gensymindex;
            }
            Phase3Data p3d;
            if (!phase3table.TryGetValue(e, out p3d) ||
                p3d.Count < inf.Count) {
                p3d = new Phase3Data(e, inf.Count);
                phase3list.Add(p3d);
                phase3table[e] = p3d;
            }
        }
Пример #3
0
        private static void buildPhase3Routine(Phase3Data inf, bool recursive_call)
        {
            Expansion e = inf.Expansion;
            Token t = null;
            if (e.InternalName.StartsWith("cc_scan_token"))
                return;

            if (!recursive_call) {
                ostr.WriteLine("  private " + CSharpCCGlobals.staticOpt() + "bool cc_3" + e.InternalName + "() {");
                xsp_declared = false;
                if (Options.getDebugLookahead() && e.Parent is NormalProduction) {
                    ostr.Write("    ");
                    if (Options.getErrorReporting()) {
                        ostr.Write("if (!cc_rescan) ");
                    }
                    ostr.WriteLine("trace_call(\"" + ((NormalProduction) e.Parent).Lhs + "(LOOKING AHEAD...)\");");
                    cc3_expansion = e;
                } else {
                    cc3_expansion = null;
                }
            }
            if (e is RegularExpression) {
                RegularExpression e_nrw = (RegularExpression) e;
                if (e_nrw.Label.Equals("")) {
                    string label;
                    if (CSharpCCGlobals.names_of_tokens.TryGetValue(e_nrw.Ordinal, out label)) {
                        ostr.WriteLine("    if (cc_scan_token(" + label + ")) " + genReturn(true));
                    } else {
                        ostr.WriteLine("    if (cc_scan_token(" + e_nrw.Ordinal + ")) " + genReturn(true));
                    }
                } else {
                    ostr.WriteLine("    if (cc_scan_token(" + e_nrw.Label + ")) " + genReturn(true));
                }
            } else if (e is NonTerminal) {
                // All expansions of non-terminals have the "name" fields set.  So
                // there's no need to check it below for "e_nrw" and "ntexp".  In
                // fact, we rely here on the fact that the "name" fields of both these
                // variables are the same.
                NonTerminal e_nrw = (NonTerminal) e;
                NormalProduction ntprod = productionTable[e_nrw.Name];
                if (ntprod is CodeProduction) {
                    ostr.WriteLine("    if (true) { cc_la = 0; cc_scanpos = cc_lastpos; " + genReturn(false) + "}");
                } else {
                    Expansion ntexp = ntprod.Expansion;
                    ostr.WriteLine("    if (" + gencc_3Call(ntexp) + ") " + genReturn(true));
                }
            } else if (e is Choice) {
                Sequence nested_seq;
                Choice e_nrw = (Choice) e;
                if (e_nrw.Choices.Count != 1) {
                    if (!xsp_declared) {
                        xsp_declared = true;
                        ostr.WriteLine("    Token xsp;");
                    }
                    ostr.WriteLine("    xsp = cc_scanpos;");
                }
                for (int i = 0; i < e_nrw.Choices.Count; i++) {
                    nested_seq = (Sequence) (e_nrw.Choices[i]);
                    Lookahead la = (Lookahead) (nested_seq.Units[0]);
                    if (la.ActionTokens.Count != 0) {
                        // We have semantic lookahead that must be evaluated.
                        CSharpCCGlobals.lookaheadNeeded = true;
                        ostr.WriteLine("    cc_lookingAhead = true;");
                        ostr.Write("    cc_semLA = ");
                        CSharpCCGlobals.PrintTokenSetup(la.ActionTokens[0]);
                        foreach (var token in la.ActionTokens) {
                            t = token;
                            CSharpCCGlobals.PrintToken(t, ostr);
                        }
                        CSharpCCGlobals.PrintTrailingComments(t, ostr);
                        ostr.WriteLine(";");
                        ostr.WriteLine("    cc_lookingAhead = false;");
                    }
                    ostr.Write("    if (");
                    if (la.ActionTokens.Count != 0) {
                        ostr.Write("!cc_semLA || ");
                    }
                    if (i != e_nrw.Choices.Count - 1) {
                        ostr.WriteLine(gencc_3Call(nested_seq) + ") {");
                        ostr.WriteLine("    cc_scanpos = xsp;");
                    } else {
                        ostr.WriteLine(gencc_3Call(nested_seq) + ") " + genReturn(true));
                    }
                }
                for (int i = 1; i < e_nrw.Choices.Count; i++) {
                    ostr.WriteLine("    }");
                }
            } else if (e is Sequence) {
                Sequence e_nrw = (Sequence) e;
                // We skip the first element in the following iteration since it is the
                // Lookahead object.
                int cnt = inf.Count;
                for (int i = 1; i < e_nrw.Units.Count; i++) {
                    Expansion eseq = (Expansion) (e_nrw.Units[i]);
                    buildPhase3Routine(new Phase3Data(eseq, cnt), true);

                    cnt -= minimumSize(eseq);
                    if (cnt <= 0)
                        break;
                }
            } else if (e is TryBlock) {
                TryBlock e_nrw = (TryBlock) e;
                buildPhase3Routine(new Phase3Data(e_nrw.Expansion, inf.Count), true);
            } else if (e is OneOrMore) {
                if (!xsp_declared) {
                    xsp_declared = true;
                    ostr.WriteLine("    Token xsp;");
                }
                OneOrMore e_nrw = (OneOrMore) e;
                Expansion nested_e = e_nrw.Expansion;
                ostr.WriteLine("    if (" + gencc_3Call(nested_e) + ") " + genReturn(true));
                ostr.WriteLine("    while (true) {");
                ostr.WriteLine("      xsp = cc_scanpos;");
                ostr.WriteLine("      if (" + gencc_3Call(nested_e) + ") { cc_scanpos = xsp; break; }");
                ostr.WriteLine("    }");
            } else if (e is ZeroOrMore) {
                if (!xsp_declared) {
                    xsp_declared = true;
                    ostr.WriteLine("    Token xsp;");
                }
                ZeroOrMore e_nrw = (ZeroOrMore) e;
                Expansion nested_e = e_nrw.Expansion;
                ostr.WriteLine("    while (true) {");
                ostr.WriteLine("      xsp = cc_scanpos;");
                ostr.WriteLine("      if (" + gencc_3Call(nested_e) + ") { cc_scanpos = xsp; break; }");
                ostr.WriteLine("    }");
            } else if (e is ZeroOrOne) {
                if (!xsp_declared) {
                    xsp_declared = true;
                    ostr.WriteLine("    Token xsp;");
                }
                ZeroOrOne e_nrw = (ZeroOrOne) e;
                Expansion nested_e = e_nrw.Expansion;
                ostr.WriteLine("    xsp = cc_scanpos;");
                ostr.WriteLine("    if (" + gencc_3Call(nested_e) + ") cc_scanpos = xsp;");
            }
            if (!recursive_call) {
                ostr.WriteLine("    " + genReturn(false));
                ostr.WriteLine("  }");
                ostr.WriteLine("");
            }
        }
Пример #4
0
 private static void buildPhase2Routine(Lookahead la)
 {
     Expansion e = la.Expansion;
     ostr.WriteLine("  private " + CSharpCCGlobals.staticOpt() + " bool cc_2" + e.InternalName + "(int xla) {");
     ostr.WriteLine("    cc_la = xla; cc_lastpos = cc_scanpos = token;");
     ostr.WriteLine("    try { return !cc_3" + e.InternalName + "(); }");
     ostr.WriteLine("    catch(LookaheadSuccess) { return true; }");
     if (Options.getErrorReporting())
         ostr.WriteLine("    finally { cc_save(" + (Int32.Parse(e.InternalName.Substring(1), CultureInfo.InvariantCulture) - 1) + ", xla); }");
     ostr.WriteLine("  }");
     ostr.WriteLine("");
     Phase3Data p3d = new Phase3Data(e, la.Amount);
     phase3list.Add(p3d);
     phase3table[e] = p3d;
 }
Пример #5
0
 private static void setupPhase3Builds(Phase3Data inf)
 {
     Expansion e = inf.Expansion;
     if (e is RegularExpression) {
         ; // nothing to here
     } else if (e is NonTerminal) {
         // All expansions of non-terminals have the "name" fields set.  So
         // there's no need to check it below for "e_nrw" and "ntexp".  In
         // fact, we rely here on the fact that the "name" fields of both these
         // variables are the same.
         NonTerminal e_nrw = (NonTerminal) e;
         NormalProduction ntprod = productionTable[e_nrw.Name];
         if (ntprod is CodeProduction) {
             ; // nothing to do here
         } else {
             generate3R(ntprod.Expansion, inf);
         }
     } else if (e is Choice) {
         Choice e_nrw = (Choice) e;
         for (int i = 0; i < e_nrw.Choices.Count; i++) {
             generate3R(e_nrw.Choices[i], inf);
         }
     } else if (e is Sequence) {
         Sequence e_nrw = (Sequence) e;
         // We skip the first element in the following iteration since it is the
         // Lookahead object.
         int cnt = inf.Count;
         for (int i = 1; i < e_nrw.Units.Count; i++) {
             Expansion eseq = e_nrw.Units[i];
             setupPhase3Builds(new Phase3Data(eseq, cnt));
             cnt -= minimumSize(eseq);
             if (cnt <= 0)
                 break;
         }
     } else if (e is TryBlock) {
         TryBlock e_nrw = (TryBlock) e;
         setupPhase3Builds(new Phase3Data(e_nrw.Expansion, inf.Count));
     } else if (e is OneOrMore) {
         OneOrMore e_nrw = (OneOrMore) e;
         generate3R(e_nrw.Expansion, inf);
     } else if (e is ZeroOrMore) {
         ZeroOrMore e_nrw = (ZeroOrMore) e;
         generate3R(e_nrw.Expansion, inf);
     } else if (e is ZeroOrOne) {
         ZeroOrOne e_nrw = (ZeroOrOne) e;
         generate3R(e_nrw.Expansion, inf);
     }
 }