예제 #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;
 }