Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.Algorithms.PushGP/HeuristicLab.Algorithms.PushGP/Expressions/Code/CodeDefineExpression.cs @ 14328

Last change on this file since 14328 was 14328, checked in by pkimmesw, 8 years ago

#2665 Set .NET version to 4.5, C# version to 5.0, Added expression templates and factory

File size: 1.1 KB
Line 
1using HeuristicLab.Algorithms.PushGP.Expressions.Exec;
2using HeuristicLab.Algorithms.PushGP.Interpreter;
3
4namespace HeuristicLab.Algorithms.PushGP.Expressions.Code
5{
6    public class CodeDefineExpression : Expression
7    {
8        public override bool IsCodeOp { get { return true; } }
9
10        public override void Eval(IInterpreter interpreter)
11        {
12            // not enough arguments on stack
13            if (interpreter.NameStack.Count == 0 ||
14                interpreter.CodeStack.Count == 0)
15                return;
16
17            var name = interpreter.NameStack.Pop();
18            var expression = new ExecPushExpression(interpreter.CodeStack.Top);
19
20            if (interpreter.CustomExpressions.ContainsKey(name))
21            {
22                interpreter.CustomExpressions[name] = expression;
23            }
24            else
25            {
26                interpreter.CustomExpressions.Add(name, expression);
27            }
28
29            interpreter.CodeStack.Pop();
30        }
31
32        public override string ToString()
33        {
34            return Symbols.CodeDefine;
35        }
36    }
37}
Note: See TracBrowser for help on using the repository browser.