public Cell Visit(GridValueNode node)
        {
            MathExpressionAstEvaluator exprVisitor = new MathExpressionAstEvaluator();

            int x = exprVisitor.Visit(node.FirstD);
            int y = exprVisitor.Visit(node.SecondD);

            // Wrap around if out of bounds
            while (x >= sender.X_Max)
            {
                x -= sender.X_Max;
            }

            while (x < 0)
            {
                x += sender.X_Max;
            }

            while (y >= sender.Y_Max)
            {
                y -= sender.Y_Max;
            }

            while (y < 0)
            {
                y += sender.Y_Max;
            }

            return(sender.GetCell(new Pos(x, y)));
        }
        public void Visit(AdvancedReturnStatementNode node)
        {
            ValueAstEvaluator          valueEvaluator = new ValueAstEvaluator(sender);
            MathExpressionAstEvaluator exprEvaluator  = new MathExpressionAstEvaluator();
            Cell   cell = sender.GetCurrentCell();
            Symbol sym  = Stbl.st.Retrieve(node.Identifier.Label);

            if (sym is StateSymbol s)
            {
                try
                {
                    // Set state members
                    StateSymbol state = s.Copy();
                    foreach (ReturnMemberNode rNode in node.ReturnMembers)
                    {
                        MemberSymbol member = state.RetrieveMember(rNode.ID.Label);
                        switch (rNode.Value)
                        {
                        case ExpressionNode valueNode: member.SetValue(exprEvaluator.Visit(valueNode)); break;

                        case StringValueNode valueNode: member.SetValue(valueNode.Value); break;

                        default: throw new TheLanguageErrorException($"ReturnMember value cannot be of type \'{ rNode.Value.GetType().Name }\'");
                        }
                    }
                    sender.SetCell(cell, state);
                }
                catch (TheLanguageErrorException e) { throw new TheLanguageErrorException($"Return statement \'{ node.Identifier.Label }\'", e); }
            }
            else
            {
                throw new TheLanguageErrorException($"Return statement. Unexpected type { sym } expected State");
            }

            sender.ReturnStatementHasBeenHit = true;
        }
        public void Visit(MemberAssignmentStatementNode node)
        {
            ValueAstEvaluator valueEvaluator = new ValueAstEvaluator(sender);
            Cell cell;

            // Get cell
            if (node.GridPoint != null)
            {
                cell = valueEvaluator.Visit(node.GridPoint);
            }
            else
            {
                cell = sender.GetCurrentCell();
            }

            // Evaluate expression or string
            object result;

            if (node.Value is ExpressionNode exprNode)
            {
                if (exprNode is ComparisonNode)
                {
                    result = new ComparisonExpressionAstEvaluator().Visit(exprNode);
                }
                else
                {
                    result = new MathExpressionAstEvaluator().Visit(exprNode);
                }
            }
            else
            {
                result = ((StringValueNode)node.Value).Value;
            }

            // Retrieve state member for the next cell
            Cell         nextCell = sender.GetNextCell(cell.Pos);
            MemberSymbol member   = nextCell.State.RetrieveMember(node.MemberID.Label);

            if (member != null)
            {
                try
                {
                    // Set new value
                    switch (result)
                    {
                    case int i: member.SetValue(i); break;

                    case string s: member.SetValue(s); break;

                    default: throw new TheLanguageErrorException($"Cannot assign value of type \'{ result.GetType() }\' to a member");
                    }
                }
                catch (TheLanguageErrorException e)
                {
                    throw new TheLanguageErrorException($"Member .{ member.Label }", e);
                }
            }
            else
            {
                throw new TheLanguageErrorException($"Unknown member \'{ node.MemberID.Label }\'");
            }
        }
        public override int Visit(InfixExpressionNode node)
        {
            MathExpressionAstEvaluator expressionAstEvaluator = new MathExpressionAstEvaluator();

            return(expressionAstEvaluator.Visit(node));
        }