Last change
on this file since 14320 was
14320,
checked in by pkimmesw, 8 years ago
|
#2665 Added Interpreter, Parser, 16 Examples, Expressions needed for the examples
|
File size:
1.6 KB
|
Line | |
---|
1 | using HeuristicLab.Algorithms.PushGP.Stack;
|
---|
2 |
|
---|
3 | namespace HeuristicLab.Algorithms.PushGP.Expressions
|
---|
4 | {
|
---|
5 | public class ExecDoRangeExpression : Expression
|
---|
6 | {
|
---|
7 | public ExecDoRangeExpression() : base(OpCode.ExecDoXRange)
|
---|
8 | { }
|
---|
9 |
|
---|
10 | public override void Eval(IInterpreterService interpreterService)
|
---|
11 | {
|
---|
12 | // not enough arguments on stack
|
---|
13 | if (interpreterService.IntegerStack.Count < 2 ||
|
---|
14 | interpreterService.ExecStack.Count == 0)
|
---|
15 | return;
|
---|
16 |
|
---|
17 | var destinationIndex = interpreterService.IntegerStack.Pop();
|
---|
18 | var currentIndex = interpreterService.IntegerStack.Pop();
|
---|
19 | var loopBody = interpreterService.ExecStack.Pop();
|
---|
20 |
|
---|
21 | if (destinationIndex == currentIndex)
|
---|
22 | {
|
---|
23 | interpreterService.IntegerStack.Push(currentIndex);
|
---|
24 | interpreterService.ExecStack.Push(loopBody);
|
---|
25 | }
|
---|
26 | else
|
---|
27 | {
|
---|
28 | var nextIndex = destinationIndex < currentIndex
|
---|
29 | ? currentIndex - 1
|
---|
30 | : currentIndex + 1;
|
---|
31 |
|
---|
32 | interpreterService.IntegerStack.Push(currentIndex);
|
---|
33 | interpreterService.IntegerStack.Push(nextIndex);
|
---|
34 | interpreterService.IntegerStack.Push(destinationIndex);
|
---|
35 |
|
---|
36 | var expression = new ExecDoRangeExpression();
|
---|
37 | interpreterService.ExecStack.Push(loopBody);
|
---|
38 | interpreterService.ExecStack.Push(loopBody);
|
---|
39 | interpreterService.ExecStack.Push(expression);
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
43 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.