public override Result VisitBinaryExpression(AntlrConditionParser.BinaryExpressionContext context) { var left = Visit(context.left); var right = Visit(context.right); if (left.Type != right.Type && left.Type != ResultType.Bool) { throw new Exception("Invalid type comparison"); } if (context.op.AND() != null) { return new Result { Bool = left.Bool.GetValueOrDefault() && right.Bool.GetValueOrDefault() } } ; if (context.op.OR() != null) { return new Result { Bool = left.Bool.GetValueOrDefault() || right.Bool.GetValueOrDefault() } } ; return(new Result()); }
/// <summary> /// Exit a parse tree produced by the <c>binaryExpression</c> /// labeled alternative in <see cref="AntlrConditionParser.expression"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitBinaryExpression([NotNull] AntlrConditionParser.BinaryExpressionContext context) { }
/// <summary> /// Visit a parse tree produced by the <c>binaryExpression</c> /// labeled alternative in <see cref="AntlrConditionParser.expression"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitBinaryExpression([NotNull] AntlrConditionParser.BinaryExpressionContext context) { return(VisitChildren(context)); }