Exemplo n.º 1
0
        private static SyntaxNode BinaryOperator(RParser.ExprContext expr, Func <ParserRuleContext, Scope, SyntaxNode> transform, Scope scope)
        {
            var left  = transform(expr.GetRuleContext <RParser.ExprContext>(0), scope) as ExpressionSyntax;
            var right = transform(expr.GetRuleContext <RParser.ExprContext>(1), scope) as ExpressionSyntax;

            Debug.Assert(left != null && right != null);

            Debug.Assert(expr.children.Count == 3);
            var op = expr.children[1].GetText();

            return(binaryOperatorCall.Get(_binaryOperators[op], left, right));
        }
Exemplo n.º 2
0
        private static SyntaxNode UnaryOperator(RParser.ExprContext expr, Func <ParserRuleContext, Scope, SyntaxNode> transform, Scope scope)
        {
            Debug.Assert(expr.children.Count == 2);
            var op = expr.children[0].GetText();

            var value = transform(expr.GetRuleContext <RParser.ExprContext>(0), scope) as ExpressionSyntax;

            if (isConstant(value))
            {
                return(CSharp.ParseExpression(op + value.ToString()));
            }

            Debug.Assert(value != null);

            return(unaryOperatorCall.Get(_unaryOperators[op], value));
        }