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 override AstNode Visit(TernaryOperation node) { // Visit recursively. node.GetCondExpression().Accept(this); node.GetLeftExpression().Accept(this); node.GetRightExpression().Accept(this); return(node); }
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; }
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); }
public void VisitTernaryOperation(TernaryOperation node) { throw new NotImplementedException(); }