public string ReadList(RulesTextCallback cb) { if (NextInstructionIsAccessor()) { return(cb()); } else { throw new UnexpectedByteException("Expected a list-getting instruction, got " + (Instruction)pop()); } }
public string ReadCardLiteral(RulesTextCallback cb) { if (NextInstructionIsAccessor()) { return(cb()); } try { CheckType(Instruction.CARD); return($"Card {ReadIntLiteral(doNothing)}"); } catch (UnexpectedByteException e) { throw e; } }
public string ReadBoolLiteral(RulesTextCallback cb) { if (NextInstructionIsAccessor()) { return(cb()); } try { CheckType(Instruction.BOOL); return((pop() != 0) ? "true" : "false"); } catch (UnexpectedByteException e) { throw e; } }
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; } }
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; } }
public RulesTextInterpreter(List <byte> arr) { push(arr); readAccessorFirst = ReadAccessorFirst; doNothing = DoNothing; }