[15771] | 1 | using System;
|
---|
| 2 | using System.Linq;
|
---|
| 3 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; |
---|
| 4 | |
---|
| 5 | namespace HeuristicLab.Problems.ProgramSynthesis { |
---|
[15017] | 6 |
|
---|
[15032] | 7 | /// <summary>
|
---|
| 8 | /// Pushes TRUE onto the BOOLEAN stack if the top char represents a whitespace char, otherwise FALSE.
|
---|
| 9 | /// </summary>
|
---|
| 10 | [PushExpression(
|
---|
| 11 | StackTypes.Char,
|
---|
| 12 | "CHAR.ISWHITESPACE",
|
---|
| 13 | "Pushes TRUE onto the BOOLEAN stack if the top char represents a whitespace char, otherwise FALSE.",
|
---|
| 14 | StackTypes.Boolean)]
|
---|
[14952] | 15 | [StorableClass]
|
---|
[14777] | 16 | public class CharIsWhitespaceExpression : StatelessExpression {
|
---|
[14952] | 17 | public CharIsWhitespaceExpression() { }
|
---|
| 18 | [StorableConstructor]
|
---|
| 19 | public CharIsWhitespaceExpression(bool deserializing) : base(deserializing) { }
|
---|
[14777] | 20 |
|
---|
[14952] | 21 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 22 | return interpreter.CharStack.IsEmpty;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
[14777] | 26 | var c = interpreter.CharStack.Pop();
|
---|
| 27 | interpreter.BooleanStack.Push(char.IsWhiteSpace(c));
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 |
|
---|
[15032] | 31 | /// <summary>
|
---|
| 32 | /// Pushes TRUE onto the CHAR stack if the top char represents a letter, otherwise FALSE.
|
---|
| 33 | /// </summary>
|
---|
| 34 | [PushExpression(
|
---|
| 35 | StackTypes.Char,
|
---|
| 36 | "CHAR.ISLETTER",
|
---|
| 37 | "Pushes TRUE onto the CHAR stack if the top char represents a letter, otherwise FALSE.",
|
---|
| 38 | StackTypes.Boolean)]
|
---|
[14952] | 39 | [StorableClass]
|
---|
[14777] | 40 | public class CharIsLetterExpression : StatelessExpression {
|
---|
[14952] | 41 | public CharIsLetterExpression() { }
|
---|
| 42 | [StorableConstructor]
|
---|
| 43 | public CharIsLetterExpression(bool deserializing) : base(deserializing) { }
|
---|
[14777] | 44 |
|
---|
[14952] | 45 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 46 | return interpreter.CharStack.IsEmpty;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
[14777] | 50 | var c = interpreter.CharStack.Pop();
|
---|
| 51 | interpreter.BooleanStack.Push(char.IsLetter(c));
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[15032] | 55 | /// <summary>
|
---|
| 56 | /// Pushes TRUE onto the CHAR stack if the top char represents a digit, otherwise FALSE.
|
---|
| 57 | /// </summary>
|
---|
| 58 | [PushExpression(
|
---|
| 59 | StackTypes.Char,
|
---|
| 60 | "CHAR.ISDIGIT",
|
---|
| 61 | "Pushes TRUE onto the CHAR stack if the top char represents a digit, otherwise FALSE.",
|
---|
| 62 | StackTypes.Boolean)]
|
---|
[14952] | 63 | [StorableClass]
|
---|
[14777] | 64 | public class CharIsDigitExpression : StatelessExpression {
|
---|
[14952] | 65 | public CharIsDigitExpression() { }
|
---|
| 66 | [StorableConstructor]
|
---|
| 67 | public CharIsDigitExpression(bool deserializing) : base(deserializing) { }
|
---|
[14777] | 68 |
|
---|
[14952] | 69 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 70 | return interpreter.CharStack.IsEmpty;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
[14777] | 74 | var c = interpreter.CharStack.Pop();
|
---|
| 75 | interpreter.BooleanStack.Push(char.IsDigit(c));
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[15032] | 79 | /// <summary>
|
---|
| 80 | /// Takes the top integer, converts it to an char using ASCII encoding and pushes this char onto the CHAR stack.
|
---|
| 81 | /// </summary>
|
---|
| 82 | [PushExpression(
|
---|
| 83 | StackTypes.Char,
|
---|
| 84 | "CHAR.FROMINTEGER",
|
---|
| 85 | "Takes the top integer, converts it to an char using ASCII encoding and pushes this char onto the CHAR stack.",
|
---|
| 86 | StackTypes.Integer)]
|
---|
[14952] | 87 | [StorableClass]
|
---|
[14777] | 88 | public class CharFromIntegerExpression : StatelessExpression {
|
---|
[14952] | 89 | public CharFromIntegerExpression() { }
|
---|
| 90 | [StorableConstructor]
|
---|
| 91 | public CharFromIntegerExpression(bool deserializing) : base(deserializing) { }
|
---|
[14777] | 92 |
|
---|
[14952] | 93 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 94 | return interpreter.IntegerStack.IsEmpty;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
[14777] | 98 | var value = (int)Math.Abs(interpreter.IntegerStack.Pop() % 128);
|
---|
| 99 | var c = Convert.ToChar(value);
|
---|
| 100 |
|
---|
| 101 | interpreter.CharStack.Push(c);
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[15032] | 105 | /// <summary>
|
---|
| 106 | /// Takes the top float, casts it to an integer, converts it to an char using ASCII encoding and pushes this char onto the CHAR stack.
|
---|
| 107 | /// </summary>
|
---|
| 108 | [PushExpression(
|
---|
| 109 | StackTypes.Char,
|
---|
| 110 | "CHAR.FROMFLOAT",
|
---|
| 111 | "Takes the top float, casts it to an integer, converts it to an char using ASCII encoding and pushes this char onto the CHAR stack.",
|
---|
| 112 | StackTypes.Float)]
|
---|
[14952] | 113 | [StorableClass]
|
---|
[14777] | 114 | public class CharFromFloatExpression : StatelessExpression {
|
---|
[14952] | 115 | public CharFromFloatExpression() { }
|
---|
| 116 | [StorableConstructor]
|
---|
| 117 | public CharFromFloatExpression(bool deserializing) : base(deserializing) { }
|
---|
[14777] | 118 |
|
---|
[14952] | 119 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 120 | return interpreter.FloatStack.IsEmpty;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
[14777] | 124 | var value = (int)Math.Abs(interpreter.FloatStack.Pop() % 128);
|
---|
| 125 | var c = Convert.ToChar(value);
|
---|
| 126 |
|
---|
| 127 | interpreter.CharStack.Push(c);
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 |
|
---|
[15032] | 131 | /// <summary>
|
---|
| 132 | /// Takes the top string and pushes the chars of this string onto the CHAR stack in reversed order.
|
---|
| 133 | /// </summary>
|
---|
| 134 | [PushExpression(
|
---|
| 135 | StackTypes.Char,
|
---|
| 136 | "CHAR.ALLFROMSTRING",
|
---|
| 137 | "Takes the top string and pushes the chars of this string onto the CHAR stack in reversed order.",
|
---|
| 138 | StackTypes.String)]
|
---|
[14952] | 139 | [StorableClass]
|
---|
[14777] | 140 | public class CharAllFromStringExpression : StatelessExpression {
|
---|
[14952] | 141 | public CharAllFromStringExpression() { }
|
---|
| 142 | [StorableConstructor]
|
---|
| 143 | public CharAllFromStringExpression(bool deserializing) : base(deserializing) { }
|
---|
[14777] | 144 |
|
---|
[14952] | 145 | public override bool IsNoop(IInternalPushInterpreter interpreter) {
|
---|
| 146 | return interpreter.StringStack.IsEmpty;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | public override void Eval(IInternalPushInterpreter interpreter) {
|
---|
[15189] | 150 | var chars = interpreter.StringStack.Pop().Reverse().ToList();
|
---|
[14777] | 151 | interpreter.CharStack.Push(chars);
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | }
|
---|