public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode)
        {
            base.Init(context, treeNode);

            _baseCurrencyExpr = AddChild("baseCurrencyExpr", treeNode.ChildNodes[0]) as ExpressionAstNode;
            _variableCurrencyExpr = AddChild("variableCurrencyExpr", treeNode.ChildNodes[2]) as ExpressionAstNode;
        }
 public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode)
 {
     base.Init(context, treeNode);
     _leftExpression = AddChild("leftExpression", treeNode.ChildNodes[0]) as ExpressionAstNode;
     _op = treeNode.ChildNodes[1].FindTokenAndGetText();
     _rightExpression = AddChild("rightExpression", treeNode.ChildNodes[2]) as ExpressionAstNode;
 }
 public override void Init(ParsingContext context, ParseTreeNode treeNode)
 {
     base.Init(context, treeNode);
     Condition = AddChild("Condition", treeNode.ChildNodes[0]) as ExpressionAstNode;
     IfTrueStatments = AddChild("IfTrueStatments", treeNode.ChildNodes[1]) as StatementListNode;
     if (treeNode.ChildNodes.Count > 2)
         IfFalseStatements = AddChild("IfFalseStatements", treeNode.ChildNodes[2]) as StatementListNode;
 }
        public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode)
        {
            base.Init(context, treeNode);

            if (treeNode.ChildNodes[1].FindTokenAndGetText() == "not")
            {
                _isIn = false;
            }
            else
                _isIn = true;

            _element = (ExpressionAstNode)AddChild("element", treeNode.ChildNodes[0]);
            _set = (CollectionAstNode) AddChild("set", treeNode.ChildNodes[2]);

        }
        public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode)
        {
            string type = treeNode.ChildNodes[0].FindTokenAndGetText();
            switch (type.ToLower())
            {
                case "string": _type = typeof(string); break;
                case "int": _type = typeof(int); break;
                case "decimal": _type = typeof(decimal); break;
                default:
                    throw new Exception("Unhanled type: " + type);
            }

            _variable = AddChild("variable", treeNode.ChildNodes[1]) as VariableAstNode;
            _initialization = AddChild("initialization", treeNode.ChildNodes[2]) as ExpressionAstNode;

        }
 public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode)
 {
     base.Init(context, treeNode);
     _variable = AddChild("variable", treeNode.ChildNodes[0]) as VariableAstNode;
     _expression = AddChild("expression", treeNode.ChildNodes[1]) as ExpressionAstNode;
 }
        /// <summary>
        /// Create Expression node from the expression node on abstract syntax tree
        /// </summary>
        /// <param name="astExpr"></param>
        /// <returns></returns>
        private Expression ConvertExpressionAst(ExpressionAstNode astExpr)
        {
            if (astExpr is IntegerAstNode)
            {
                IntegerAstNode intAst = astExpr as IntegerAstNode;
                return new Constant(typeof(int), intAst.Value);
            }
            else if (astExpr is StringAstNode)
            {
                StringAstNode stringAst = astExpr as StringAstNode;
                return new Constant(typeof(string), stringAst.Value);
            }
            else if (astExpr is DecimalAstNode)
            {
                DecimalAstNode decimalAst = astExpr as DecimalAstNode;
                return new Constant(typeof(decimal), decimalAst.Value);
            }
            else if (astExpr is PropertyAccessAstNode)
            {
                PropertyAccessAstNode propertyAccessAst = astExpr as PropertyAccessAstNode;
                return new PropertyAccessor(
                    CreateVariable(propertyAccessAst.Variable.Name),
                    propertyAccessAst.Property);
            }
            else if (astExpr is ElementIsInSetNode)
            {
                ElementIsInSetNode elementInSetAst = astExpr as ElementIsInSetNode;

                if (elementInSetAst.IsIn)
                {
                    return new IsInSet()
                    {
                        LeftExpression = ConvertExpressionAst(elementInSetAst.Element),
                        RightExpression = ConvertExpressionAst(elementInSetAst.Set)
                    };
                }
                else
                {
                    return new IsNotInSet()
                    {
                        LeftExpression = ConvertExpressionAst(elementInSetAst.Element),
                        RightExpression = ConvertExpressionAst(elementInSetAst.Set)
                    };
                }
            }
            else if (astExpr is VariableAstNode)
            {
                VariableAstNode variable = astExpr as VariableAstNode;
                return CreateVariable(variable.Name);
            }
            else if (astExpr is PropertyElementCollectionNode)
            {
                PropertyElementCollectionNode pecNode = astExpr as PropertyElementCollectionNode;
                return new CollectionPropertiesAccessor(
                    ConvertExpressionAst(pecNode.Collection),
                    pecNode.Property);
            }
            else if (astExpr is PositionSetAstNode)
            {
                PositionSetAstNode postionSetAstNode = astExpr as PositionSetAstNode;
                return CreateVariable(postionSetAstNode.PositionSetName, typeof(PositionSet));
            }
            else if (astExpr is PredefinedSetAstNode)
            {
                PredefinedSetAstNode predefinedSetAstNode = astExpr as PredefinedSetAstNode;
                return CreateVariable(predefinedSetAstNode.SetName, typeof(PredefinedDataSet));
            }
            else if (astExpr is OperationExprAstNode)
            {
                OperationExprAstNode opAst = astExpr as OperationExprAstNode;

                Expression leftExpression = ConvertExpressionAst(opAst.LeftExpression);
                Expression rightExpression = ConvertExpressionAst(opAst.RightExpression);

                switch (opAst.Op.ToLower())
                {
                    case "+": return new Sum { LeftExpression = leftExpression, RightExpression = rightExpression }; 
                    case "-": return new Subtract { LeftExpression = leftExpression, RightExpression = rightExpression }; 
                    case "*": return new Multiply { LeftExpression = leftExpression, RightExpression = rightExpression }; 
                    case "/": return new Divide { LeftExpression = leftExpression, RightExpression = rightExpression };
                    case ">": return new GreaterThan{LeftExpression = leftExpression, RightExpression = rightExpression };
                    case "<": return new LessThan{LeftExpression = leftExpression, RightExpression = rightExpression };
                    case ">=": return new GreaterThanOrEq{LeftExpression = leftExpression, RightExpression = rightExpression };
                    case "<=": return new LessThanOrEq { LeftExpression = leftExpression, RightExpression = rightExpression };
                    case "and": return new And { LeftExpression = leftExpression, RightExpression = rightExpression };
                    case "or": return new Or { LeftExpression = leftExpression, RightExpression = rightExpression };
                    default:
                        throw new Exception("Unknown operator" + opAst.Op);

                }
            }
            else if (astExpr is SimpleMovingAverageAstNode)
            {
                var movAstExpr = astExpr as SimpleMovingAverageAstNode;

                return new MovingAverage(
                    (ExchangeRateAccessor) ConvertExpressionAst(movAstExpr.ExchangeRateAccessor),
                    (PeriodicTimeDefinition) ConvertExecutionFrequency(movAstExpr.LengthOfPeriod),
                    ConvertExpressionAst(movAstExpr.DateExpr));
            }
            else if (astExpr is AtTimeAstNode)
            {
                var atTimeAst = astExpr as AtTimeAstNode;
                return new AtTime(
                     (ExchangeRateAccessor)ConvertExpressionAst(atTimeAst.ExchangeRateAccessor),
                    ConvertExpressionAst(atTimeAst.DateExpr));
            }
            else if (astExpr is ExchangeRateAccessorAstNode)
            {
                var exRateAccessor = astExpr as ExchangeRateAccessorAstNode;
                return new ExchangeRateAccessor(
                    ConvertExpressionAst(exRateAccessor.BaseCurrencyExpr),
                    ConvertExpressionAst(exRateAccessor.VariableCurrencyExpr));
            }
            else if (astExpr is DateAstNode)
            {
                var dateExpr = astExpr as DateAstNode;

                return new Constant(typeof(DateTime), dateExpr.Value);
            }
            else
                throw new Exception("The derived type of ExpressionAstNode is not handled. Type name: " + astExpr.GetType().ToString());
        }