示例#1
0
        protected override StepResult ExecuteInternal(TContext ctx)
        {
            StagingCache cache = ctx.BeginStaging();

            StepResult result = child.Execute(ctx);

            if (result != StepResult.Positive)
            {
                ctx.EndStaging(cache, false);
                return(result);
            }

            while (child.Execute(ctx) == StepResult.Positive)
            {
                ;
            }

            ctx.EndStaging(cache, true, false);
            ctx.AddSymbol(new Production(Name, cache.Symbols));

            return(StepResult.Positive);
        }
示例#2
0
        protected override StepResult ExecuteInternal(TContext ctx)
        {
            BranchedStagingCache cache = ctx.BeginStagingBranched();

            StagingCache posBranch = cache.BeginSingleBranch();

            StepResult posResult = a.Execute(ctx);

            if (posResult == StepResult.Positive)
            {
                StagingCache negBranch = cache.BeginSingleBranch();

                StepResult negResult = b.Execute(ctx);

                switch (negResult)
                {
                case StepResult.Negative:
                    cache.EndBranch(negBranch, posBranch);

                    ctx.EndStaging(cache, true, false);

                    ctx.AddSymbol(new Production(Name, cache.Symbols));

                    return(StepResult.Positive);

                case StepResult.Positive:
                    if (negBranch.Consumed < posBranch.Consumed)
                    {
                        goto case StepResult.Negative;
                    }

                    posResult = StepResult.Negative;
                    break;

                case StepResult.AddRecursion:
                    posResult = StepResult.AddRecursion;
                    break;
                }
            }

            ctx.EndStaging(cache, false);

            return(posResult);
        }