Example #1
0
        // TAKE QUANTITY
        public override ASTNode VisitTakeQuantityStmt(CLUBSParser.TakeQuantityStmtContext context)
        {
            TakeActionNode node = new TakeActionNode(new SourcePosition(context.start));

            node.Quantity = Visit(context.quantity) as ExpressionNode;

            return(node);
        }
Example #2
0
        // TAKE
        public override ASTNode VisitTakeStmt(CLUBSParser.TakeStmtContext context)
        {
            TakeActionNode node = Visit(context.takeActionStmt()) as TakeActionNode;

            node.Source = Visit(context.source) as ReferenceNode;
            node.Target = Visit(context.target) as ReferenceNode;

            return(node);
        }
        // TAKE
        public override string Visit(TakeActionNode node, object obj)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("{\n");
            builder.Append($"var _tempList = {Visit(node.Source)}.Take({Visit(node.Quantity)}).ToList();\n");
            builder.Append($"{Visit(node.Target)}.AddRange(_tempList);\n");
            builder.Append($"_tempList.ForEach(x => {Visit(node.Source)}.Remove(x));\n");
            builder.Append("}\n");

            return(builder.ToString());
        }
Example #4
0
        // TAKE
        public override TypeNode Visit(TakeActionNode node, object obj)
        {
            VisitPutAction(node); // Call generic VisitPut method

            TypeNode quantityType = Visit(node.Quantity);

            // If quantity type is not Int, log error
            if (quantityType != StandardTypes.Int)
            {
                ErrorLogger.LogError(new ExpectedTypeError(StandardTypes.Int, quantityType.SourcePosition));
                return(new ErrorTypeNode(node.SourcePosition));
            }

            return(null);
        }
Example #5
0
 public abstract T Visit(TakeActionNode node, object obj);