Exemple #1
0
        public void Construct(CommonTree syntaxIf)
        {
            //Condition
            var syntaxCondition = syntaxIf.GetChild(0).CastTo <CommonTree>();

            ConditionExpression = TreeHelper.GetExpression(this, Scope, syntaxCondition);
            ConditionExpression.Construct(syntaxCondition);

            //check if we have an empty block
            if (syntaxIf.ChildCount < 2)
            {
                return;
            }

            //True
            var syntaxTrueStatementsBlock = syntaxIf.GetChild(1).CastTo <CommonTree>();

            TrueCaseBlockStatement = TreeHelper.GetStatements(this, Scope, syntaxTrueStatementsBlock)
                                     .First();
            TrueCaseBlockStatement.Construct(syntaxTrueStatementsBlock);


            //False
            if (syntaxIf.ChildCount < 3)
            {
                return;
            }
            var syntaxFalseStatementsBlock = syntaxIf.GetChild(2).CastTo <CommonTree>();

            FasleCaseBlockStatement = TreeHelper.GetStatements(this, Scope, syntaxFalseStatementsBlock)
                                      .First();
            FasleCaseBlockStatement.Construct(syntaxFalseStatementsBlock);
        }
Exemple #2
0
        public void Construct(CommonTree syntaxFor)
        {
            //Initialization
            var syntaxForInitialization = syntaxFor.GetChild(0).CastTo<CommonTree>();
            if (syntaxForInitialization.ChildCount > 0)
            {
                //TODO: IMPLEMENT / FIX THIS
                syntaxForInitialization.Children.Cast<CommonTree>()
                    .ForEach(syntaxVarDeclarationOrAssignment =>
                    {
                        InitializationStatement =
                            TreeHelper.GetStatements(this, Scope, syntaxVarDeclarationOrAssignment).First();
                        InitializationStatement.Construct(syntaxVarDeclarationOrAssignment);
                    });
            }

            //Condition
            var syntaxForCondition = syntaxFor.GetChild(1).CastTo<CommonTree>();
            if (syntaxForCondition.ChildCount > 0)
            {
                syntaxForCondition.Children.Cast<CommonTree>()
                    .ForEach(syntaxBoolExpression =>
                    {
                        ConditionExpression = TreeHelper.GetExpression(this, Scope, syntaxBoolExpression);
                        ConditionExpression.Construct(syntaxBoolExpression);
                    });
            }

            //Iteration
            var syntaxForIteration = syntaxFor.GetChild(2).CastTo<CommonTree>();
            if (syntaxForIteration.ChildCount > 0)
            {
                syntaxForIteration.Children.Cast<CommonTree>()
                    .ForEach(syntaxVarAssignment =>
                    {
                        IterationStatement = TreeHelper.GetStatements(this, Scope, syntaxVarAssignment).First();
                        //if(iterationExpression is Varial)
                        IterationStatement.Construct(syntaxVarAssignment);
                    });
            }


            //Block
            if (syntaxFor.ChildCount > 3)
            {
                var syntaxForBlock = syntaxFor.GetChild(3).CastTo<CommonTree>();
                BlockOrSingleStatement = TreeHelper.GetStatements(this, Scope, syntaxForBlock).First();
                BlockOrSingleStatement.Construct(syntaxForBlock);
            }
        }
        public void Construct(CommonTree syntaxWhile)
        {
            //condition
            var syntaxCondition = syntaxWhile.GetChild(0).CastTo <CommonTree>();

            ConditionExpression = TreeHelper.GetExpression(this, Scope, syntaxCondition);
            ConditionExpression.Construct(syntaxCondition);

            if (syntaxWhile.ChildCount > 1)
            {
                var syntaxBlockOrSingleStatement = syntaxWhile.GetChild(1).CastTo <CommonTree>();

                BlockOrSingleStatement =
                    TreeHelper.GetStatements(this, Scope, syntaxBlockOrSingleStatement)[0];
                BlockOrSingleStatement.Construct(syntaxBlockOrSingleStatement);
            }
        }