Changeset 14952 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/CharExpressions.cs
- Timestamp:
- 05/10/17 11:23:05 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/CharExpressions.cs
r14834 r14952 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { 2 2 using System; 3 4 using HeuristicLab.Problems.ProgramSynthesis.Push.Attributes;5 using HeuristicLab.Problems.ProgramSynthesis.Push.Interpreter;6 using HeuristicLab.Problems.ProgramSynthesis.Push.Stack;3 using Attributes; 4 using Interpreter; 5 using Persistence.Default.CompositeSerializers.Storable; 6 using Stack; 7 7 8 8 [PushExpression(StackTypes.Char, "CHAR.ISWHITESPACE", StackTypes.Boolean)] 9 [StorableClass] 9 10 public class CharIsWhitespaceExpression : StatelessExpression { 10 public override bool Eval(IInternalPushInterpreter interpreter) { 11 if (interpreter.CharStack.IsEmpty) return false; 11 public CharIsWhitespaceExpression() { } 12 [StorableConstructor] 13 public CharIsWhitespaceExpression(bool deserializing) : base(deserializing) { } 12 14 15 public override bool IsNoop(IInternalPushInterpreter interpreter) { 16 return interpreter.CharStack.IsEmpty; 17 } 18 19 public override void Eval(IInternalPushInterpreter interpreter) { 13 20 var c = interpreter.CharStack.Pop(); 14 21 interpreter.BooleanStack.Push(char.IsWhiteSpace(c)); 15 return true;16 22 } 17 23 } 18 24 19 25 [PushExpression(StackTypes.Char, "CHAR.ISLETTER", StackTypes.Boolean)] 26 [StorableClass] 20 27 public class CharIsLetterExpression : StatelessExpression { 21 public override bool Eval(IInternalPushInterpreter interpreter) { 22 if (interpreter.CharStack.IsEmpty) return false; 28 public CharIsLetterExpression() { } 29 [StorableConstructor] 30 public CharIsLetterExpression(bool deserializing) : base(deserializing) { } 23 31 32 public override bool IsNoop(IInternalPushInterpreter interpreter) { 33 return interpreter.CharStack.IsEmpty; 34 } 35 36 public override void Eval(IInternalPushInterpreter interpreter) { 24 37 var c = interpreter.CharStack.Pop(); 25 38 interpreter.BooleanStack.Push(char.IsLetter(c)); 26 return true;27 39 } 28 40 } 29 41 30 42 [PushExpression(StackTypes.Char, "CHAR.ISDIGIT", StackTypes.Boolean)] 43 [StorableClass] 31 44 public class CharIsDigitExpression : StatelessExpression { 32 public override bool Eval(IInternalPushInterpreter interpreter) { 33 if (interpreter.CharStack.IsEmpty) return false; 45 public CharIsDigitExpression() { } 46 [StorableConstructor] 47 public CharIsDigitExpression(bool deserializing) : base(deserializing) { } 34 48 49 public override bool IsNoop(IInternalPushInterpreter interpreter) { 50 return interpreter.CharStack.IsEmpty; 51 } 52 53 public override void Eval(IInternalPushInterpreter interpreter) { 35 54 var c = interpreter.CharStack.Pop(); 36 55 interpreter.BooleanStack.Push(char.IsDigit(c)); 37 return true;38 56 } 39 57 } 40 58 41 59 [PushExpression(StackTypes.Char, "CHAR.FROMINTEGER", StackTypes.Integer)] 60 [StorableClass] 42 61 public class CharFromIntegerExpression : StatelessExpression { 43 public override bool Eval(IInternalPushInterpreter interpreter) { 44 if (interpreter.IntegerStack.IsEmpty) return false; 62 public CharFromIntegerExpression() { } 63 [StorableConstructor] 64 public CharFromIntegerExpression(bool deserializing) : base(deserializing) { } 45 65 66 public override bool IsNoop(IInternalPushInterpreter interpreter) { 67 return interpreter.IntegerStack.IsEmpty; 68 } 69 70 public override void Eval(IInternalPushInterpreter interpreter) { 46 71 var value = (int)Math.Abs(interpreter.IntegerStack.Pop() % 128); 47 72 var c = Convert.ToChar(value); 48 73 49 74 interpreter.CharStack.Push(c); 50 return true;51 75 } 52 76 } 53 77 54 78 [PushExpression(StackTypes.Char, "CHAR.FROMFLOAT", StackTypes.Float)] 79 [StorableClass] 55 80 public class CharFromFloatExpression : StatelessExpression { 56 public override bool Eval(IInternalPushInterpreter interpreter) { 57 if (interpreter.FloatStack.IsEmpty) return false; 81 public CharFromFloatExpression() { } 82 [StorableConstructor] 83 public CharFromFloatExpression(bool deserializing) : base(deserializing) { } 58 84 85 public override bool IsNoop(IInternalPushInterpreter interpreter) { 86 return interpreter.FloatStack.IsEmpty; 87 } 88 89 public override void Eval(IInternalPushInterpreter interpreter) { 59 90 var value = (int)Math.Abs(interpreter.FloatStack.Pop() % 128); 60 91 var c = Convert.ToChar(value); 61 92 62 93 interpreter.CharStack.Push(c); 63 return true;64 94 } 65 95 } 66 96 67 97 [PushExpression(StackTypes.Char, "CHAR.ALLFROMSTRING", StackTypes.String)] 98 [StorableClass] 68 99 public class CharAllFromStringExpression : StatelessExpression { 69 public override bool Eval(IInternalPushInterpreter interpreter) { 70 if (interpreter.StringStack.IsEmpty) return false; 100 public CharAllFromStringExpression() { } 101 [StorableConstructor] 102 public CharAllFromStringExpression(bool deserializing) : base(deserializing) { } 71 103 104 public override bool IsNoop(IInternalPushInterpreter interpreter) { 105 return interpreter.StringStack.IsEmpty; 106 } 107 108 public override void Eval(IInternalPushInterpreter interpreter) { 72 109 var chars = interpreter.StringStack.Pop().ToCharArray(); 73 110 interpreter.CharStack.Push(chars); 74 return true;75 111 } 76 112 }
Note: See TracChangeset
for help on using the changeset viewer.