Ejemplo n.º 1
0
        // PUT
        public override ASTNode VisitPutStmt(CLUBSParser.PutStmtContext context)
        {
            PutActionNode node = new PutActionNode(new SourcePosition(context.start));

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

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

            builder.Append($"{Visit(node.Target)}.AddRange({Visit(node.Source)});\n");
            builder.Append($"{Visit(node.Source)}.Clear();\n");

            return(builder.ToString());
        }
Ejemplo n.º 3
0
        // HELPER METHODS

        // Generic visitor for PUT actions
        private TypeNode VisitPutAction(PutActionNode node)
        {
            SetTypeNode deckType = StandardTypes.GetSetType(StandardTypes.Card);

            TypeNode sourceType = Visit(node.Source);
            TypeNode targetType = Visit(node.Target);

            // If the source type is not a Set OF Card, log error
            if (sourceType != deckType)
            {
                ErrorLogger.LogError(new ExpectedTypeError(deckType, node.Source.SourcePosition));
                return(new ErrorTypeNode(node.SourcePosition));
            }

            // If the target type is not a Set OF Card, log error
            if (targetType != deckType)
            {
                ErrorLogger.LogError(new ExpectedTypeError(deckType, node.Target.SourcePosition));
                return(new ErrorTypeNode(node.SourcePosition));
            }

            return(null);
        }
Ejemplo n.º 4
0
 // PUT
 public override TypeNode Visit(PutActionNode node, object obj)
 {
     VisitPutAction(node); // Call generic VisitPut method
     return(null);
 }
Ejemplo n.º 5
0
 public abstract T Visit(PutActionNode node, object obj);