コード例 #1
0
ファイル: Key.cs プロジェクト: zain-tariq/ios-samples
 /// <summary>Print the key and rank only, not the rest.</summary>
 /// <remarks>Print the key and rank only, not the rest.</remarks>
 public virtual void PrintKey(int indent)
 {
     for (int i = 0; i < indent; i++)
     {
         ConsoleSurrogate.Write(" ");
     }
     ConsoleSurrogate.WriteLine("key: " + key + " " + rank);
 }
コード例 #2
0
ファイル: Decomp.cs プロジェクト: zain-tariq/ios-samples
 /// <summary>Get the next reassembly rule.</summary>
 /// <remarks>Get the next reassembly rule.</remarks>
 public virtual string NextRule()
 {
     if (reasemb.Count == 0)
     {
         ConsoleSurrogate.WriteLine("No reassembly rule.");
         return(null);
     }
     return((string)reasemb[currReasmb]);
 }
コード例 #3
0
ファイル: WordList.cs プロジェクト: zain-tariq/ios-samples
 /// <summary>Print a word list on one line.</summary>
 /// <remarks>Print a word list on one line.</remarks>
 public virtual void Print(int indent)
 {
     for (int i = 0; i < Count; i++)
     {
         string s = (string)this [i];
         ConsoleSurrogate.Write(s + "  ");
     }
     ConsoleSurrogate.WriteLine();
 }
コード例 #4
0
ファイル: Decomp.cs プロジェクト: zain-tariq/ios-samples
        /// <summary>Print out the decomp rule.</summary>
        /// <remarks>Print out the decomp rule.</remarks>
        public virtual void Print(int indent)
        {
            string m = mem ? "true" : "false";

            for (int i = 0; i < indent; i++)
            {
                ConsoleSurrogate.Write(" ");
            }
            ConsoleSurrogate.WriteLine("decomp: " + pattern + " " + m);
            reasemb.Print(indent + 2);
        }
コード例 #5
0
 /// <summary>Print the reassembly list.</summary>
 /// <remarks>Print the reassembly list.</remarks>
 public virtual void Print(int indent)
 {
     for (int i = 0; i < Count; i++)
     {
         for (int j = 0; j < indent; j++)
         {
             ConsoleSurrogate.Write(" ");
         }
         string s = (string)this[i];
         ConsoleSurrogate.WriteLine("reasemb: " + s);
     }
 }
コード例 #6
0
ファイル: SynList.cs プロジェクト: zain-tariq/ios-samples
 /// <summary>Prnt the synonym lists.</summary>
 /// <remarks>Prnt the synonym lists.</remarks>
 public virtual void Print(int indent)
 {
     for (int i = 0; i < Count; i++)
     {
         for (int j = 0; j < indent; j++)
         {
             ConsoleSurrogate.Write(" ");
         }
         ConsoleSurrogate.Write("synon: ");
         WordList w = (WordList)this[i];
         w.Print(indent);
     }
 }
コード例 #7
0
        /// <summary>Assembly a reply from a decomp rule and the input.</summary>
        /// <remarks>
        /// Assembly a reply from a decomp rule and the input. If the reassembly rule
        /// is goto, return null and give the gotoKey to use. Otherwise return the
        /// response.
        /// </remarks>
        private string Assemble(Decomp d, string[] reply, Key gotoKey)
        {
            string[] lines = new string[3];
            d.StepRule();
            string rule = d.NextRule();

            if (EString.Match(rule, "goto *", lines))
            {
                // goto rule -- set gotoKey and return false.
                gotoKey.Copy(keys.GetKey(lines[0]));
                if (gotoKey.GetKey() != null)
                {
                    return(null);
                }
                ConsoleSurrogate.WriteLine("Goto rule did not match key: " + lines[0]);
                return(null);
            }
            string work = string.Empty;

            while (EString.Match(rule, "* (#)*", lines))
            {
                // reassembly rule with number substitution
                rule = lines[2];
                // there might be more
                int n = 0;
                try
                {
                    n = int.Parse(lines[1]) - 1;
                }
                catch (FormatException)
                {
                    ConsoleSurrogate.WriteLine("Number is wrong in reassembly rule " + lines[1]);
                }
                if (n < 0 || n >= reply.Length)
                {
                    ConsoleSurrogate.WriteLine("Substitution number is bad " + lines[1]);
                    return(null);
                }
                reply[n] = post.Translate(reply[n]);
                work    += lines[0] + " " + reply[n];
            }
            work += rule;
            if (d.Mem())
            {
                mem.Save(work);
                return(null);
            }
            return(work);
        }
コード例 #8
0
ファイル: SynList.cs プロジェクト: zain-tariq/ios-samples
        /// <summary>
        /// Decomposition match,
        /// If decomp has no synonyms, do a regular match.
        /// </summary>
        /// <remarks>
        /// Decomposition match,
        /// If decomp has no synonyms, do a regular match.
        /// Otherwise, try all synonyms.
        /// </remarks>
        internal virtual bool MatchDecomp(string str, string pat, string[] lines)
        {
            if (!EString.Match(pat, "*@* *", lines))
            {
                //  no synonyms in decomp pattern
                return(EString.Match(str, pat, lines));
            }
            //  Decomp pattern has synonym -- isolate the synonym
            string first   = lines[0];
            string synWord = lines[1];
            string theRest = " " + lines[2];
            //  Look up the synonym
            WordList syn = Find(synWord);

            if (syn == null)
            {
                ConsoleSurrogate.WriteLine("Could not fnd syn list for " + synWord);
                return(false);
            }
            //  Try each synonym individually
            for (int i = 0; i < syn.Count; i++)
            {
                //  Make a modified pattern
                pat = first + (string)syn[i] + theRest;
                if (EString.Match(str, pat, lines))
                {
                    int n = EString.Count(first, '*');
                    //  Make room for the synonym in the match list.
                    for (int j = lines.Length - 2; j >= n; j--)
                    {
                        lines[j + 1] = lines[j];
                    }
                    //  The synonym goes in the match list.
                    lines[n] = (string)syn[i];
                    return(true);
                }
            }
            return(false);
        }
コード例 #9
0
 private int ReadScript(ILineSource linesource)
 {
     try
     {
         while (true)
         {
             string s;
             s = linesource.ReadLine();
             if (s == null)
             {
                 break;
             }
             Collect(s);
         }
     }
     catch (Exception)
     {
         ConsoleSurrogate.WriteLine("There was a problem reading the script file.");
         ConsoleSurrogate.WriteLine("Tried " + linesource.ToString());
         return(1);
     }
     return(0);
 }
コード例 #10
0
 /// <summary>Process a line of script input.</summary>
 /// <remarks>Process a line of script input.</remarks>
 private void Collect(string s)
 {
     string[] lines = new string[4];
     if (EString.Match(s, "*reasmb: *", lines))
     {
         if (lastReasemb == null)
         {
             ConsoleSurrogate.WriteLine("Error: no last reasemb");
             return;
         }
         lastReasemb.Add(lines[1]);
     }
     else
     {
         if (EString.Match(s, "*decomp: *", lines))
         {
             if (lastDecomp == null)
             {
                 ConsoleSurrogate.WriteLine("Error: no last decomp");
                 return;
             }
             lastReasemb = new ReasembList();
             string temp = lines[1];
             if (EString.Match(temp, "$ *", lines))
             {
                 lastDecomp.Add(lines[0], true, lastReasemb);
             }
             else
             {
                 lastDecomp.Add(temp, false, lastReasemb);
             }
         }
         else
         {
             if (EString.Match(s, "*key: * #*", lines))
             {
                 lastDecomp  = new DecompList();
                 lastReasemb = null;
                 int n = 0;
                 if (lines[2].Length != 0)
                 {
                     try
                     {
                         n = int.Parse(lines[2]);
                     }
                     catch (FormatException)
                     {
                         ConsoleSurrogate.WriteLine("Number is wrong in key: " + lines[2]);
                     }
                 }
                 keys.Add(lines[1], n, lastDecomp);
             }
             else
             {
                 if (EString.Match(s, "*key: *", lines))
                 {
                     lastDecomp  = new DecompList();
                     lastReasemb = null;
                     keys.Add(lines[1], 0, lastDecomp);
                 }
                 else
                 {
                     if (EString.Match(s, "*synon: * *", lines))
                     {
                         WordList words = new WordList();
                         words.Add(lines[1]);
                         s = lines[2];
                         while (EString.Match(s, "* *", lines))
                         {
                             words.Add(lines[0]);
                             s = lines[1];
                         }
                         words.Add(s);
                         syns.Add(words);
                     }
                     else
                     {
                         if (EString.Match(s, "*pre: * *", lines))
                         {
                             pre.Add(lines[1], lines[2]);
                         }
                         else
                         {
                             if (EString.Match(s, "*post: * *", lines))
                             {
                                 post.Add(lines[1], lines[2]);
                             }
                             else
                             {
                                 if (EString.Match(s, "*initial: *", lines))
                                 {
                                     initial = lines[1];
                                 }
                                 else
                                 {
                                     if (EString.Match(s, "*final: *", lines))
                                     {
                                         finl = lines[1];
                                     }
                                     else
                                     {
                                         if (EString.Match(s, "*quit: *", lines))
                                         {
                                             quit.Add(" " + lines[1] + " ");
                                         }
                                         else
                                         {
                                             ConsoleSurrogate.WriteLine("Unrecognized input: " + s);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }