public void Accept(TernaryOperationNode node) { var falseLabel = nextLabel(); var endLabel = nextLabel(); node.Condition.Visit(this); emit(node.Condition.SourceLocation, InstructionType.JumpIfFalse, falseLabel); node.TrueExpression.Visit(this); emit(node.TrueExpression.SourceLocation, InstructionType.Jump, endLabel); emitLabel(node.FalseExpression.SourceLocation, falseLabel); node.FalseExpression.Visit(this); emitLabel(node.FalseExpression.SourceLocation, endLabel); }
private AstNode parseTernary() { var location = this.location; AstNode left = parseLogicalOr(); while (acceptToken(TokenType.Question)) { AstNode trueStatement = parseExpression(); expectToken(TokenType.Colon); AstNode falseStatement = parseExpression(); left = new TernaryOperationNode(location, left, trueStatement, falseStatement); } return(left); }