Esempio n. 1
0
        public override Expression VisitUnaryExpression([NotNull] RuleEngineParser.UnaryExpressionContext context)
        {
            var primaryExpressionContext = context.primaryExpression();

            if (primaryExpressionContext != null)
            {
                return(VisitPrimaryExpression(primaryExpressionContext));
            }

            var expression = VisitUnaryExpression(context.unaryExpression());

            var operatorSign = context.GetChild(0).GetText();

            switch (operatorSign)
            {
            case "+":
                return(expression);

            case "-":
                var leftExpression = Expression.Convert(Expression.Constant(0), expression.Type);
                return(Expression.Subtract(leftExpression, expression));

            case "!":
                return(Expression.Not(expression));

            default:
                throw new NotSupportedException($"Not support operator '{operatorSign}'.");
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="RuleEngineParser.unaryExpression"/>.
 /// <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 VisitUnaryExpression([NotNull] RuleEngineParser.UnaryExpressionContext context)
 {
     return(VisitChildren(context));
 }