Exemplo n.º 1
0
            public object Execute(ParseTree.Node node)
            {
                if (PreCondition != null && !PreCondition(node))
                {
                    throw new ParseErrorException();
                }

                if (node.Parent == null)
                {
                    return(null);
                }

                var operandStack  = node.Parent.OperandStack;
                var capturedValue = node.Value;
                var productions   = node.ChildProductions;

                // pop-out rule operands from operand stack
                object[] ruleOperands = FetchOperands(operandStack);

                // calculate order of actions taking child productions into account
                var actionScheduling = ScheduleActions(productions);

                // run actions in the calculated order
                T production = default(T);

                foreach (var actionSchedule in actionScheduling)
                {
                    var a = actionSchedule.Action;
                    var childProduction = actionSchedule.Production;

                    // if production is null and action is update, init with default production
                    if (production == null && a.ActionInfo.ReturnType == typeof(void))
                    {
                        production = DefaultProduction(capturedValue, operandStack, productions);
                    }

                    // if action uses child production, use it as input instead of the rule operands
                    if (childProduction != null)
                    {
                        a.Execute(ref production, capturedValue, childProduction);
                    }
                    else
                    {
                        a.Execute(ref production, capturedValue, ruleOperands);
                    }
                }

                // if no production was created by rule actions, create default production
                if (production == null)
                {
                    production = DefaultProduction(capturedValue, operandStack, productions);
                }

                return(production);
            }
Exemplo n.º 2
0
 protected virtual bool TestPreCondition(
     ParseTree.Node node,
     string capturedValue,
     Stack <ParseTree.Node> operandStack,
     ProductionObjects productions)
 {
     if (PreCondition == null)
     {
         return(true);
     }
     return(PreCondition(node));
 }