コード例 #1
0
        // TAKE AT
        public override ASTNode VisitTakeIndexStmt(CLUBSParser.TakeIndexStmtContext context)
        {
            TakeAtActionNode node = new TakeAtActionNode(new SourcePosition(context.start));

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

            return(node);
        }
コード例 #2
0
        // TAKE AT
        public override string Visit(TakeAtActionNode node, object obj)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("{\n");
            builder.Append($"var _tempList = {Visit(node.Source)}.Skip({Visit(node.Index)}).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());
        }
コード例 #3
0
        // TAKE AT
        public override TypeNode Visit(TakeAtActionNode node, object obj)
        {
            VisitPutAction(node); // Call generic VisitPut method

            TypeNode quantityType = Visit(node.Quantity);
            TypeNode indexType    = Visit(node.Index);

            // 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));
            }

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

            return(null);
        }
コード例 #4
0
 public abstract T Visit(TakeAtActionNode node, object obj);