public BinaryExpressionNode BinaryOperand(ExpressionNode left, ExpressionNode right, string @operator)
        {
            if (left == null)
                ThrowHelper.ThrowArgumentNullException(() => left);
            if (right == null)
                ThrowHelper.ThrowArgumentNullException(() => right);

            OperatorNode operatorNode;

            if (!_operators.TryGetValue(@operator, out operatorNode))
                throw new Exception("Unsupported operator!");

            if (operatorNode is LogicalBinaryOperatorNode) {
                return new BinaryExpressionNode(left, right, operatorNode as LogicalBinaryOperatorNode);
            }

            if (operatorNode is NumericBinaryOperatorNode) {
                return new BinaryExpressionNode(left, right, operatorNode as NumericBinaryOperatorNode);
            }

            if (operatorNode is RelationalBinaryOperatorNode) {
                return new BinaryExpressionNode(left, right, operatorNode as RelationalBinaryOperatorNode);
            }

            throw new Exception("Invalid operator has found!");
        }
        public ExpressionStatementNode(ExpressionNode expression)
        {
            if (expression == null)
                throw new ArgumentNullException("expression", "The expression is null!");

            Expression = expression;
        }
        public ReturnStatementNode(ExpressionNode returnExpression)
        {
            if (returnExpression == null)
                ThrowHelper.ThrowArgumentNullException(() => returnExpression);

            ReturnExpression = returnExpression;
            AddChildren(ReturnExpression);
        }
        public WhileLoopStatementNode(ExpressionNode conditionExpression, StatementNodeBase body, AttributeNode[] attributes)
            : base(body, attributes)
        {
            if (conditionExpression == null)
                throw new ArgumentNullException("conditionExpression", "The ConditionExpression is null!");

            ConditionExpression = conditionExpression;
            AddChildren(ConditionExpression);
        }
Example #5
0
        public WhileLoopStatementNode While(ExpressionNode condition, StatementNodeBase body, AttributeNode[] attributes)
        {
            if (condition == null)
                ThrowHelper.ThrowArgumentNullException(() => condition);

            if (attributes == null)
                ThrowHelper.ThrowArgumentNullException(() => attributes);

            return new WhileLoopStatementNode(condition, body, attributes);
        }
        public AssignmentExpressionNode Assignment(MemberExpressionNode leftValue, ExpressionNode rightValue, IEnumerable<AttributeNode> attributes)
        {
            if (leftValue == null)
                ThrowHelper.ThrowArgumentNullException(() => leftValue);

            if (rightValue == null)
                ThrowHelper.ThrowArgumentNullException(() => rightValue);

            return new AssignmentExpressionNode(leftValue, rightValue, attributes);
        }
        public AssignmentExpressionNode(MemberExpressionNode variable, ExpressionNode rightValue, IEnumerable<AttributeNode> attributes)
            : base(attributes)
        {
            if (variable == null)
                ThrowHelper.ThrowArgumentNullException(() => variable);
            if (rightValue == null)
                ThrowHelper.ThrowArgumentNullException(() => rightValue);

            LeftValue = variable;
            RightValue = rightValue;

            AddChildren(LeftValue, RightValue);
        }
        public UnaryExpressionNode(UnaryOperatorNode @operator, ExpressionNode expression)
        {
            if (@operator == null)
                ThrowHelper.ThrowArgumentNullException(() => @operator);

            if (expression == null)
                ThrowHelper.ThrowArgumentNullException(() => expression);

            Operator = @operator;
            Expression = expression;

            AddChildren(Operator, Expression);
        }
Example #9
0
        public ForeachLoopStatementNode Foreach(string variable, TypeNameNode variableType, ExpressionNode expression, StatementNodeBase body, AttributeNode[] attributes)
        {
            if (string.IsNullOrWhiteSpace(variable))
                ThrowHelper.ThrowException("The 'variable' is blank!");
            if (expression == null)
                ThrowHelper.ThrowArgumentNullException(() => expression);
            if (body == null)
                ThrowHelper.ThrowArgumentNullException(() => body);
            if (attributes == null)
                ThrowHelper.ThrowArgumentNullException(() => attributes);

            return new ForeachLoopStatementNode(variable, variableType, expression, body, attributes);
        }
        public InnerExpressionNode(ExpressionNode expression, IEnumerable<AttributeNode> attributes)
        {
            if (expression == null)
                ThrowHelper.ThrowArgumentNullException(() => expression);

            if (attributes == null)
                ThrowHelper.ThrowArgumentNullException(() => attributes);

            Expression = expression;
            Attributes = attributes.ToList();

            AddChildren(Expression);
            AddChildren(Attributes);
        }
        public BinaryExpressionNode(ExpressionNode left, ExpressionNode right, BinaryOperatorNode operatorNode)
        {
            if (left == null)
                ThrowHelper.ThrowArgumentNullException(() => left);
            if (right == null)
                ThrowHelper.ThrowArgumentNullException(() => right);
            if (operatorNode == null)
                ThrowHelper.ThrowArgumentNullException(() => operatorNode);

            Left = left;
            Right = right;
            Operator = operatorNode;

            AddChildren(Left, Right, Operator);
        }
Example #12
0
        public IfStatementNode(ExpressionNode condition, BlockStatementNode trueStatement, BlockStatementNode falseStatement, IEnumerable<AttributeNode> attributes)
        {
            if (condition == null) throw new ArgumentNullException("condition");
            if (trueStatement == null) throw new ArgumentNullException("trueStatement");
            if (falseStatement == null) throw new ArgumentNullException("falseStatement");
            if (attributes == null)
                ThrowHelper.ThrowArgumentNullException(() => attributes);

            ConditionExpression = condition;
            TrueStatementNode = trueStatement;
            FalseStatementNode = falseStatement;
            Attributes = attributes.ToList();

            AddChildren(condition, trueStatement, falseStatement);
            AddChildren(Attributes);
        }
        public ForeachLoopStatementNode(string variable, TypeNameNode variableType, ExpressionNode expression, StatementNodeBase body, AttributeNode[] attributes)
            : base(body, attributes)
        {
            if (string.IsNullOrWhiteSpace(variable))
                ThrowHelper.ThrowException("The 'variable' is blank!");

            if (expression == null) throw new ArgumentNullException("expression", "The expression is null!");

            if (attributes == null)
                ThrowHelper.ThrowArgumentNullException(() => attributes);

            LoopVariable = new IdentifierExpressionNode(variable);
            Expression = expression;
            LoopVariableType = variableType;

            AddChildren(LoopVariable, LoopVariableType, Expression);
        }
        public VariableDeclarationStatementNode(string name, TypeNameNode variableType, ExpressionNode initialValue, AttributeNode[] attributes)
        {
            if (name == null)
                ThrowHelper.ThrowArgumentNullException(() => name);

            if (variableType == null)
                ThrowHelper.ThrowArgumentNullException(() => variableType);

            if (initialValue == null)
                ThrowHelper.ThrowArgumentNullException(() => initialValue);

            InitialValue = initialValue;
            Identifier = new IdentifierExpressionNode(name, null);
            VariableType = variableType;
            Attributes = attributes.ToList();

            AddChildren(Identifier, VariableType, InitialValue);
            AddChildren(Attributes);
        }
Example #15
0
        public IfStatementNode IfThenElse(ExpressionNode condition, BlockStatementNode trueStatement, IfStatementNode[] elseIfStatements, BlockStatementNode falseStatement, IEnumerable<AttributeNode> attributes)
        {
            if (condition == null)
                ThrowHelper.ThrowArgumentNullException(() => condition);
            if (trueStatement == null)
                ThrowHelper.ThrowArgumentNullException(() => trueStatement);

            if (falseStatement == null)
                falseStatement = EmptyBlock();

            if (elseIfStatements.Any())
            {
                var elseIf = elseIfStatements.First();
                falseStatement =
                    Block(
                        new StatementNodeBase[]{
                                                   IfThenElse(elseIf.ConditionExpression, elseIf.TrueStatementNode, elseIfStatements.Skip(1).ToArray(), new AttributeNode[0])
                                               }
                    );
            }

            return new IfStatementNode(condition, trueStatement, falseStatement, attributes);
        }
Example #16
0
        public ExpressionStatementNode Expression(ExpressionNode expression)
        {
            if (expression == null)
                ThrowHelper.ThrowArgumentNullException(() => expression);

            return new ExpressionStatementNode(expression);
        }
Example #17
0
 public VariableDeclarationStatementNode DeclareVariable(string name, TypeNameNode typeName, ExpressionNode initialValue)
 {
     return DeclareVariable(name, typeName, initialValue, new AttributeNode[0]);
 }
Example #18
0
        public VariableDeclarationStatementNode DeclareVariable(string name, TypeNameNode typeName, ExpressionNode initialValue, AttributeNode[] attributes)
        {
            if (string.IsNullOrWhiteSpace(name))
                ThrowHelper.ThrowException("The name is blank!");

            if (attributes == null)
                ThrowHelper.ThrowArgumentNullException(() => attributes);

            return new VariableDeclarationStatementNode(name, typeName, initialValue, attributes);
        }
Example #19
0
        public FunctionDeclarationStatementNode Function(string name, TypeNameNode returnType, FormalParameterNode[] parameters, ExpressionNode body, AttributeNode[] attributes)
        {
            var statementFactory = CompilerService.StatementFactory;

            return Function(name, returnType, parameters, statementFactory.Block(new StatementNodeBase[] { statementFactory.Expression(body) }), attributes);
        }
Example #20
0
 public IfStatementNode IfThenElse(ExpressionNode condition, BlockStatementNode trueStatement, IfStatementNode[] elseIfStatements, IEnumerable<AttributeNode> attributes)
 {
     return IfThenElse(condition, trueStatement, elseIfStatements, EmptyBlock(), attributes);
 }
Example #21
0
 public AssignmentExpressionNode Assignment(MemberExpressionNode leftValue, ExpressionNode rightValue)
 {
     return Assignment(leftValue, rightValue, new AttributeNode[0]);
 }
Example #22
0
        public UnaryExpressionNode UnaryOperand(ExpressionNode expr, string op)
        {
            if (expr == null)
                ThrowHelper.ThrowArgumentNullException(() => expr);

            OperatorNode operatorNode;

            if (!_operators.TryGetValue(op, out operatorNode))
                throw new Exception("Unsupported operator!");

            if (operatorNode is LogicalUnaryOperatorNode)
            {
                return new UnaryExpressionNode(operatorNode as LogicalUnaryOperatorNode, expr);
            }

            throw new Exception("Invalid operator has found!");
        }
Example #23
0
        public FunctionCallExpressionNode FunctionCall(string name, ExpressionNode[] actualParameters)
        {
            if (string.IsNullOrWhiteSpace(name))
                ThrowHelper.ThrowException("The 'name' is blank!");

            if (actualParameters == null)
                ThrowHelper.ThrowArgumentNullException(() => actualParameters);

            return new FunctionCallExpressionNode(name, actualParameters);
        }
Example #24
0
        public InnerExpressionNode InnerExpression(ExpressionNode expression, IEnumerable<AttributeNode> attributes)
        {
            if (expression == null)
                ThrowHelper.ThrowArgumentNullException(() => expression);

            if (attributes == null)
                ThrowHelper.ThrowArgumentNullException(() => attributes);

            return new InnerExpressionNode(expression, attributes);
        }
Example #25
0
 public ExpressionNode InnerExpression(ExpressionNode expression)
 {
     return InnerExpression(expression, new AttributeNode[0]);
 }
 public InnerExpressionNode(ExpressionNode expression)
     : this(expression, new AttributeNode[0])
 {
 }
Example #27
0
 public ForeachLoopStatementNode Foreach(string variable, TypeNameNode variableType, ExpressionNode expression, StatementNodeBase body)
 {
     return Foreach(variable, variableType, expression, body, new AttributeNode[0]);
 }