// RANDOM
        public override ASTNode VisitRandomExpr(CLUBSParser.RandomExprContext context)
        {
            RandomNode node = new RandomNode(new SourcePosition(context.start));

            node.LowerLimit = Visit(context.lower) as ExpressionNode;
            node.UpperLimit = Visit(context.upper) as ExpressionNode;

            return(node);
        }
Esempio n. 2
0
        // RANDOM
        public override TypeNode Visit(RandomNode node, object obj)
        {
            TypeNode lowerLimitType = Visit(node.LowerLimit);
            TypeNode upperLimitType = Visit(node.UpperLimit);

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

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

            return(new IntTypeNode(node.SourcePosition));
        }
Esempio n. 3
0
 public abstract T Visit(RandomNode node, object obj);
 // RANDOM
 public override string Visit(RandomNode node, object obj)
 {
     return($"_random.Next({Visit(node.LowerLimit)}, {Visit(node.UpperLimit)})");
 }