示例#1
0
 public string ReadList(RulesTextCallback cb)
 {
     if (NextInstructionIsAccessor())
     {
         return(cb());
     }
     else
     {
         throw new UnexpectedByteException("Expected a list-getting instruction, got " + (Instruction)pop());
     }
 }
示例#2
0
 public string ReadCardLiteral(RulesTextCallback cb)
 {
     if (NextInstructionIsAccessor())
     {
         return(cb());
     }
     try {
         CheckType(Instruction.CARD);
         return($"Card {ReadIntLiteral(doNothing)}");
     } catch (UnexpectedByteException e) {
         throw e;
     }
 }
示例#3
0
 public string ReadBoolLiteral(RulesTextCallback cb)
 {
     if (NextInstructionIsAccessor())
     {
         return(cb());
     }
     try {
         CheckType(Instruction.BOOL);
         return((pop() != 0) ? "true" : "false");
     } catch (UnexpectedByteException e) {
         throw e;
     }
 }
示例#4
0
 public string ReadIntLiteral(RulesTextCallback cb)
 {
     if (NextInstructionIsAccessor())
     {
         return(cb());
     }
     try {
         CheckType(Instruction.INT);
         List <byte> intRepresentation = pop(4);
         int         num = BitConverter.ToInt32(intRepresentation.ToArray(), 0);
         return(num.ToString());
     } catch (UnexpectedByteException e) {
         throw e;
     }
 }
示例#5
0
 public string ReadStringLiteral(RulesTextCallback cb)
 {
     if (NextInstructionIsAccessor())
     {
         return(cb());
     }
     try {
         CheckType(Instruction.STRING);
         int         arrSize  = ReadIntLiteral(doNothing);
         List <byte> strArray = pop(arrSize);
         char[]      chars    = System.Text.Encoding.UTF8.GetChars(strArray.ToArray());
         return(new string(chars));
     } catch (UnexpectedByteException e) {
         throw e;
     }
 }
示例#6
0
 public RulesTextInterpreter(List <byte> arr)
 {
     push(arr);
     readAccessorFirst = ReadAccessorFirst;
     doNothing         = DoNothing;
 }