Esempio n. 1
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);
        }
Esempio n. 2
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;
 }