Beispiel #1
0
 public TernaryExpression(Location location, Expression left, Expression middle, Expression right, TernaryOperation operation)
     : base(location)
 {
     this.operation = operation;
     this.left = left;
     this.middle = middle;
     this.right = right;
 }
Beispiel #2
0
 public override AstNode Visit(TernaryOperation node)
 {
     // Visit recursively.
     node.GetCondExpression().Accept(this);
     node.GetLeftExpression().Accept(this);
     node.GetRightExpression().Accept(this);
     return(node);
 }
Beispiel #3
0
        public void VisitTernaryOperation(TernaryOperation node)
        {
            var conditionType = InferType(node.Condition, _context);

            if (!KnownType.Boolean.Equals(conditionType))
            {
                throw new TypeInferenceException("Condition of a ternary operation must have a boolean type");
            }

            var trueBranchType  = InferType(node.TrueBranch, _context);
            var falseBranchType = InferType(node.FalseBranch, _context);

            if (!trueBranchType.Equals(falseBranchType))
            {
                throw new TypeInferenceException(trueBranchType, falseBranchType);
            }

            _type = trueBranchType;
        }
Beispiel #4
0
    void Start()
    {
        Player_Property player1 = new Player_Property();
        Player_Property player2 = new Player_Property();

        TernaryOperation ternaryOperation = new TernaryOperation();

        // Properties can be used just like variables
        player1.Experience = 5000;
        int x = player1.Level;

        player1.Health = 10;

        player2.Level = 7;
        int y = player2.Experience;

        player2.Name = "2号";

        Debug.Log(x);
        Debug.Log(y);
        // The specific HealthMessage method called will depend on the arguments passed in.
        ternaryOperation.HealthMessage(player1.Health, nameof(player1));
        ternaryOperation.HealthMessage(player2);
    }
Beispiel #5
0
 public TernaryExpression(Location location, Expression left, Expression middle, Expression right, TernaryOperation operation)
     : base(location)
 {
     this.operation = operation;
     this.left      = left;
     this.middle    = middle;
     this.right     = right;
 }
 public void VisitTernaryOperation(TernaryOperation node)
 {
     throw new NotImplementedException();
 }