Esempio n. 1
0
        // Deck value expression
        public override TypeNode Visit(DeckValueNode node, object obj)
        {
            SourcePosition sourcePosition = node.SourcePosition;

            SetTypeNode cardValueSet = StandardTypes.GetSetType(StandardTypes.CardValue);

            int count = 1;

            // Go through all identifiers in the deck for errors
            foreach (IdentifierNode id in node.Ids)
            {
                Symbol symbol = SymbolTable.RetrieveSymbol(id.Text);
                // If id has not been declared or the reference type is not Set OF CardValue, log error
                if (symbol == null)
                {
                    ErrorLogger.LogError(new UndeclaredVariableError(id.Text, id.SourcePosition));
                    return(new ErrorTypeNode(node.SourcePosition));
                }
                else if (symbol.Type != cardValueSet)
                {
                    ErrorLogger.LogError(new ExpectedTypeError(node, cardValueSet, id.SourcePosition));
                    return(new ErrorTypeNode(node.SourcePosition));
                }
                count *= (symbol.Type as SetTypeNode).ElementCount; // Get total number of cards in deck
            }

            node.Type         = new SetTypeNode(new CardTypeNode(sourcePosition), sourcePosition);
            node.ElementCount = count; // Save the number of cards in the type for later use

            return(node.Type);
        }
 public override string Visit(SetTypeNode node, object obj)
 {
     if (node.Type is BaseTypeNode)
     {
         return($"ComparableList<{node.Type}>");
     }
     else
     {
         return($"List<{Visit(node.Type)}>");
     }
 }
Esempio 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);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DeckValueNode"/> class.
 /// </summary>
 /// <param name="sourcePosition">The source position of the node in the program.</param>
 public DeckValueNode(List <IdentifierNode> ids, SourcePosition sourcePosition) : base(sourcePosition)
 {
     Ids  = ids;
     Type = new SetTypeNode(new CardTypeNode(sourcePosition), sourcePosition);
 }
Esempio n. 5
0
 public abstract T Visit(SetTypeNode node, object obj);
 public override TypeNode Visit(SetTypeNode node, object obj)
 {
     node.Type = Visit(node.Type);
     return(node);
 }