Exemple #1
0
        bool EvaluateVersionConditional(Expression expr)
        {
            if (expr is NameExpr)
            {
                var e = expr as NameExpr;
                return Tags.Contains(e.Name);
            }

            if (expr is BinaryOperatorExpr)
            {
                var e = expr as BinaryOperatorExpr;
                bool left = EvaluateVersionConditional(e.Left);
                bool right = EvaluateVersionConditional(e.Right);
                if (e.Op == TokenType.LogicalAnd)
                    return left && right;
                if (e.Op == TokenType.LogicalOr)
                    return left || right;
                Error.Create("Unsupported operator '{0}' in version condition", e.Op).At(e.Position).Throw();
            }

            if (expr is UnaryOperatorExpr)
            {
                var e = expr as UnaryOperatorExpr;
                bool right = EvaluateVersionConditional(e.Right);
                if (e.Op == TokenType.Bang)
                    return !right;
                Error.Create("Unsupported operator '{0}' in version condition", e.Op).At(e.Position).Throw();
            }

            Error.Create("Syntax error").At(expr.Position).Throw();
            return false;
        }
Exemple #2
0
 ExpressionStatement ParseExpressionStatement(Expression expr)
 {
     Consume(TokenType.Semi);
     return new ExpressionStatement { Expr = expr, Position = expr.Position };
 }